comparison gifdec.c @ 4652:6679d37a3338 libavcodec

Give context to dprintf
author mbardiaux
date Mon, 12 Mar 2007 12:36:41 +0000
parents 9bf957e669f0
children dd9ad0da0a51
comparison
equal deleted inserted replaced
4651:ff9749708137 4652:6679d37a3338
51 LZWState *lzw; 51 LZWState *lzw;
52 52
53 /* aux buffers */ 53 /* aux buffers */
54 uint8_t global_palette[256 * 3]; 54 uint8_t global_palette[256 * 3];
55 uint8_t local_palette[256 * 3]; 55 uint8_t local_palette[256 * 3];
56
57 AVCodecContext* avctx;
56 } GifState; 58 } GifState;
57 59
58 static const uint8_t gif87a_sig[6] = "GIF87a"; 60 static const uint8_t gif87a_sig[6] = "GIF87a";
59 static const uint8_t gif89a_sig[6] = "GIF89a"; 61 static const uint8_t gif89a_sig[6] = "GIF89a";
60 62
71 flags = bytestream_get_byte(&s->bytestream); 73 flags = bytestream_get_byte(&s->bytestream);
72 is_interleaved = flags & 0x40; 74 is_interleaved = flags & 0x40;
73 has_local_palette = flags & 0x80; 75 has_local_palette = flags & 0x80;
74 bits_per_pixel = (flags & 0x07) + 1; 76 bits_per_pixel = (flags & 0x07) + 1;
75 #ifdef DEBUG 77 #ifdef DEBUG
76 dprintf("gif: image x=%d y=%d w=%d h=%d\n", left, top, width, height); 78 dprintf(s->avctx, "gif: image x=%d y=%d w=%d h=%d\n", left, top, width, height);
77 #endif 79 #endif
78 80
79 if (has_local_palette) { 81 if (has_local_palette) {
80 bytestream_get_buffer(&s->bytestream, s->local_palette, 3 * (1 << bits_per_pixel)); 82 bytestream_get_buffer(&s->bytestream, s->local_palette, 3 * (1 << bits_per_pixel));
81 palette = s->local_palette; 83 palette = s->local_palette;
162 164
163 /* extension */ 165 /* extension */
164 ext_code = bytestream_get_byte(&s->bytestream); 166 ext_code = bytestream_get_byte(&s->bytestream);
165 ext_len = bytestream_get_byte(&s->bytestream); 167 ext_len = bytestream_get_byte(&s->bytestream);
166 #ifdef DEBUG 168 #ifdef DEBUG
167 dprintf("gif: ext_code=0x%x len=%d\n", ext_code, ext_len); 169 dprintf(s->avctx, "gif: ext_code=0x%x len=%d\n", ext_code, ext_len);
168 #endif 170 #endif
169 switch(ext_code) { 171 switch(ext_code) {
170 case 0xf9: 172 case 0xf9:
171 if (ext_len != 4) 173 if (ext_len != 4)
172 goto discard_ext; 174 goto discard_ext;
178 s->transparent_color_index = gce_transparent_index; 180 s->transparent_color_index = gce_transparent_index;
179 else 181 else
180 s->transparent_color_index = -1; 182 s->transparent_color_index = -1;
181 s->gce_disposal = (gce_flags >> 2) & 0x7; 183 s->gce_disposal = (gce_flags >> 2) & 0x7;
182 #ifdef DEBUG 184 #ifdef DEBUG
183 dprintf("gif: gce_flags=%x delay=%d tcolor=%d disposal=%d\n", 185 dprintf(s->avctx, "gif: gce_flags=%x delay=%d tcolor=%d disposal=%d\n",
184 gce_flags, s->gce_delay, 186 gce_flags, s->gce_delay,
185 s->transparent_color_index, s->gce_disposal); 187 s->transparent_color_index, s->gce_disposal);
186 #endif 188 #endif
187 ext_len = bytestream_get_byte(&s->bytestream); 189 ext_len = bytestream_get_byte(&s->bytestream);
188 break; 190 break;
193 while (ext_len != 0) { 195 while (ext_len != 0) {
194 for (i = 0; i < ext_len; i++) 196 for (i = 0; i < ext_len; i++)
195 bytestream_get_byte(&s->bytestream); 197 bytestream_get_byte(&s->bytestream);
196 ext_len = bytestream_get_byte(&s->bytestream); 198 ext_len = bytestream_get_byte(&s->bytestream);
197 #ifdef DEBUG 199 #ifdef DEBUG
198 dprintf("gif: ext_len1=%d\n", ext_len); 200 dprintf(s->avctx, "gif: ext_len1=%d\n", ext_len);
199 #endif 201 #endif
200 } 202 }
201 return 0; 203 return 0;
202 } 204 }
203 205
228 has_global_palette = (v & 0x80); 230 has_global_palette = (v & 0x80);
229 s->bits_per_pixel = (v & 0x07) + 1; 231 s->bits_per_pixel = (v & 0x07) + 1;
230 s->background_color_index = bytestream_get_byte(&s->bytestream); 232 s->background_color_index = bytestream_get_byte(&s->bytestream);
231 bytestream_get_byte(&s->bytestream); /* ignored */ 233 bytestream_get_byte(&s->bytestream); /* ignored */
232 #ifdef DEBUG 234 #ifdef DEBUG
233 dprintf("gif: screen_w=%d screen_h=%d bpp=%d global_palette=%d\n", 235 dprintf(s->avctx, "gif: screen_w=%d screen_h=%d bpp=%d global_palette=%d\n",
234 s->screen_width, s->screen_height, s->bits_per_pixel, 236 s->screen_width, s->screen_height, s->bits_per_pixel,
235 has_global_palette); 237 has_global_palette);
236 #endif 238 #endif
237 if (has_global_palette) { 239 if (has_global_palette) {
238 n = 1 << s->bits_per_pixel; 240 n = 1 << s->bits_per_pixel;
246 int ret, code; 248 int ret, code;
247 249
248 for (;;) { 250 for (;;) {
249 code = bytestream_get_byte(&s->bytestream); 251 code = bytestream_get_byte(&s->bytestream);
250 #ifdef DEBUG 252 #ifdef DEBUG
251 dprintf("gif: code=%02x '%c'\n", code, code); 253 dprintf(s->avctx, "gif: code=%02x '%c'\n", code, code);
252 #endif 254 #endif
253 switch (code) { 255 switch (code) {
254 case ',': 256 case ',':
255 if (gif_read_image(s) < 0) 257 if (gif_read_image(s) < 0)
256 return -1; 258 return -1;
277 279
278 static int gif_decode_init(AVCodecContext *avctx) 280 static int gif_decode_init(AVCodecContext *avctx)
279 { 281 {
280 GifState *s = avctx->priv_data; 282 GifState *s = avctx->priv_data;
281 283
284 s->avctx = avctx;
285
282 avcodec_get_frame_defaults(&s->picture); 286 avcodec_get_frame_defaults(&s->picture);
283 avctx->coded_frame= &s->picture; 287 avctx->coded_frame= &s->picture;
284 s->picture.data[0] = NULL; 288 s->picture.data[0] = NULL;
285 ff_lzw_decode_open(&s->lzw); 289 ff_lzw_decode_open(&s->lzw);
286 return 0; 290 return 0;