[Ffmpeg-devel] [PATCH] PNG 16-bit grayscale support

Kostya kostya.shishkov
Sat Oct 14 14:43:22 CEST 2006


This patch enables grayscale PNG decoding with 16-bit per sample size.
Sample is here:
http://samples.mplayerhq.hu/V-codecs/PNG/les_dns_xz.mov
(playable with MPlayer)
-------------- next part --------------
Index: png.c
===================================================================
--- png.c	(revision 6681)
+++ png.c	(working copy)
@@ -367,6 +367,16 @@
                            s->last_row, s->row_size, s->bpp);
             memcpy(s->last_row, s->tmp_row, s->row_size);
             convert_to_rgba32(ptr, s->tmp_row, s->width);
+        } else if(s->bit_depth == 16){
+            int i; uint8_t *tmp;
+            png_filter_row(s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
+                           s->last_row, s->row_size, s->bpp);
+            memcpy(s->last_row, s->tmp_row, s->row_size);
+            tmp = s->tmp_row;
+            for(i = 0; i < s->width; i++){
+                *ptr++ = tmp[0];
+                tmp += 2;
+            }
         } else {
             /* in normal case, we avoid one copy */
             if (s->y == 0)
@@ -534,7 +544,7 @@
                 } else if (s->bit_depth == 8 &&
                            s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
                     avctx->pix_fmt = PIX_FMT_RGBA32;
-                } else if (s->bit_depth == 8 &&
+                } else if ((s->bit_depth == 8 || s->bit_depth == 16) &&
                            s->color_type == PNG_COLOR_TYPE_GRAY) {
                     avctx->pix_fmt = PIX_FMT_GRAY8;
                 } else if (s->bit_depth == 1 &&
@@ -573,7 +583,8 @@
                 if (!s->last_row)
                     goto fail;
                 if (s->interlace_type ||
-                    s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
+                    s->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
+                    s->bit_depth == 16) {
                     s->tmp_row = av_malloc(s->row_size);
                     if (!s->tmp_row)
                         goto fail;



More information about the ffmpeg-devel mailing list