[FFmpeg-devel] [PATCH 2/2] pngdec: expose gAMA and cHRM chunks as AVMasteringDisplayMetadata
Rostislav Pehlivanov
atomnuker at gmail.com
Wed Sep 20 06:00:28 EEST 2017
Signed-off-by: Rostislav Pehlivanov <atomnuker at gmail.com>
---
libavcodec/pngdec.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 0d6612ccca..b7d9ded89c 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -25,6 +25,7 @@
#include "libavutil/bprint.h"
#include "libavutil/imgutils.h"
#include "libavutil/stereo3d.h"
+#include "libavutil/mastering_display_metadata.h"
#include "avcodec.h"
#include "bytestream.h"
@@ -1163,10 +1164,15 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s,
AVFrame *p, AVPacket *avpkt)
{
AVDictionary **metadatap = NULL;
+ AVMasteringDisplayMetadata mdm;
uint32_t tag, length;
int decode_next_dat = 0;
int ret;
+ mdm.has_primaries = 0;
+ mdm.has_luminance = 0;
+ mdm.has_gamma = 0;
+
for (;;) {
length = bytestream2_get_bytes_left(&s->gb);
if (length <= 0) {
@@ -1287,6 +1293,41 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s,
goto fail;
break;
}
+ case MKTAG('c', 'H', 'R', 'M'): {
+ mdm.white_point[0].num = bytestream2_get_be32(&s->gb);
+ mdm.white_point[0].den = 100000;
+ mdm.white_point[1].num = bytestream2_get_be32(&s->gb);
+ mdm.white_point[1].den = 100000;
+
+ /* Red primaries */
+ mdm.display_primaries[0][0].num = bytestream2_get_be32(&s->gb);
+ mdm.display_primaries[0][0].den = 100000;
+ mdm.display_primaries[0][1].num = bytestream2_get_be32(&s->gb);
+ mdm.display_primaries[0][1].den = 100000;
+
+ /* Green primaries */
+ mdm.display_primaries[1][0].num = bytestream2_get_be32(&s->gb);
+ mdm.display_primaries[1][0].den = 100000;
+ mdm.display_primaries[1][1].num = bytestream2_get_be32(&s->gb);
+ mdm.display_primaries[1][1].den = 100000;
+
+ /* Blue primaries */
+ mdm.display_primaries[2][0].num = bytestream2_get_be32(&s->gb);
+ mdm.display_primaries[2][0].den = 100000;
+ mdm.display_primaries[2][1].num = bytestream2_get_be32(&s->gb);
+ mdm.display_primaries[2][1].den = 100000;
+
+ mdm.has_primaries = 1;
+ bytestream2_skip(&s->gb, 4); /* crc */
+ break;
+ }
+ case MKTAG('g', 'A', 'M', 'A'): {
+ mdm.gamma.num = bytestream2_get_be32(&s->gb);
+ mdm.gamma.den = 100000;
+ mdm.has_gamma = 1;
+ bytestream2_skip(&s->gb, 4); /* crc */
+ break;
+ }
case MKTAG('I', 'E', 'N', 'D'):
if (!(s->pic_state & PNG_ALLIMAGE))
av_log(avctx, AV_LOG_ERROR, "IEND without all image\n");
@@ -1305,6 +1346,11 @@ skip_tag:
}
exit_loop:
+ if (mdm.has_gamma || mdm.has_primaries) {
+ AVMasteringDisplayMetadata *new_mdm = av_mastering_display_metadata_create_side_data(p);
+ memcpy(new_mdm, &mdm, sizeof(AVMasteringDisplayMetadata));
+ }
+
if (avctx->codec_id == AV_CODEC_ID_PNG &&
avctx->skip_frame == AVDISCARD_ALL) {
return 0;
--
2.14.1.821.g8fa685d3b7
More information about the ffmpeg-devel
mailing list