Mercurial > libavcodec.hg
comparison pngdec.c @ 5339:a8c48a070cff libavcodec
hardly anything in PNGContext is shared; split it
author | mru |
---|---|
date | Sun, 15 Jul 2007 19:23:55 +0000 |
parents | 26f4095e35d2 |
children | 45d083bbbbe7 |
comparison
equal
deleted
inserted
replaced
5338:5c1695f0f3e4 | 5339:a8c48a070cff |
---|---|
28 | 28 |
29 #include <zlib.h> | 29 #include <zlib.h> |
30 | 30 |
31 //#define DEBUG | 31 //#define DEBUG |
32 | 32 |
33 typedef struct PNGDecContext { | |
34 uint8_t *bytestream; | |
35 uint8_t *bytestream_start; | |
36 uint8_t *bytestream_end; | |
37 AVFrame picture; | |
38 | |
39 int state; | |
40 int width, height; | |
41 int bit_depth; | |
42 int color_type; | |
43 int compression_type; | |
44 int interlace_type; | |
45 int filter_type; | |
46 int channels; | |
47 int bits_per_pixel; | |
48 int bpp; | |
49 | |
50 uint8_t *image_buf; | |
51 int image_linesize; | |
52 uint32_t palette[256]; | |
53 uint8_t *crow_buf; | |
54 uint8_t *last_row; | |
55 uint8_t *tmp_row; | |
56 int pass; | |
57 int crow_size; /* compressed row size (include filter type) */ | |
58 int row_size; /* decompressed row size */ | |
59 int pass_row_size; /* decompress row size of the current pass */ | |
60 int y; | |
61 z_stream zstream; | |
62 } PNGDecContext; | |
63 | |
33 /* Mask to determine which y pixels can be written in a pass */ | 64 /* Mask to determine which y pixels can be written in a pass */ |
34 static const uint8_t png_pass_dsp_ymask[NB_PASSES] = { | 65 static const uint8_t png_pass_dsp_ymask[NB_PASSES] = { |
35 0xff, 0xff, 0x0f, 0xcc, 0x33, 0xff, 0x55, | 66 0xff, 0xff, 0x0f, 0xcc, 0x33, 0xff, 0x55, |
36 }; | 67 }; |
37 | 68 |
180 src += 4; | 211 src += 4; |
181 } | 212 } |
182 } | 213 } |
183 | 214 |
184 /* process exactly one decompressed row */ | 215 /* process exactly one decompressed row */ |
185 static void png_handle_row(PNGContext *s) | 216 static void png_handle_row(PNGDecContext *s) |
186 { | 217 { |
187 uint8_t *ptr, *last_row; | 218 uint8_t *ptr, *last_row; |
188 int got_line; | 219 int got_line; |
189 | 220 |
190 if (!s->interlace_type) { | 221 if (!s->interlace_type) { |
250 } | 281 } |
251 the_end: ; | 282 the_end: ; |
252 } | 283 } |
253 } | 284 } |
254 | 285 |
255 static int png_decode_idat(PNGContext *s, int length) | 286 static int png_decode_idat(PNGDecContext *s, int length) |
256 { | 287 { |
257 int ret; | 288 int ret; |
258 s->zstream.avail_in = length; | 289 s->zstream.avail_in = length; |
259 s->zstream.next_in = s->bytestream; | 290 s->zstream.next_in = s->bytestream; |
260 s->bytestream += length; | 291 s->bytestream += length; |
281 | 312 |
282 static int decode_frame(AVCodecContext *avctx, | 313 static int decode_frame(AVCodecContext *avctx, |
283 void *data, int *data_size, | 314 void *data, int *data_size, |
284 uint8_t *buf, int buf_size) | 315 uint8_t *buf, int buf_size) |
285 { | 316 { |
286 PNGContext * const s = avctx->priv_data; | 317 PNGDecContext * const s = avctx->priv_data; |
287 AVFrame *picture = data; | 318 AVFrame *picture = data; |
288 AVFrame * const p= (AVFrame*)&s->picture; | 319 AVFrame * const p= (AVFrame*)&s->picture; |
289 uint32_t tag, length; | 320 uint32_t tag, length; |
290 int ret, crc; | 321 int ret, crc; |
291 | 322 |
297 if (memcmp(s->bytestream, ff_pngsig, 8) != 0) | 328 if (memcmp(s->bytestream, ff_pngsig, 8) != 0) |
298 return -1; | 329 return -1; |
299 s->bytestream+= 8; | 330 s->bytestream+= 8; |
300 s->y= | 331 s->y= |
301 s->state=0; | 332 s->state=0; |
302 // memset(s, 0, sizeof(PNGContext)); | 333 // memset(s, 0, sizeof(PNGDecContext)); |
303 /* init the zlib */ | 334 /* init the zlib */ |
304 s->zstream.zalloc = ff_png_zalloc; | 335 s->zstream.zalloc = ff_png_zalloc; |
305 s->zstream.zfree = ff_png_zfree; | 336 s->zstream.zfree = ff_png_zfree; |
306 s->zstream.opaque = NULL; | 337 s->zstream.opaque = NULL; |
307 ret = inflateInit(&s->zstream); | 338 ret = inflateInit(&s->zstream); |
496 fail: | 527 fail: |
497 ret = -1; | 528 ret = -1; |
498 goto the_end; | 529 goto the_end; |
499 } | 530 } |
500 | 531 |
532 static int png_dec_init(AVCodecContext *avctx){ | |
533 PNGDecContext *s = avctx->priv_data; | |
534 | |
535 avcodec_get_frame_defaults((AVFrame*)&s->picture); | |
536 avctx->coded_frame= (AVFrame*)&s->picture; | |
537 | |
538 return 0; | |
539 } | |
540 | |
501 AVCodec png_decoder = { | 541 AVCodec png_decoder = { |
502 "png", | 542 "png", |
503 CODEC_TYPE_VIDEO, | 543 CODEC_TYPE_VIDEO, |
504 CODEC_ID_PNG, | 544 CODEC_ID_PNG, |
505 sizeof(PNGContext), | 545 sizeof(PNGDecContext), |
506 ff_png_common_init, | 546 png_dec_init, |
507 NULL, | 547 NULL, |
508 NULL, //decode_end, | 548 NULL, //decode_end, |
509 decode_frame, | 549 decode_frame, |
510 0 /*CODEC_CAP_DR1*/ /*| CODEC_CAP_DRAW_HORIZ_BAND*/, | 550 0 /*CODEC_CAP_DR1*/ /*| CODEC_CAP_DRAW_HORIZ_BAND*/, |
511 NULL | 551 NULL |