[FFmpeg-cvslog] avcodec/pngdec: create a function to decode tRNS chunk.

Benoit Fouet git at videolan.org
Fri Nov 14 17:10:18 CET 2014


ffmpeg | branch: master | Benoit Fouet <benoit.fouet at free.fr> | Fri Nov 14 10:17:35 2014 +0100| [6499e63f7b9e73d5b6b601f25803f9244de99bf6] | committer: Michael Niedermayer

avcodec/pngdec: create a function to decode tRNS chunk.

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6499e63f7b9e73d5b6b601f25803f9244de99bf6
---

 libavcodec/pngdec.c |   33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 9b5d5dd..92ed59d 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -694,6 +694,25 @@ static int decode_plte_chunk(AVCodecContext *avctx, PNGDecContext *s,
     return 0;
 }
 
+static int decode_trns_chunk(AVCodecContext *avctx, PNGDecContext *s,
+                             uint32_t length)
+{
+    int v, i;
+
+    /* read the transparency. XXX: Only palette mode supported */
+    if (s->color_type != PNG_COLOR_TYPE_PALETTE ||
+            length > 256 ||
+            !(s->state & PNG_PLTE))
+        return AVERROR_INVALIDDATA;
+    for (i = 0; i < length; i++) {
+        v = bytestream2_get_byte(&s->gb);
+        s->palette[i] = (s->palette[i] & 0x00ffffff) | (v << 24);
+    }
+    bytestream2_skip(&s->gb, 4);     /* crc */
+
+    return 0;
+}
+
 static int decode_frame_png(AVCodecContext *avctx,
                         void *data, int *got_frame,
                         AVPacket *avpkt)
@@ -771,20 +790,8 @@ static int decode_frame_png(AVCodecContext *avctx,
                 goto skip_tag;
         break;
         case MKTAG('t', 'R', 'N', 'S'):
-        {
-            int v, i;
-
-            /* read the transparency. XXX: Only palette mode supported */
-            if (s->color_type != PNG_COLOR_TYPE_PALETTE ||
-                length > 256 ||
-                !(s->state & PNG_PLTE))
+            if (decode_trns_chunk(avctx, s, length) < 0)
                 goto skip_tag;
-            for (i = 0; i < length; i++) {
-                v = bytestream2_get_byte(&s->gb);
-                s->palette[i] = (s->palette[i] & 0x00ffffff) | (v << 24);
-            }
-            bytestream2_skip(&s->gb, 4);     /* crc */
-        }
         break;
         case MKTAG('t', 'E', 'X', 't'):
             if (decode_text_chunk(s, length, 0, &metadata) < 0)



More information about the ffmpeg-cvslog mailing list