[FFmpeg-devel] [RFC]64bit png

Carl Eugen Hoyos cehoyos at ag.or.at
Fri Jan 20 00:35:27 CET 2012


Hi!

Attached patch shows some artefacts for 64bit loco samples, any idea why?

Thank you, Carl Eugen
-------------- next part --------------
diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 307dd1a..c30e2df 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -262,12 +262,35 @@ static av_always_inline void convert_to_rgb32_loco(uint8_t *dst, const uint8_t *
     }
 }
 
-static void convert_to_rgb32(uint8_t *dst, const uint8_t *src, int width, int loco)
+static av_always_inline void convert_to_rgb64_loco(uint16_t *dst, const uint16_t *src, int width)
+{
+    int j;
+    uint16_t r, g, b;
+    for(j = 0; j < width; j++) {
+        r = src[0];
+        g = src[1];
+        b = src[2];
+        r = (r+g)&0xffff;
+        b = (b+g)&0xffff;
+        dst[0] = r;
+        dst[1] = g;
+        dst[2] = b;
+        dst[3] = src[3];
+        dst += 4;
+        src += 4;
+    }
+}
+
+static void convert_to_rgba(uint8_t *dst, const uint8_t *src, int width, int bit_depth, int loco)
 {
     if(loco)
+        if(bit_depth == 8) {
         convert_to_rgb32_loco(dst, src, width, 1);
+	} else {
+            convert_to_rgb64_loco((uint16_t *)dst, (const uint16_t *)src, width);
+        }
     else
-        memcpy(dst, src, width * 4);
+        memcpy(dst, src, width * bit_depth >> 1);
 }
 
 static void deloco_rgb24(uint8_t *dst, int size)
@@ -292,7 +315,7 @@ static void png_handle_row(PNGDecContext *s)
         if (s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
             png_filter_row(s, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
                            s->last_row, s->row_size, s->bpp);
-            convert_to_rgb32(ptr, s->tmp_row, s->width, s->filter_type == PNG_FILTER_TYPE_LOCO);
+            convert_to_rgba(ptr, s->tmp_row, s->width, s->bit_depth, s->filter_type == PNG_FILTER_TYPE_LOCO);
             FFSWAP(uint8_t*, s->last_row, s->tmp_row);
         } else {
             /* in normal case, we avoid one copy */
@@ -484,6 +507,9 @@ static int decode_frame(AVCodecContext *avctx,
                 } else if (s->bit_depth == 16 &&
                            s->color_type == PNG_COLOR_TYPE_RGB) {
                     avctx->pix_fmt = PIX_FMT_RGB48BE;
+                } else if (s->bit_depth == 16 &&
+                           s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
+                    avctx->pix_fmt = PIX_FMT_RGBA64BE;
                 } else if (s->color_type == PNG_COLOR_TYPE_PALETTE) {
                     avctx->pix_fmt = PIX_FMT_PAL8;
                 } else if (s->bit_depth == 1) {


More information about the ffmpeg-devel mailing list