aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Fouet <benoit.fouet@free.fr>2014-11-14 10:17:32 +0100
committerMichael Niedermayer <michaelni@gmx.at>2014-11-14 15:58:35 +0100
commit3f1eaf590ca29174c225b1cef69f8b0c5418ad94 (patch)
treec7a0775283e5445bd7f4437bd82f1269e25bdb35
parent1523d1484d2e0cc59315df6713a391e5b0154ff7 (diff)
downloadffmpeg-3f1eaf590ca29174c225b1cef69f8b0c5418ad94.tar.gz
avcodec/pngdec: create a function to decode pHYs chunk.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavcodec/pngdec.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 51956a6dfe..99a3a72389 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -543,6 +543,23 @@ static int decode_ihdr_chunk(AVCodecContext *avctx, PNGDecContext *s,
"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_phys_chunk(AVCodecContext *avctx, PNGDecContext *s)
+{
+ if (s->state & PNG_IDAT) {
+ av_log(avctx, AV_LOG_ERROR, "pHYs after IDAT\n");
+ return AVERROR_INVALIDDATA;
+ }
+ avctx->sample_aspect_ratio.num = bytestream2_get_be32(&s->gb);
+ avctx->sample_aspect_ratio.den = bytestream2_get_be32(&s->gb);
+ if (avctx->sample_aspect_ratio.num < 0 || avctx->sample_aspect_ratio.den < 0)
+ avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
+ bytestream2_skip(&s->gb, 1); /* unit specifier */
+ bytestream2_skip(&s->gb, 4); /* crc */
+
return 0;
}
@@ -611,16 +628,8 @@ static int decode_frame_png(AVCodecContext *avctx,
goto fail;
break;
case MKTAG('p', 'H', 'Y', 's'):
- if (s->state & PNG_IDAT) {
- av_log(avctx, AV_LOG_ERROR, "pHYs after IDAT\n");
+ if (decode_phys_chunk(avctx, s) < 0)
goto fail;
- }
- avctx->sample_aspect_ratio.num = bytestream2_get_be32(&s->gb);
- avctx->sample_aspect_ratio.den = bytestream2_get_be32(&s->gb);
- if (avctx->sample_aspect_ratio.num < 0 || avctx->sample_aspect_ratio.den < 0)
- avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
- bytestream2_skip(&s->gb, 1); /* unit specifier */
- bytestream2_skip(&s->gb, 4); /* crc */
break;
case MKTAG('I', 'D', 'A', 'T'):
if (!(s->state & PNG_IHDR)) {