~ubuntu-branches/ubuntu/precise/ffmpeg-debian/precise

« back to all changes in this revision

Viewing changes to libavcodec/gif.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2009-01-20 09:20:53 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090120092053-izz63p40hc98qfgp
Tags: 3:0.svn20090119-1ubuntu1
* merge from debian. LP: #318501
* new version fixes CVE-2008-3230, LP: #253767

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
 
44
44
#include "avcodec.h"
45
45
#include "bytestream.h"
 
46
 
 
47
/* The GIF format uses reversed order for bitstreams... */
 
48
/* at least they don't use PDP_ENDIAN :) */
 
49
#define BITSTREAM_WRITER_LE
 
50
 
46
51
#include "bitstream.h"
47
52
 
48
53
/* bitstream minipacket size */
104
109
    { 0xff, 0xff, 0x00 }, { 0xff, 0xff, 0x33 }, { 0xff, 0xff, 0x66 }, { 0xff, 0xff, 0x99 }, { 0xff, 0xff, 0xcc }, { 0xff, 0xff, 0xff },
105
110
};
106
111
 
107
 
/* The GIF format uses reversed order for bitstreams... */
108
 
/* at least they don't use PDP_ENDIAN :) */
109
 
/* so we 'extend' PutBitContext. hmmm, OOP :) */
110
 
/* seems this thing changed slightly since I wrote it... */
111
 
 
112
 
#ifdef ALT_BITSTREAM_WRITER
113
 
# error no ALT_BITSTREAM_WRITER support for now
114
 
#endif
115
 
 
116
 
static void gif_put_bits_rev(PutBitContext *s, int n, unsigned int value)
117
 
{
118
 
    unsigned int bit_buf;
119
 
    int bit_cnt;
120
 
 
121
 
    //    printf("put_bits=%d %x\n", n, value);
122
 
    assert(n == 32 || value < (1U << n));
123
 
 
124
 
    bit_buf = s->bit_buf;
125
 
    bit_cnt = 32 - s->bit_left; /* XXX:lazyness... was = s->bit_cnt; */
126
 
 
127
 
    //    printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);
128
 
    /* XXX: optimize */
129
 
    if (n < (32-bit_cnt)) {
130
 
        bit_buf |= value << (bit_cnt);
131
 
        bit_cnt+=n;
132
 
    } else {
133
 
        bit_buf |= value << (bit_cnt);
134
 
 
135
 
        bytestream_put_le32(&s->buf_ptr, bit_buf);
136
 
 
137
 
        //printf("bitbuf = %08x\n", bit_buf);
138
 
        if (s->buf_ptr >= s->buf_end)
139
 
            abort();
140
 
//            flush_buffer_rev(s);
141
 
        bit_cnt=bit_cnt + n - 32;
142
 
        if (bit_cnt == 0) {
143
 
            bit_buf = 0;
144
 
        } else {
145
 
            bit_buf = value >> (n - bit_cnt);
146
 
        }
147
 
    }
148
 
 
149
 
    s->bit_buf = bit_buf;
150
 
    s->bit_left = 32 - bit_cnt;
151
 
}
152
 
 
153
 
/* pad the end of the output stream with zeros */
154
 
static void gif_flush_put_bits_rev(PutBitContext *s)
155
 
{
156
 
    while (s->bit_left < 32) {
157
 
        /* XXX: should test end of buffer */
158
 
        *s->buf_ptr++=s->bit_buf & 0xff;
159
 
        s->bit_buf>>=8;
160
 
        s->bit_left+=8;
161
 
    }
162
 
//    flush_buffer_rev(s);
163
 
    s->bit_left=32;
164
 
    s->bit_buf=0;
165
 
}
166
 
 
167
 
/* !RevPutBitContext */
168
 
 
169
112
/* GIF header */
170
113
static int gif_image_write_header(uint8_t **bytestream,
171
114
                                  int width, int height, int loop_count,
269
212
    w = width;
270
213
    while(left>0) {
271
214
 
272
 
        gif_put_bits_rev(&p, 9, 0x0100); /* clear code */
 
215
        put_bits(&p, 9, 0x0100); /* clear code */
273
216
 
274
217
        for(i=(left<GIF_CHUNKS)?left:GIF_CHUNKS;i;i--) {
275
218
            if (pix_fmt == PIX_FMT_RGB24) {
278
221
            } else {
279
222
                v = *ptr++;
280
223
            }
281
 
            gif_put_bits_rev(&p, 9, v);
 
224
            put_bits(&p, 9, v);
282
225
            if (--w == 0) {
283
226
                w = width;
284
227
                buf += linesize;
287
230
        }
288
231
 
289
232
        if(left<=GIF_CHUNKS) {
290
 
            gif_put_bits_rev(&p, 9, 0x101); /* end of stream */
291
 
            gif_flush_put_bits_rev(&p);
 
233
            put_bits(&p, 9, 0x101); /* end of stream */
 
234
            flush_put_bits(&p);
292
235
        }
293
236
        if(pbBufPtr(&p) - p.buf > 0) {
294
237
            bytestream_put_byte(bytestream, pbBufPtr(&p) - p.buf); /* byte count of the packet */