~ubuntu-branches/ubuntu/trusty/gst-libav1.0/trusty-proposed

« back to all changes in this revision

Viewing changes to gst-libs/ext/libav/libavcodec/pngdec.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2013-09-24 17:07:00 UTC
  • mfrom: (1.1.17) (7.1.9 experimental)
  • Revision ID: package-import@ubuntu.com-20130924170700-4dg62s3pwl0pdakz
Tags: 1.2.0-1
* New upstream stable release:
  + debian/control:
    - Build depend on GStreamer and gst-plugins-base >= 1.2.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include "libavutil/imgutils.h"
22
22
#include "avcodec.h"
23
23
#include "bytestream.h"
 
24
#include "internal.h"
24
25
#include "png.h"
25
 
#include "dsputil.h"
 
26
#include "pngdsp.h"
26
27
 
27
28
/* TODO:
28
29
 * - add 2, 4 and 16 bit depth support
33
34
//#define DEBUG
34
35
 
35
36
typedef struct PNGDecContext {
36
 
    DSPContext dsp;
 
37
    PNGDSPContext dsp;
37
38
 
38
39
    GetByteContext gb;
39
40
    AVFrame picture1, picture2;
189
190
    }
190
191
 
191
192
/* NOTE: 'dst' can be equal to 'last' */
192
 
static void png_filter_row(DSPContext *dsp, uint8_t *dst, int filter_type,
 
193
static void png_filter_row(PNGDSPContext *dsp, uint8_t *dst, int filter_type,
193
194
                           uint8_t *src, uint8_t *last, int size, int bpp)
194
195
{
195
196
    int i, p, r, g, b, a;
233
234
        if(bpp > 1 && size > 4) {
234
235
            // would write off the end of the array if we let it process the last pixel with bpp=3
235
236
            int w = bpp==4 ? size : size-3;
236
 
            dsp->add_png_paeth_prediction(dst+i, src+i, last+i, w-i, bpp);
 
237
            dsp->add_paeth_prediction(dst+i, src+i, last+i, w-i, bpp);
237
238
            i = w;
238
239
        }
239
240
        ff_add_png_paeth_prediction(dst+i, src+i, last+i, size-i, bpp);
382
383
}
383
384
 
384
385
static int decode_frame(AVCodecContext *avctx,
385
 
                        void *data, int *data_size,
 
386
                        void *data, int *got_frame,
386
387
                        AVPacket *avpkt)
387
388
{
388
389
    const uint8_t *buf = avpkt->data;
463
464
 
464
465
                if (s->bit_depth == 8 &&
465
466
                    s->color_type == PNG_COLOR_TYPE_RGB) {
466
 
                    avctx->pix_fmt = PIX_FMT_RGB24;
 
467
                    avctx->pix_fmt = AV_PIX_FMT_RGB24;
467
468
                } else if (s->bit_depth == 8 &&
468
469
                           s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
469
 
                    avctx->pix_fmt = PIX_FMT_RGB32;
 
470
                    avctx->pix_fmt = AV_PIX_FMT_RGB32;
470
471
                } else if (s->bit_depth == 8 &&
471
472
                           s->color_type == PNG_COLOR_TYPE_GRAY) {
472
 
                    avctx->pix_fmt = PIX_FMT_GRAY8;
 
473
                    avctx->pix_fmt = AV_PIX_FMT_GRAY8;
473
474
                } else if (s->bit_depth == 16 &&
474
475
                           s->color_type == PNG_COLOR_TYPE_GRAY) {
475
 
                    avctx->pix_fmt = PIX_FMT_GRAY16BE;
 
476
                    avctx->pix_fmt = AV_PIX_FMT_GRAY16BE;
476
477
                } else if (s->bit_depth == 16 &&
477
478
                           s->color_type == PNG_COLOR_TYPE_RGB) {
478
 
                    avctx->pix_fmt = PIX_FMT_RGB48BE;
 
479
                    avctx->pix_fmt = AV_PIX_FMT_RGB48BE;
479
480
                } else if (s->bit_depth == 1 &&
480
481
                           s->color_type == PNG_COLOR_TYPE_GRAY) {
481
 
                    avctx->pix_fmt = PIX_FMT_MONOBLACK;
 
482
                    avctx->pix_fmt = AV_PIX_FMT_MONOBLACK;
482
483
                } else if (s->bit_depth == 8 &&
483
484
                           s->color_type == PNG_COLOR_TYPE_PALETTE) {
484
 
                    avctx->pix_fmt = PIX_FMT_PAL8;
 
485
                    avctx->pix_fmt = AV_PIX_FMT_PAL8;
485
486
                } else if (s->bit_depth == 8 &&
486
487
                           s->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
487
 
                    avctx->pix_fmt = PIX_FMT_Y400A;
 
488
                    avctx->pix_fmt = AV_PIX_FMT_Y400A;
488
489
                } else {
489
490
                    goto fail;
490
491
                }
492
493
                    avctx->release_buffer(avctx, p);
493
494
 
494
495
                p->reference= 0;
495
 
                if(avctx->get_buffer(avctx, p) < 0){
 
496
                if(ff_get_buffer(avctx, p) < 0){
496
497
                    av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
497
498
                    goto fail;
498
499
                }
610
611
    }
611
612
 
612
613
    *picture= *s->current_picture;
613
 
    *data_size = sizeof(AVFrame);
 
614
    *got_frame = 1;
614
615
 
615
616
    ret = bytestream2_tell(&s->gb);
616
617
 the_end:
632
633
    s->last_picture = &s->picture2;
633
634
    avcodec_get_frame_defaults(&s->picture1);
634
635
    avcodec_get_frame_defaults(&s->picture2);
635
 
    dsputil_init(&s->dsp, avctx);
 
636
    ff_pngdsp_init(&s->dsp);
636
637
 
637
638
    return 0;
638
639
}
652
653
AVCodec ff_png_decoder = {
653
654
    .name           = "png",
654
655
    .type           = AVMEDIA_TYPE_VIDEO,
655
 
    .id             = CODEC_ID_PNG,
 
656
    .id             = AV_CODEC_ID_PNG,
656
657
    .priv_data_size = sizeof(PNGDecContext),
657
658
    .init           = png_dec_init,
658
659
    .close          = png_dec_end,
659
660
    .decode         = decode_frame,
660
661
    .capabilities   = CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/,
661
 
    .long_name = NULL_IF_CONFIG_SMALL("PNG image"),
 
662
    .long_name      = NULL_IF_CONFIG_SMALL("PNG (Portable Network Graphics) image"),
662
663
};