ext/libpng/gstpngdec.c: Implement paletted and grayscale png files handling. (#150363).
authorJulien Moutte <julien@moutte.net>
Mon, 6 Mar 2006 22:22:45 +0000 (22:22 +0000)
committerJulien Moutte <julien@moutte.net>
Mon, 6 Mar 2006 22:22:45 +0000 (22:22 +0000)
Original commit message from CVS:
2006-03-06  Julien MOUTTE  <julien@moutte.net>

* ext/libpng/gstpngdec.c: (gst_pngdec_caps_create_and_set):
Implement paletted and grayscale png files handling.
(#150363).

ChangeLog
ext/libpng/gstpngdec.c

index 641a91d..b50ef68 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2006-03-06  Julien MOUTTE  <julien@moutte.net>
+
+       * ext/libpng/gstpngdec.c: (gst_pngdec_caps_create_and_set): 
+       Implement paletted and grayscale png files handling.
+       (#150363).
+
 2006-03-06  Thomas Vander Stichele  <thomas at apestaart dot org>
 
        * ext/speex/gstspeexenc.c: (gst_speexenc_set_header_on_caps),
index 874114a..bbdda42 100644 (file)
@@ -294,7 +294,8 @@ gst_pngdec_caps_create_and_set (GstPngDec * pngdec)
 
   /* We don't handle 16 bits per color, strip down to 8 */
   if (bpc == 16) {
-    GST_LOG ("this is a 16 bits per channel PNG image, strip down to 8 bits");
+    GST_LOG_OBJECT (pngdec,
+        "this is a 16 bits per channel PNG image, strip down to 8 bits");
     png_set_strip_16 (pngdec->png);
   }
 
@@ -305,6 +306,23 @@ gst_pngdec_caps_create_and_set (GstPngDec * pngdec)
   if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
     png_set_bgr (pngdec->png);
 
+  /* Gray scale converted to RGB and upscaled to 8 bits */
+  if ((color_type == PNG_COLOR_TYPE_GRAY_ALPHA) ||
+      (color_type == PNG_COLOR_TYPE_GRAY)) {
+    GST_LOG_OBJECT (pngdec, "converting grayscale png to RGB");
+    png_set_gray_to_rgb (pngdec->png);
+    if (bpc < 8) {              /* Convert to 8 bits */
+      GST_LOG_OBJECT (pngdec, "converting grayscale image to 8 bits");
+      png_set_gray_1_2_4_to_8 (pngdec->png);
+    }
+  }
+
+  /* Palette converted to RGB */
+  if (color_type == PNG_COLOR_TYPE_PALETTE) {
+    GST_LOG_OBJECT (pngdec, "converting palette png to RGB");
+    png_set_palette_to_rgb (pngdec->png);
+  }
+
   /* Update the info structure */
   png_read_update_info (pngdec->png, pngdec->info);
 
@@ -316,20 +334,21 @@ gst_pngdec_caps_create_and_set (GstPngDec * pngdec)
   pngdec->width = width;
   pngdec->height = height;
 
-  GST_LOG ("this is a %dx%d PNG image", pngdec->width, pngdec->height);
+  GST_LOG_OBJECT (pngdec, "this is a %dx%d PNG image", pngdec->width,
+      pngdec->height);
 
   switch (pngdec->color_type) {
     case PNG_COLOR_TYPE_RGB:
-      GST_LOG ("we have no alpha channel, depth is 24 bits");
+      GST_LOG_OBJECT (pngdec, "we have no alpha channel, depth is 24 bits");
       pngdec->bpp = 24;
       break;
     case PNG_COLOR_TYPE_RGB_ALPHA:
-      GST_LOG ("we have an alpha channel, depth is 32 bits");
+      GST_LOG_OBJECT (pngdec, "we have an alpha channel, depth is 32 bits");
       pngdec->bpp = 32;
       break;
     default:
       GST_ELEMENT_ERROR (pngdec, STREAM, NOT_IMPLEMENTED, (NULL),
-          ("pngdec does not support grayscale or paletted data yet"));
+          ("pngdec does not support this color type"));
       ret = GST_FLOW_ERROR;
       goto beach;
   }