104
109
{ 0xff, 0xff, 0x00 }, { 0xff, 0xff, 0x33 }, { 0xff, 0xff, 0x66 }, { 0xff, 0xff, 0x99 }, { 0xff, 0xff, 0xcc }, { 0xff, 0xff, 0xff },
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... */
112
#ifdef ALT_BITSTREAM_WRITER
113
# error no ALT_BITSTREAM_WRITER support for now
116
static void gif_put_bits_rev(PutBitContext *s, int n, unsigned int value)
118
unsigned int bit_buf;
121
// printf("put_bits=%d %x\n", n, value);
122
assert(n == 32 || value < (1U << n));
124
bit_buf = s->bit_buf;
125
bit_cnt = 32 - s->bit_left; /* XXX:lazyness... was = s->bit_cnt; */
127
// printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);
129
if (n < (32-bit_cnt)) {
130
bit_buf |= value << (bit_cnt);
133
bit_buf |= value << (bit_cnt);
135
bytestream_put_le32(&s->buf_ptr, bit_buf);
137
//printf("bitbuf = %08x\n", bit_buf);
138
if (s->buf_ptr >= s->buf_end)
140
// flush_buffer_rev(s);
141
bit_cnt=bit_cnt + n - 32;
145
bit_buf = value >> (n - bit_cnt);
149
s->bit_buf = bit_buf;
150
s->bit_left = 32 - bit_cnt;
153
/* pad the end of the output stream with zeros */
154
static void gif_flush_put_bits_rev(PutBitContext *s)
156
while (s->bit_left < 32) {
157
/* XXX: should test end of buffer */
158
*s->buf_ptr++=s->bit_buf & 0xff;
162
// flush_buffer_rev(s);
167
/* !RevPutBitContext */
170
113
static int gif_image_write_header(uint8_t **bytestream,
171
114
int width, int height, int loop_count,
272
gif_put_bits_rev(&p, 9, 0x0100); /* clear code */
215
put_bits(&p, 9, 0x0100); /* clear code */
274
217
for(i=(left<GIF_CHUNKS)?left:GIF_CHUNKS;i;i--) {
275
218
if (pix_fmt == PIX_FMT_RGB24) {
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 */
293
236
if(pbBufPtr(&p) - p.buf > 0) {
294
237
bytestream_put_byte(bytestream, pbBufPtr(&p) - p.buf); /* byte count of the packet */