From c220fe008c5a3f7c652dbd03ce2a58e392e59e19 Mon Sep 17 00:00:00 2001 From: James Almer Date: Wed, 26 Jul 2017 01:28:35 -0300 Subject: avcodec/webp: add support for ICCP chunks Export the raw data as ICC Profile frame side data. Reviwed-by: Rostislav Pehlivanov Signed-off-by: James Almer --- libavcodec/webp.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/webp.c b/libavcodec/webp.c index a0d4d1812d..efa864a6f1 100644 --- a/libavcodec/webp.c +++ b/libavcodec/webp.c @@ -33,10 +33,10 @@ * * @author James Almer * Exif metadata + * ICC profile * * Unimplemented: * - Animation - * - ICC profile * - XMP metadata */ @@ -197,6 +197,7 @@ typedef struct WebPContext { uint8_t *alpha_data; /* alpha chunk data */ int alpha_data_size; /* alpha chunk data size */ int has_exif; /* set after an EXIF chunk has been processed */ + int has_iccp; /* set after an ICCP chunk has been processed */ int width; /* image width */ int height; /* image height */ int lossless; /* indicates lossless or lossy */ @@ -1381,6 +1382,7 @@ static int webp_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, *got_frame = 0; s->has_alpha = 0; s->has_exif = 0; + s->has_iccp = 0; bytestream2_init(&gb, avpkt->data, avpkt->size); if (bytestream2_get_bytes_left(&gb) < 12) @@ -1514,7 +1516,27 @@ exif_end: bytestream2_skip(&gb, chunk_size); break; } - case MKTAG('I', 'C', 'C', 'P'): + case MKTAG('I', 'C', 'C', 'P'): { + AVFrameSideData *sd; + + if (s->has_iccp) { + av_log(avctx, AV_LOG_VERBOSE, "Ignoring extra ICCP chunk\n"); + bytestream2_skip(&gb, chunk_size); + break; + } + if (!(vp8x_flags & VP8X_FLAG_ICC)) + av_log(avctx, AV_LOG_WARNING, + "ICCP chunk present, but ICC Profile bit not set in the " + "VP8X header\n"); + + s->has_iccp = 1; + sd = av_frame_new_side_data(p, AV_FRAME_DATA_ICC_PROFILE, chunk_size); + if (!sd) + return AVERROR(ENOMEM); + + bytestream2_get_buffer(&gb, sd->data, chunk_size); + break; + } case MKTAG('A', 'N', 'I', 'M'): case MKTAG('A', 'N', 'M', 'F'): case MKTAG('X', 'M', 'P', ' '): -- cgit v1.2.3