It addes support PAL8 pixel format for APNG-picture.
The picture is http://littlesvr.ca/apng/samples.html (clock)
It is a qualification task of GSoC 2015 (mentor is Paul B Mahol)

---
 libavcodec/pngdec.c | 58 +++++++++++++++++++++++++++++++++--------------------
 1 file changed, 36 insertions(+), 22 deletions(-)

diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 901abae..7dbf28a 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -877,7 +877,8 @@ static int handle_p_frame_apng(AVCodecContext *avctx, PNGDecContext *s,
         return ls;
 
     if (s->blend_op == APNG_BLEND_OP_OVER &&
-        avctx->pix_fmt != AV_PIX_FMT_RGBA && avctx->pix_fmt != AV_PIX_FMT_ARGB) {
+        avctx->pix_fmt != AV_PIX_FMT_RGBA && avctx->pix_fmt != AV_PIX_FMT_ARGB &&
+        avctx->pix_fmt != AV_PIX_FMT_PAL8) {
         avpriv_request_sample(avctx, "Blending with pixel format %s",
                               av_get_pix_fmt_name(avctx->pix_fmt));
         return AVERROR_PATCHWELCOME;
@@ -897,43 +898,56 @@ static int handle_p_frame_apng(AVCodecContext *avctx, PNGDecContext *s,
         uint8_t ri, gi, bi, ai;
 
         pd_last_region += s->y_offset * s->image_linesize;
-        if (avctx->pix_fmt == AV_PIX_FMT_RGBA) {
+        switch(avctx->pix_fmt)
+        {
+        case AV_PIX_FMT_RGBA:
             ri = 0;
             gi = 1;
             bi = 2;
             ai = 3;
-        } else {
+            break;
+        case AV_PIX_FMT_ARGB:
             ri = 3;
             gi = 2;
             bi = 1;
             ai = 0;
+            break;
+        case AV_PIX_FMT_PAL8:
+            memcpy(s->palette, p->data[1], 256 * sizeof(uint32_t));
+            break;
         }
 
         for (j = s->y_offset; j < s->y_offset + s->cur_h; j++) {
             i = s->x_offset * s->bpp;
+
             if (i)
                 memcpy(pd, pd_last, i);
-            for (; i < (s->x_offset + s->cur_w) * s->bpp; i += s->bpp) {
-                uint8_t alpha = pd[i+ai];
-
-                /* output = alpha * foreground + (1-alpha) * background */
-                switch (alpha) {
-                case 0:
-                    pd[i+ri] = pd_last_region[i+ri];
-                    pd[i+gi] = pd_last_region[i+gi];
-                    pd[i+bi] = pd_last_region[i+bi];
-                    pd[i+ai] = 0xff;
-                    break;
-                case 255:
-                    break;
-                default:
-                    pd[i+ri] = FAST_DIV255(alpha * pd[i+ri] + (255 - alpha) * pd_last_region[i+ri]);
-                    pd[i+gi] = FAST_DIV255(alpha * pd[i+gi] + (255 - alpha) * pd_last_region[i+gi]);
-                    pd[i+bi] = FAST_DIV255(alpha * pd[i+bi] + (255 - alpha) * pd_last_region[i+bi]);
-                    pd[i+ai] = 0xff;
-                    break;
+
+            if (avctx->pix_fmt != AV_PIX_FMT_PAL8) {
+                for (; i < (s->x_offset + s->cur_w) * s->bpp; i += s->bpp) {
+                    uint8_t alpha = pd[i+ai];
+                    /* output = alpha * foreground + (1-alpha) * background */
+                    switch (alpha) {
+                    case 0:
+                        pd[i+ri] = pd_last_region[i+ri];
+                        pd[i+gi] = pd_last_region[i+gi];
+                        pd[i+bi] = pd_last_region[i+bi];
+                        pd[i+ai] = 0xff;
+                        break;
+                    case 255:
+                        break;
+                    default:
+                        pd[i+ri] = FAST_DIV255(alpha * pd[i+ri] + (255 - alpha) * pd_last_region[i+ri]);
+                        pd[i+gi] = FAST_DIV255(alpha * pd[i+gi] + (255 - alpha) * pd_last_region[i+gi]);
+                        pd[i+bi] = FAST_DIV255(alpha * pd[i+bi] + (255 - alpha) * pd_last_region[i+bi]);
+                        pd[i+ai] = 0xff;
+                        break;
+                    }
                 }
             }
+            else
+                i = (s->x_offset + s->cur_w) * s->bpp;
+
             if (ls - i)
                 memcpy(pd+i, pd_last+i, ls - i);
             pd      += s->image_linesize;
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to