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, n, i;

    uint8_t *ptr, *spal, *palette, *ptr1;



    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;

    has_local_palette = flags & 0x80;

    bits_per_pixel = (flags & 0x07) + 1;



    av_dlog(s->avctx, "image x=%d y=%d w=%d h=%d\n", left, top, width, height);



    if (has_local_palette) {

        bytestream_get_buffer(&s->bytestream, s->local_palette, 3 * (1 << bits_per_pixel));

        palette = s->local_palette;

    } else {

        palette = s->global_palette;

        bits_per_pixel = s->bits_per_pixel;

    }



    /* verify that all the image is inside the screen dimensions */

    if (left + width > s->screen_width ||

        top + height > s->screen_height)

        return AVERROR(EINVAL);



    /* build the palette */

    n = (1 << bits_per_pixel);

    spal = palette;

    for(i = 0; i < n; i++) {

        s->image_palette[i] = (0xffu << 24) | AV_RB24(spal);

        spal += 3;

    }

    for(; i < 256; i++)

        s->image_palette[i] = (0xffu << 24);

    /* handle transparency */

    if (s->transparent_color_index >= 0)

        s->image_palette[s->transparent_color_index] = 0;



    /* now get the image data */

    code_size = bytestream_get_byte(&s->bytestream);

    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];

    ptr1 = s->picture.data[0] + top * linesize + left;

    ptr = ptr1;

    pass = 0;

    y1 = 0;

    for (y = 0; y < height; y++) {

        ff_lzw_decode(s->lzw, ptr, width);

        if (is_interleaved) {

            switch(pass) {

            default:

            case 0:

            case 1:

                y1 += 8;

                ptr += linesize * 8;

                if (y1 >= height) {

                    y1 = pass ? 2 : 4;

                    ptr = ptr1 + linesize * y1;

                    pass++;

                }

                break;

            case 2:

                y1 += 4;

                ptr += linesize * 4;

                if (y1 >= height) {

                    y1 = 1;

                    ptr = ptr1 + linesize;

                    pass++;

                }

                break;

            case 3:

                y1 += 2;

                ptr += linesize * 2;

                break;

            }

        } else {

            ptr += linesize;

        }

    }

    /* read the garbage data until end marker is found */

    ff_lzw_decode_tail(s->lzw);

    s->bytestream = ff_lzw_cur_ptr(s->lzw);

    return 0;

}

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, n, i;

    uint8_t *ptr, *spal, *palette, *ptr1;



    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;

    has_local_palette = flags & 0x80;

    bits_per_pixel = (flags & 0x07) + 1;



    av_dlog(s->avctx, "image x=%d y=%d w=%d h=%d\n", left, top, width, height);



    if (has_local_palette) {

        bytestream_get_buffer(&s->bytestream, s->local_palette, 3 * (1 << bits_per_pixel));

        palette = s->local_palette;

    } else {

        palette = s->global_palette;

        bits_per_pixel = s->bits_per_pixel;

    }



    

    if (left + width > s->screen_width ||

        top + height > s->screen_height)

        return AVERROR(EINVAL);



    

    n = (1 << bits_per_pixel);

    spal = palette;

    for(i = 0; i < n; i++) {

        s->image_palette[i] = (0xffu << 24) | AV_RB24(spal);

        spal += 3;

    }

    for(; i < 256; i++)

        s->image_palette[i] = (0xffu << 24);

    

    if (s->transparent_color_index >= 0)

        s->image_palette[s->transparent_color_index] = 0;



    

    code_size = bytestream_get_byte(&s->bytestream);

    ff_lzw_decode_init(s->lzw, code_size, s->bytestream,

                       s->bytestream_end - s->bytestream, FF_LZW_GIF);



    

    linesize = s->picture.linesize[0];

    ptr1 = s->picture.data[0] + top * linesize + left;

    ptr = ptr1;

    pass = 0;

    y1 = 0;

    for (y = 0; y < height; y++) {

        ff_lzw_decode(s->lzw, ptr, width);

        if (is_interleaved) {

            switch(pass) {

            default:

            case 0:

            case 1:

                y1 += 8;

                ptr += linesize * 8;

                if (y1 >= height) {

                    y1 = pass ? 2 : 4;

                    ptr = ptr1 + linesize * y1;

                    pass++;

                }

                break;

            case 2:

                y1 += 4;

                ptr += linesize * 4;

                if (y1 >= height) {

                    y1 = 1;

                    ptr = ptr1 + linesize;

                    pass++;

                }

                break;

            case 3:

                y1 += 2;

                ptr += linesize * 2;

                break;

            }

        } else {

            ptr += linesize;

        }

    }

    

    ff_lzw_decode_tail(s->lzw);

    s->bytestream = ff_lzw_cur_ptr(s->lzw);

    return 0;

}

static int FUNC_0(GifState *VAR_0)

{

    int VAR_1, VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7;

    int VAR_8, VAR_9, VAR_10, VAR_11, VAR_12, VAR_13, VAR_14, VAR_15;

    uint8_t *ptr, *spal, *palette, *ptr1;



    VAR_1 = bytestream_get_le16(&VAR_0->bytestream);

    VAR_2 = bytestream_get_le16(&VAR_0->bytestream);

    VAR_3 = bytestream_get_le16(&VAR_0->bytestream);

    VAR_4 = bytestream_get_le16(&VAR_0->bytestream);

    VAR_7 = bytestream_get_byte(&VAR_0->bytestream);

    VAR_8 = VAR_7 & 0x40;

    VAR_9 = VAR_7 & 0x80;

    VAR_5 = (VAR_7 & 0x07) + 1;



    av_dlog(VAR_0->avctx, "image x=%d VAR_10=%d w=%d h=%d\VAR_14", VAR_1, VAR_2, VAR_3, VAR_4);



    if (VAR_9) {

        bytestream_get_buffer(&VAR_0->bytestream, VAR_0->local_palette, 3 * (1 << VAR_5));

        palette = VAR_0->local_palette;

    } else {

        palette = VAR_0->global_palette;

        VAR_5 = VAR_0->VAR_5;

    }



    

    if (VAR_1 + VAR_3 > VAR_0->screen_width ||

        VAR_2 + VAR_4 > VAR_0->screen_height)

        return AVERROR(EINVAL);



    

    VAR_14 = (1 << VAR_5);

    spal = palette;

    for(VAR_15 = 0; VAR_15 < VAR_14; VAR_15++) {

        VAR_0->image_palette[VAR_15] = (0xffu << 24) | AV_RB24(spal);

        spal += 3;

    }

    for(; VAR_15 < 256; VAR_15++)

        VAR_0->image_palette[VAR_15] = (0xffu << 24);

    

    if (VAR_0->transparent_color_index >= 0)

        VAR_0->image_palette[VAR_0->transparent_color_index] = 0;



    

    VAR_6 = bytestream_get_byte(&VAR_0->bytestream);

    ff_lzw_decode_init(VAR_0->lzw, VAR_6, VAR_0->bytestream,

                       VAR_0->bytestream_end - VAR_0->bytestream, FF_LZW_GIF);



    

    VAR_13 = VAR_0->picture.VAR_13[0];

    ptr1 = VAR_0->picture.data[0] + VAR_2 * VAR_13 + VAR_1;

    ptr = ptr1;

    VAR_11 = 0;

    VAR_12 = 0;

    for (VAR_10 = 0; VAR_10 < VAR_4; VAR_10++) {

        ff_lzw_decode(VAR_0->lzw, ptr, VAR_3);

        if (VAR_8) {

            switch(VAR_11) {

            default:

            case 0:

            case 1:

                VAR_12 += 8;

                ptr += VAR_13 * 8;

                if (VAR_12 >= VAR_4) {

                    VAR_12 = VAR_11 ? 2 : 4;

                    ptr = ptr1 + VAR_13 * VAR_12;

                    VAR_11++;

                }

                break;

            case 2:

                VAR_12 += 4;

                ptr += VAR_13 * 4;

                if (VAR_12 >= VAR_4) {

                    VAR_12 = 1;

                    ptr = ptr1 + VAR_13;

                    VAR_11++;

                }

                break;

            case 3:

                VAR_12 += 2;

                ptr += VAR_13 * 2;

                break;

            }

        } else {

            ptr += VAR_13;

        }

    }

    

    ff_lzw_decode_tail(VAR_0->lzw);

    VAR_0->bytestream = ff_lzw_cur_ptr(VAR_0->lzw);

    return 0;

}

static int FUNC_0(GifState *VAR_0)
{ int VAR_1, VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7; int VAR_8, VAR_9, VAR_10, VAR_11, VAR_12, VAR_13, VAR_14, VAR_15; uint8_t *ptr, *spal, *palette, *ptr1; VAR_1 = bytestream_get_le16(&VAR_0->bytestream); VAR_2 = bytestream_get_le16(&VAR_0->bytestream); VAR_3 = bytestream_get_le16(&VAR_0->bytestream); VAR_4 = bytestream_get_le16(&VAR_0->bytestream); VAR_7 = bytestream_get_byte(&VAR_0->bytestream); VAR_8 = VAR_7 & 0x40; VAR_9 = VAR_7 & 0x80; VAR_5 = (VAR_7 & 0x07) + 1; av_dlog(VAR_0->avctx, "image x=%d VAR_10=%d w=%d h=%d\VAR_14", VAR_1, VAR_2, VAR_3, VAR_4); if (VAR_9) { bytestream_get_buffer(&VAR_0->bytestream, VAR_0->local_palette, 3 * (1 << VAR_5)); palette = VAR_0->local_palette; } else { palette = VAR_0->global_palette; VAR_5 = VAR_0->VAR_5; } if (VAR_1 + VAR_3 > VAR_0->screen_width ||
VAR_2 + VAR_4 > VAR_0->screen_height)
return AVERROR(EINVAL); VAR_14 = (1 << VAR_5); spal = palette; for(VAR_15 = 0; VAR_15 < VAR_14; VAR_15++) { VAR_0->image_palette[VAR_15] = (0xffu << 24) | AV_RB24(spal); spal += 3; } for(; VAR_15 < 256; VAR_15++) VAR_0->image_palette[VAR_15] = (0xffu << 24); if (VAR_0->transparent_color_index >= 0)
VAR_0->image_palette[VAR_0->transparent_color_index] = 0; VAR_6 = bytestream_get_byte(&VAR_0->bytestream); ff_lzw_decode_init(VAR_0->lzw, VAR_6, VAR_0->bytestream,
VAR_0->bytestream_end - VAR_0->bytestream, FF_LZW_GIF); VAR_13 = VAR_0->picture.VAR_13[0]; ptr1 = VAR_0->picture.data[0] + VAR_2 * VAR_13 + VAR_1; ptr = ptr1; VAR_11 = 0; VAR_12 = 0; for (VAR_10 = 0; VAR_10 < VAR_4; VAR_10++) { ff_lzw_decode(VAR_0->lzw, ptr, VAR_3); if (VAR_8) { switch(VAR_11) { default:
case 0:
case 1:
VAR_12 += 8; ptr += VAR_13 * 8; if (VAR_12 >= VAR_4) { VAR_12 = VAR_11 ? 2 : 4; ptr = ptr1 + VAR_13 * VAR_12; VAR_11++; } break; case 2:
VAR_12 += 4; ptr += VAR_13 * 4; if (VAR_12 >= VAR_4) { VAR_12 = 1; ptr = ptr1 + VAR_13; VAR_11++; } break; case 3:
VAR_12 += 2; ptr += VAR_13 * 2; break; } } else { ptr += VAR_13; } } ff_lzw_decode_tail(VAR_0->lzw); VAR_0->bytestream = ff_lzw_cur_ptr(VAR_0->lzw); return 0; }