summaryrefslogtreecommitdiff
path: root/libavcodec/pngenc.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-02-18 02:20:19 +0100
committerMichael Niedermayer <michaelni@gmx.at>2012-02-18 02:20:19 +0100
commitbbb61a1cd5cb2046e480f367a7ae58a32f2ef907 (patch)
tree0e7cc2b59558e2dc31d6b8752d90f6b5b5c886e5 /libavcodec/pngenc.c
parentf6492476a63938cc66c51bf61c88407b7749f780 (diff)
parentaf468015d972c0dec5c8c37b2685ffa5cbe4ae87 (diff)
Merge remote-tracking branch 'qatar/master'
* qatar/master: (22 commits) als: prevent infinite loop in zero_remaining(). cook: prevent div-by-zero if channels is zero. pamenc: switch to encode2(). svq1enc: switch to encode2(). dvenc: switch to encode2(). dpxenc: switch to encode2(). pngenc: switch to encode2(). v210enc: switch to encode2(). xwdenc: switch to encode2(). ttadec: use branchless unsigned-to-signed unfolding avcodec: add a Sun Rasterfile encoder sunrast: Move common defines to a new header file. cdxl: fix video decoding for some files cdxl: fix audio for some samples apetag: add proper support for binary tags ttadec: remove dead code swscale: make access to filter data conditional on filter type. swscale: update context offsets after removal of AlpMmxFilter. prores: initialise encoder and decoder parts only when needed swscale: make monowhite/black RGB-independent. ... Conflicts: Changelog libavcodec/alsdec.c libavcodec/dpxenc.c libavcodec/golomb.h libavcodec/pamenc.c libavcodec/pngenc.c libavformat/img2.c libswscale/output.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/pngenc.c')
-rw-r--r--libavcodec/pngenc.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c
index 69ca8e469d..60b896473a 100644
--- a/libavcodec/pngenc.c
+++ b/libavcodec/pngenc.c
@@ -212,12 +212,13 @@ static int png_write_row(PNGEncContext *s, const uint8_t *data, int size)
return 0;
}
-static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
+static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
+ const AVFrame *pict, int *got_packet)
+{
PNGEncContext *s = avctx->priv_data;
- AVFrame *pict = data;
AVFrame * const p= &s->picture;
int bit_depth, color_type, y, len, row_size, ret, is_progressive;
- int bits_per_pixel, pass_row_size;
+ int bits_per_pixel, pass_row_size, max_packet_size;
int compression_level;
uint8_t *ptr, *top;
uint8_t *crow_base = NULL, *crow_buf, *crow;
@@ -228,9 +229,17 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
p->pict_type= AV_PICTURE_TYPE_I;
p->key_frame= 1;
- s->bytestream_start=
- s->bytestream= buf;
- s->bytestream_end= buf+buf_size;
+ max_packet_size = IOBUF_SIZE*avctx->height + FF_MIN_BUFFER_SIZE;
+ if (!pkt->data &&
+ (ret = av_new_packet(pkt, max_packet_size)) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Could not allocate output packet of size %d.\n",
+ max_packet_size);
+ return ret;
+ }
+
+ s->bytestream_start =
+ s->bytestream = pkt->data;
+ s->bytestream_end = pkt->data + pkt->size;
is_progressive = !!(avctx->flags & CODEC_FLAG_INTERLACED_DCT);
switch(avctx->pix_fmt) {
@@ -393,7 +402,11 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
}
png_write_chunk(&s->bytestream, MKTAG('I', 'E', 'N', 'D'), NULL, 0);
- ret = s->bytestream - s->bytestream_start;
+ pkt->size = s->bytestream - s->bytestream_start;
+ pkt->flags |= AV_PKT_FLAG_KEY;
+ *got_packet = 1;
+ ret = 0;
+
the_end:
av_free(crow_base);
av_free(progressive_buf);
@@ -425,7 +438,7 @@ AVCodec ff_png_encoder = {
.id = CODEC_ID_PNG,
.priv_data_size = sizeof(PNGEncContext),
.init = png_enc_init,
- .encode = encode_frame,
+ .encode2 = encode_frame,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGBA,
PIX_FMT_RGB48BE, PIX_FMT_RGBA64BE,
PIX_FMT_PAL8,