[FFmpeg-devel] [PATCH v2 7/7] Gif decoder code tidy.

Paul B Mahol onemda at gmail.com
Fri Nov 30 17:07:52 CET 2012


On 11/30/12, Vitaliy E Sugrobov <vsugrob at hotmail.com> wrote:
> This concludes patch series related to animated gif demuxer/decoder.
>
> Signed-off-by: Vitaliy E Sugrobov <vsugrob at hotmail.com>
> ---
>  libavcodec/gifdec.c |   49
> ++++++++++++++++++++++++++++++-------------------
>  1 files changed, 30 insertions(+), 19 deletions(-)
>
> diff --git a/libavcodec/gifdec.c b/libavcodec/gifdec.c
> index f46e669..aee90c6 100755
> --- a/libavcodec/gifdec.c
> +++ b/libavcodec/gifdec.c
> @@ -2,6 +2,7 @@
>   * GIF decoder
>   * Copyright (c) 2003 Fabrice Bellard
>   * Copyright (c) 2006 Baptiste Coudurier
> + * Copyright (c) 2012 Vitaliy E Sugrobov

Too late, applied it already in correct commit.
>   *
>   * This file is part of FFmpeg.
>   *
> @@ -46,7 +47,7 @@ typedef struct GifState {
>      int background_color_index;
>      int transparent_color_index;
>      int color_resolution;
> -    /* intermediate buffer for storing color indices
> +    /** intermediate buffer for storing color indices

???
>       * obtained from lzw-encoded data stream */
>      uint8_t *idx_line;
>
> @@ -130,24 +131,25 @@ static void gif_copy_img_rect(const uint32_t *src,
> uint32_t *dst,
>
>  static int gif_read_image(GifState *s)
>  {
> -    int left, top, width, height, bits_per_pixel, code_size, flags;
> -    int is_interleaved, has_local_palette, y, pass, y1, linesize,
> pal_size;
> +    int left, top, width, height,
> +        bits_per_pixel, code_size, flags,
> +        is_interleaved, has_local_palette,
> +        y, pass, y1, linesize, pal_size, ret;

I doubt there is similar style in other files.
>      uint32_t *ptr, *pal, *px, *pr, *ptr1;
> -    int ret;
>      uint8_t *idx;
>
>      /* At least 9 bytes of Image Descriptor. */
>      if (s->bytestream_end < s->bytestream + 9)
>          return AVERROR_INVALIDDATA;
>
> -    left = bytestream_get_le16(&s->bytestream);
> -    top = bytestream_get_le16(&s->bytestream);
> -    width = bytestream_get_le16(&s->bytestream);
> +    left   = bytestream_get_le16(&s->bytestream);
> +    top    = bytestream_get_le16(&s->bytestream);
> +    width  = bytestream_get_le16(&s->bytestream);
>      height = bytestream_get_le16(&s->bytestream);
> -    flags = bytestream_get_byte(&s->bytestream);
> -    is_interleaved = flags & 0x40;
> +    flags  = bytestream_get_byte(&s->bytestream);
> +    is_interleaved    = flags & 0x40;
>      has_local_palette = flags & 0x80;
> -    bits_per_pixel = (flags & 0x07) + 1;
> +    bits_per_pixel    = (flags & 0x07) + 1;
>
>      av_dlog(s->avctx, "image x=%d y=%d w=%d h=%d\n", left, top, width,
> height);
>
> @@ -234,6 +236,7 @@ static int gif_read_image(GifState *s)
>      ptr = ptr1;
>      pass = 0;
>      y1 = 0;
> +
>      for (y = 0; y < height; y++) {
>          if (ff_lzw_decode(s->lzw, s->idx_line, width) == 0)
>              goto decode_tail;
> @@ -292,7 +295,8 @@ static int gif_read_image(GifState *s)
>
>  static int gif_read_extension(GifState *s)
>  {
> -    int ext_code, ext_len, i, gce_flags, gce_transparent_index;
> +    int ext_code, ext_len, i,
> +        gce_flags, gce_transparent_index;

ditto
>
>      /* There must be at least 2 bytes:
>       * 1 for extension label and 1 for extension length. */
> @@ -318,12 +322,13 @@ static int gif_read_extension(GifState *s)
>          gce_flags = bytestream_get_byte(&s->bytestream);
>          bytestream_get_le16(&s->bytestream);    // delay during which the
> frame is shown
>          gce_transparent_index = bytestream_get_byte(&s->bytestream);
> +
>          if (gce_flags & 0x01)
>              s->transparent_color_index = gce_transparent_index;
>          else
>              s->transparent_color_index = -1;
> -        s->gce_disposal = (gce_flags >> 2) & 0x7;
>
> +        s->gce_disposal = (gce_flags >> 2) & 0x7;
>          av_dlog(s->avctx, "gce_flags=%x tcolor=%d disposal=%d\n",
>                 gce_flags,
>                 s->transparent_color_index, s->gce_disposal);
> @@ -350,14 +355,14 @@ static int gif_read_extension(GifState *s)
>
>          av_dlog(s->avctx, "ext_len1=%d\n", ext_len);
>      }
> +
>      return 0;
>  }
>
>  static int gif_read_header1(GifState *s)
>  {
>      uint8_t sig[6];
> -    int v, n;
> -    int background_color_index;
> +    int v, n, background_color_index;
>
>      if (s->bytestream_end < s->bytestream + 13)
>          return AVERROR_INVALIDDATA;
> @@ -372,8 +377,9 @@ static int gif_read_header1(GifState *s)
>      s->transparent_color_index = -1;
>      s->screen_width = bytestream_get_le16(&s->bytestream);
>      s->screen_height = bytestream_get_le16(&s->bytestream);
> -    if(   (unsigned)s->screen_width  > 32767
> -       || (unsigned)s->screen_height > 32767){
> +
> +    if ((unsigned)s->screen_width  > 32767 ||
> +        (unsigned)s->screen_height > 32767) {
>          av_log(s->avctx, AV_LOG_ERROR, "picture size too large\n");
>          return AVERROR_INVALIDDATA;
>      }
> @@ -411,6 +417,7 @@ static int gif_parse_next_image(GifState *s, int
> *got_picture)
>  {
>      int ret;
>      *got_picture = sizeof(AVPicture);
> +
>      while (s->bytestream < s->bytestream_end) {
>          int code = bytestream_get_byte(&s->bytestream);
>
> @@ -432,6 +439,7 @@ static int gif_parse_next_image(GifState *s, int
> *got_picture)
>              return AVERROR_INVALIDDATA;
>          }
>      }
> +
>      return AVERROR_EOF;
>  }
>
> @@ -440,12 +448,12 @@ static av_cold int gif_decode_init(AVCodecContext
> *avctx)
>      GifState *s = avctx->priv_data;
>
>      s->avctx = avctx;
> -
>      avctx->pix_fmt = AV_PIX_FMT_RGB32;
>      avcodec_get_frame_defaults(&s->picture);
> -    avctx->coded_frame= &s->picture;
> +    avctx->coded_frame = &s->picture;
>      s->picture.data[0] = NULL;
>      ff_lzw_decode_open(&s->lzw);
> +
>      return 0;
>  }
>
> @@ -477,6 +485,7 @@ static int gif_decode_frame(AVCodecContext *avctx, void
> *data, int *got_picture,
>
>          if ((ret = av_image_check_size(s->screen_width, s->screen_height,
> 0, avctx)) < 0)
>              return ret;
> +
>          avcodec_set_dimensions(avctx, s->screen_width, s->screen_height);
>
>          if (s->picture.data[0])
> @@ -500,6 +509,7 @@ static int gif_decode_frame(AVCodecContext *avctx, void
> *data, int *got_picture,
>      }
>
>      ret = gif_parse_next_image(s, got_picture);
> +
>      if (ret < 0)
>          return ret;
>      else if (*got_picture)
> @@ -513,7 +523,8 @@ static av_cold int gif_decode_close(AVCodecContext
> *avctx)
>      GifState *s = avctx->priv_data;
>
>      ff_lzw_decode_close(&s->lzw);
> -    if(s->picture.data[0])
> +
> +    if (s->picture.data[0])
>          avctx->release_buffer(avctx, &s->picture);
>
>      av_freep(&s->idx_line);
> --
> 1.7.2.5
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>


More information about the ffmpeg-devel mailing list