]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/gifdec.c
Fix lossless jpeg encoder to comply to spec and store full redundant
[ffmpeg] / libavcodec / gifdec.c
index 386c039c9c2110f96a1b34ada7427b065077d1f4..ee805a8d5ae3a7ad6fff7226ca6a01ae2bd02e60 100644 (file)
@@ -47,8 +47,8 @@ typedef struct GifState {
     int gce_delay;
 
     /* LZW compatible decoder */
-    uint8_t *bytestream;
-    uint8_t *bytestream_end;
+    const uint8_t *bytestream;
+    const uint8_t *bytestream_end;
     LZWState *lzw;
 
     /* aux buffers */
@@ -96,8 +96,7 @@ static int gif_read_image(GifState *s)
     n = (1 << bits_per_pixel);
     spal = palette;
     for(i = 0; i < n; i++) {
-        s->image_palette[i] = (0xff << 24) |
-            (spal[0] << 16) | (spal[1] << 8) | (spal[2]);
+        s->image_palette[i] = (0xff << 24) | AV_RB24(spal);
         spal += 3;
     }
     for(; i < 256; i++)
@@ -108,8 +107,8 @@ static int gif_read_image(GifState *s)
 
     /* now get the image data */
     code_size = bytestream_get_byte(&s->bytestream);
-    //TODO: add proper data size
-    ff_lzw_decode_init(s->lzw, code_size, s->bytestream, 0, FF_LZW_GIF);
+    ff_lzw_decode_init(s->lzw, code_size, s->bytestream,
+                       s->bytestream_end - s->bytestream, FF_LZW_GIF);
 
     /* read all the image */
     linesize = s->picture.linesize[0];
@@ -127,11 +126,8 @@ static int gif_read_image(GifState *s)
                 y1 += 8;
                 ptr += linesize * 8;
                 if (y1 >= height) {
-                    y1 = 4;
-                    if (pass == 0)
-                        ptr = ptr1 + linesize * 4;
-                    else
-                        ptr = ptr1 + linesize * 2;
+                    y1 = pass ? 2 : 4;
+                    ptr = ptr1 + linesize * y1;
                     pass++;
                 }
                 break;
@@ -258,25 +254,22 @@ static int gif_parse_next_image(GifState *s)
 #endif
         switch (code) {
         case ',':
-            if (gif_read_image(s) < 0)
-                return -1;
-            return 0;
-        case ';':
-            /* end of image */
-            return -1;
+            return gif_read_image(s);
         case '!':
             if (gif_read_extension(s) < 0)
                 return -1;
             break;
+        case ';':
+            /* end of image */
         default:
-            /* error or errneous EOF */
+            /* error or erroneous EOF */
             return -1;
         }
     }
     return -1;
 }
 
-static int gif_decode_init(AVCodecContext *avctx)
+static av_cold int gif_decode_init(AVCodecContext *avctx)
 {
     GifState *s = avctx->priv_data;
 
@@ -289,7 +282,7 @@ static int gif_decode_init(AVCodecContext *avctx)
     return 0;
 }
 
-static int gif_decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
+static int gif_decode_frame(AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size)
 {
     GifState *s = avctx->priv_data;
     AVFrame *picture = data;
@@ -321,7 +314,7 @@ static int gif_decode_frame(AVCodecContext *avctx, void *data, int *data_size, u
     return s->bytestream - buf;
 }
 
-static int gif_decode_close(AVCodecContext *avctx)
+static av_cold int gif_decode_close(AVCodecContext *avctx)
 {
     GifState *s = avctx->priv_data;
 
@@ -340,4 +333,5 @@ AVCodec gif_decoder = {
     NULL,
     gif_decode_close,
     gif_decode_frame,
+    .long_name = NULL_IF_CONFIG_SMALL("GIF (Graphics Interchange Format)"),
 };