diff options
author | Benoit Fouet <benoit.fouet@free.fr> | 2014-11-14 10:17:31 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2014-11-14 15:58:02 +0100 |
commit | 1523d1484d2e0cc59315df6713a391e5b0154ff7 (patch) | |
tree | 73b81b61f21a86703b2d3494b25aca5804302ddf /libavcodec/pngdec.c | |
parent | 98abb98cb1c7e83322d70b7e3a3f20a2479c6e9b (diff) | |
download | ffmpeg-1523d1484d2e0cc59315df6713a391e5b0154ff7.tar.gz |
avcodec/pngdec: create a function to decode IHDR chunk.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/pngdec.c')
-rw-r--r-- | libavcodec/pngdec.c | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index abb8029321..51956a6dfe 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -519,6 +519,33 @@ static int decode_text_chunk(PNGDecContext *s, uint32_t length, int compressed, return 0; } +static int decode_ihdr_chunk(AVCodecContext *avctx, PNGDecContext *s, + uint32_t length) +{ + if (length != 13) + return AVERROR_INVALIDDATA; + s->width = bytestream2_get_be32(&s->gb); + s->height = bytestream2_get_be32(&s->gb); + if (av_image_check_size(s->width, s->height, 0, avctx)) { + s->width = s->height = 0; + av_log(avctx, AV_LOG_ERROR, "Invalid image size\n"); + return AVERROR_INVALIDDATA; + } + s->bit_depth = bytestream2_get_byte(&s->gb); + s->color_type = bytestream2_get_byte(&s->gb); + s->compression_type = bytestream2_get_byte(&s->gb); + s->filter_type = bytestream2_get_byte(&s->gb); + s->interlace_type = bytestream2_get_byte(&s->gb); + bytestream2_skip(&s->gb, 4); /* crc */ + s->state |= PNG_IHDR; + if (avctx->debug & FF_DEBUG_PICT_INFO) + av_log(avctx, AV_LOG_DEBUG, "width=%d height=%d depth=%d color_type=%d " + "compression_type=%d filter_type=%d interlace_type=%d\n", + s->width, s->height, s->bit_depth, s->color_type, + s->compression_type, s->filter_type, s->interlace_type); + return 0; +} + static int decode_frame_png(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) @@ -580,27 +607,8 @@ static int decode_frame_png(AVCodecContext *avctx, ((tag >> 24) & 0xff), length); switch (tag) { case MKTAG('I', 'H', 'D', 'R'): - if (length != 13) - goto fail; - s->width = bytestream2_get_be32(&s->gb); - s->height = bytestream2_get_be32(&s->gb); - if (av_image_check_size(s->width, s->height, 0, avctx)) { - s->width = s->height = 0; - av_log(avctx, AV_LOG_ERROR, "Invalid image size\n"); + if (decode_ihdr_chunk(avctx, s, length) < 0) goto fail; - } - s->bit_depth = bytestream2_get_byte(&s->gb); - s->color_type = bytestream2_get_byte(&s->gb); - s->compression_type = bytestream2_get_byte(&s->gb); - s->filter_type = bytestream2_get_byte(&s->gb); - s->interlace_type = bytestream2_get_byte(&s->gb); - bytestream2_skip(&s->gb, 4); /* crc */ - s->state |= PNG_IHDR; - if (avctx->debug & FF_DEBUG_PICT_INFO) - av_log(avctx, AV_LOG_DEBUG, "width=%d height=%d depth=%d color_type=%d " - "compression_type=%d filter_type=%d interlace_type=%d\n", - s->width, s->height, s->bit_depth, s->color_type, - s->compression_type, s->filter_type, s->interlace_type); break; case MKTAG('p', 'H', 'Y', 's'): if (s->state & PNG_IDAT) { |