[FFmpeg-devel] [PATCH v2 2/3] pngdec: expose gAMA and cHRM chunks as side data

Rostislav Pehlivanov atomnuker at gmail.com
Mon Sep 25 22:28:08 EEST 2017


Signed-off-by: Rostislav Pehlivanov <atomnuker at gmail.com>
---
 libavcodec/pngdec.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 0d6612ccca..2d005f90fc 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"
@@ -1287,6 +1288,53 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s,
                 goto fail;
             break;
         }
+        case MKTAG('c', 'H', 'R', 'M'): {
+            AVMasteringDisplayMetadata *mdm = av_mastering_display_metadata_create_side_data(p);
+            if (!mdm) {
+                ret = AVERROR(ENOMEM);
+                goto fail;
+            }
+
+            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'): {
+            AVFrameSideData *sd = av_frame_new_side_data(p, AV_FRAME_DATA_GAMMA, sizeof(AVRational));
+            AVRational *gamma = (AVRational *)sd->data;
+            if (!sd) {
+                ret = AVERROR(ENOMEM);
+                goto fail;
+            }
+
+            gamma->num = bytestream2_get_be32(&s->gb);
+            gamma->den = 100000;
+            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");
-- 
2.14.1.821.g8fa685d3b7



More information about the ffmpeg-devel mailing list