Mercurial > libavcodec.hg
comparison pngdec.c @ 9387:cd207441ca56 libavcodec
Add support to CorePNG P-frames.
Patch by Thilo Borgmann thilo DOT borgmann A googlemail com.
author | stefano |
---|---|
date | Fri, 10 Apr 2009 17:16:19 +0000 |
parents | 54bc8a2727b0 |
children | 05cf2547e0f0 |
comparison
equal
deleted
inserted
replaced
9386:a673af90ed8f | 9387:cd207441ca56 |
---|---|
35 DSPContext dsp; | 35 DSPContext dsp; |
36 | 36 |
37 const uint8_t *bytestream; | 37 const uint8_t *bytestream; |
38 const uint8_t *bytestream_start; | 38 const uint8_t *bytestream_start; |
39 const uint8_t *bytestream_end; | 39 const uint8_t *bytestream_end; |
40 AVFrame picture; | 40 AVFrame picture1, picture2; |
41 AVFrame *current_picture, *last_picture; | |
41 | 42 |
42 int state; | 43 int state; |
43 int width, height; | 44 int width, height; |
44 int bit_depth; | 45 int bit_depth; |
45 int color_type; | 46 int color_type; |
383 { | 384 { |
384 const uint8_t *buf = avpkt->data; | 385 const uint8_t *buf = avpkt->data; |
385 int buf_size = avpkt->size; | 386 int buf_size = avpkt->size; |
386 PNGDecContext * const s = avctx->priv_data; | 387 PNGDecContext * const s = avctx->priv_data; |
387 AVFrame *picture = data; | 388 AVFrame *picture = data; |
388 AVFrame * const p= &s->picture; | 389 AVFrame *p; |
389 uint32_t tag, length; | 390 uint32_t tag, length; |
390 int ret, crc; | 391 int ret, crc; |
392 | |
393 FFSWAP(AVFrame *, s->current_picture, s->last_picture); | |
394 avctx->coded_frame= s->current_picture; | |
395 p = s->current_picture; | |
391 | 396 |
392 s->bytestream_start= | 397 s->bytestream_start= |
393 s->bytestream= buf; | 398 s->bytestream= buf; |
394 s->bytestream_end= buf + buf_size; | 399 s->bytestream_end= buf + buf_size; |
395 | 400 |
582 s->bytestream += length + 4; | 587 s->bytestream += length + 4; |
583 break; | 588 break; |
584 } | 589 } |
585 } | 590 } |
586 exit_loop: | 591 exit_loop: |
587 *picture= s->picture; | 592 /* handle p-frames only if a predecessor frame is available */ |
593 if(s->last_picture->data[0] != NULL) { | |
594 if(!(avpkt->flags & PKT_FLAG_KEY)) { | |
595 int i, j; | |
596 uint8_t *pd = s->current_picture->data[0]; | |
597 uint8_t *pd_last = s->last_picture->data[0]; | |
598 | |
599 for(j=0; j < s->height; j++) { | |
600 for(i=0; i < s->width * s->bpp; i++) { | |
601 pd[i] += pd_last[i]; | |
602 } | |
603 pd += s->image_linesize; | |
604 pd_last += s->image_linesize; | |
605 } | |
606 } | |
607 } | |
608 | |
609 *picture= *s->current_picture; | |
588 *data_size = sizeof(AVFrame); | 610 *data_size = sizeof(AVFrame); |
589 | 611 |
590 ret = s->bytestream - s->bytestream_start; | 612 ret = s->bytestream - s->bytestream_start; |
591 the_end: | 613 the_end: |
592 inflateEnd(&s->zstream); | 614 inflateEnd(&s->zstream); |
600 } | 622 } |
601 | 623 |
602 static av_cold int png_dec_init(AVCodecContext *avctx){ | 624 static av_cold int png_dec_init(AVCodecContext *avctx){ |
603 PNGDecContext *s = avctx->priv_data; | 625 PNGDecContext *s = avctx->priv_data; |
604 | 626 |
605 avcodec_get_frame_defaults(&s->picture); | 627 s->current_picture = &s->picture1; |
606 avctx->coded_frame= &s->picture; | 628 s->last_picture = &s->picture2; |
629 avcodec_get_frame_defaults(&s->picture1); | |
630 avcodec_get_frame_defaults(&s->picture2); | |
607 dsputil_init(&s->dsp, avctx); | 631 dsputil_init(&s->dsp, avctx); |
608 | 632 |
609 return 0; | 633 return 0; |
610 } | 634 } |
611 | 635 |