static int gif_image_write_image(ByteIOContext *pb, 

                                 int x1, int y1, int width, int height,

                                 const uint8_t *buf, int linesize, int pix_fmt)

{

    PutBitContext p;

    uint8_t buffer[200]; /* 100 * 9 / 8 = 113 */

    int i, left, w, v;

    const uint8_t *ptr;

    /* image block */



    put_byte(pb, 0x2c);

    put_le16(pb, x1);

    put_le16(pb, y1);

    put_le16(pb, width);

    put_le16(pb, height);

    put_byte(pb, 0x00); /* flags */

    /* no local clut */



    put_byte(pb, 0x08);



    left= width * height;



    init_put_bits(&p, buffer, 130);



/*

 * the thing here is the bitstream is written as little packets, with a size byte before

 * but it's still the same bitstream between packets (no flush !)

 */

    ptr = buf;

    w = width;

    while(left>0) {



        gif_put_bits_rev(&p, 9, 0x0100); /* clear code */



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

            if (pix_fmt == PIX_FMT_RGB24) {

                v = gif_clut_index(ptr[0], ptr[1], ptr[2]);

                ptr+=3;

            } else {

                v = *ptr++;

            }

            gif_put_bits_rev(&p, 9, v);

            if (--w == 0) {

                w = width;

                buf += linesize;

                ptr = buf;

            }

        }



        if(left<=GIF_CHUNKS) {

            gif_put_bits_rev(&p, 9, 0x101); /* end of stream */

            gif_flush_put_bits_rev(&p);

        }

        if(pbBufPtr(&p) - p.buf > 0) {

            put_byte(pb, pbBufPtr(&p) - p.buf); /* byte count of the packet */

            put_buffer(pb, p.buf, pbBufPtr(&p) - p.buf); /* the actual buffer */

            p.buf_ptr = p.buf; /* dequeue the bytes off the bitstream */

        }

        if(left<=GIF_CHUNKS) {

            put_byte(pb, 0x00); /* end of image block */

        }



        left-=GIF_CHUNKS;

    }

    return 0;

}

static int gif_image_write_image(ByteIOContext *pb, 

                                 int x1, int y1, int width, int height,

                                 const uint8_t *buf, int linesize, int pix_fmt)

{

    PutBitContext p;

    uint8_t buffer[200]; 

    int i, left, w, v;

    const uint8_t *ptr;

    



    put_byte(pb, 0x2c);

    put_le16(pb, x1);

    put_le16(pb, y1);

    put_le16(pb, width);

    put_le16(pb, height);

    put_byte(pb, 0x00); 

    



    put_byte(pb, 0x08);



    left= width * height;



    init_put_bits(&p, buffer, 130);











    ptr = buf;

    w = width;

    while(left>0) {



        gif_put_bits_rev(&p, 9, 0x0100); 



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

            if (pix_fmt == PIX_FMT_RGB24) {

                v = gif_clut_index(ptr[0], ptr[1], ptr[2]);

                ptr+=3;

            } else {

                v = *ptr++;

            }

            gif_put_bits_rev(&p, 9, v);

            if (--w == 0) {

                w = width;

                buf += linesize;

                ptr = buf;

            }

        }



        if(left<=GIF_CHUNKS) {

            gif_put_bits_rev(&p, 9, 0x101); 

            gif_flush_put_bits_rev(&p);

        }

        if(pbBufPtr(&p) - p.buf > 0) {

            put_byte(pb, pbBufPtr(&p) - p.buf); 

            put_buffer(pb, p.buf, pbBufPtr(&p) - p.buf); 

            p.buf_ptr = p.buf; 

        }

        if(left<=GIF_CHUNKS) {

            put_byte(pb, 0x00); 

        }



        left-=GIF_CHUNKS;

    }

    return 0;

}

        for(i=0;i<GIF_CHUNKS;i++) {         if(left<=GIF_CHUNKS) {
static int FUNC_0(ByteIOContext *VAR_0, 

                                 int VAR_1, int VAR_2, int VAR_3, int VAR_4,

                                 const uint8_t *VAR_5, int VAR_6, int VAR_7)

{

    PutBitContext p;

    uint8_t buffer[200]; 

    int VAR_8, VAR_9, VAR_10, VAR_11;

    const uint8_t *VAR_12;

    



    put_byte(VAR_0, 0x2c);

    put_le16(VAR_0, VAR_1);

    put_le16(VAR_0, VAR_2);

    put_le16(VAR_0, VAR_3);

    put_le16(VAR_0, VAR_4);

    put_byte(VAR_0, 0x00); 

    



    put_byte(VAR_0, 0x08);



    VAR_9= VAR_3 * VAR_4;



    init_put_bits(&p, buffer, 130);











    VAR_12 = VAR_5;

    VAR_10 = VAR_3;

    while(VAR_9>0) {



        gif_put_bits_rev(&p, 9, 0x0100); 



        for(VAR_8=0;VAR_8<GIF_CHUNKS;VAR_8++) {

            if (VAR_7 == PIX_FMT_RGB24) {

                VAR_11 = gif_clut_index(VAR_12[0], VAR_12[1], VAR_12[2]);

                VAR_12+=3;

            } else {

                VAR_11 = *VAR_12++;

            }

            gif_put_bits_rev(&p, 9, VAR_11);

            if (--VAR_10 == 0) {

                VAR_10 = VAR_3;

                VAR_5 += VAR_6;

                VAR_12 = VAR_5;

            }

        }



        if(VAR_9<=GIF_CHUNKS) {

            gif_put_bits_rev(&p, 9, 0x101); 

            gif_flush_put_bits_rev(&p);

        }

        if(pbBufPtr(&p) - p.VAR_5 > 0) {

            put_byte(VAR_0, pbBufPtr(&p) - p.VAR_5); 

            put_buffer(VAR_0, p.VAR_5, pbBufPtr(&p) - p.VAR_5); 

            p.buf_ptr = p.VAR_5; 

        }

        if(VAR_9<=GIF_CHUNKS) {

            put_byte(VAR_0, 0x00); 

        }



        VAR_9-=GIF_CHUNKS;

    }

    return 0;

}

static int FUNC_0(ByteIOContext *VAR_0,
int VAR_1, int VAR_2, int VAR_3, int VAR_4,
const uint8_t *VAR_5, int VAR_6, int VAR_7)
{ PutBitContext p; uint8_t buffer[200]; int VAR_8, VAR_9, VAR_10, VAR_11; const uint8_t *VAR_12; put_byte(VAR_0, 0x2c); put_le16(VAR_0, VAR_1); put_le16(VAR_0, VAR_2); put_le16(VAR_0, VAR_3); put_le16(VAR_0, VAR_4); put_byte(VAR_0, 0x00); put_byte(VAR_0, 0x08); VAR_9= VAR_3 * VAR_4; init_put_bits(&p, buffer, 130); VAR_12 = VAR_5; VAR_10 = VAR_3; while(VAR_9>0) { gif_put_bits_rev(&p, 9, 0x0100); for(VAR_8=0;VAR_8<GIF_CHUNKS;VAR_8++) { if (VAR_7 == PIX_FMT_RGB24) { VAR_11 = gif_clut_index(VAR_12[0], VAR_12[1], VAR_12[2]); VAR_12+=3; } else { VAR_11 = *VAR_12++; } gif_put_bits_rev(&p, 9, VAR_11); if (--VAR_10 == 0) { VAR_10 = VAR_3; VAR_5 += VAR_6; VAR_12 = VAR_5; } } if(VAR_9<=GIF_CHUNKS) { gif_put_bits_rev(&p, 9, 0x101); gif_flush_put_bits_rev(&p); } if(pbBufPtr(&p) - p.VAR_5 > 0) { put_byte(VAR_0, pbBufPtr(&p) - p.VAR_5); put_buffer(VAR_0, p.VAR_5, pbBufPtr(&p) - p.VAR_5); p.buf_ptr = p.VAR_5; } if(VAR_9<=GIF_CHUNKS) { put_byte(VAR_0, 0x00); } VAR_9-=GIF_CHUNKS; } return 0; }