[FFmpeg-cvslog] avcodec/dpx: Report color_range from DPX header

Harry Mallon git at videolan.org
Thu Dec 17 14:05:29 EET 2020


ffmpeg | branch: master | Harry Mallon <harry.mallon at codex.online> | Mon Dec  7 10:32:12 2020 +0000| [8232e01e41488bc3f4504b3de241106a4cca7cb7] | committer: Paul B Mahol

avcodec/dpx: Report color_range from DPX header

Signed-off-by: Harry Mallon <harry.mallon at codex.online>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8232e01e41488bc3f4504b3de241106a4cca7cb7
---

 libavcodec/dpx.c         | 25 ++++++++++++++++++++++++-
 tests/ref/fate/dpx-probe |  2 +-
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/libavcodec/dpx.c b/libavcodec/dpx.c
index 51428459ef..577171258a 100644
--- a/libavcodec/dpx.c
+++ b/libavcodec/dpx.c
@@ -132,7 +132,7 @@ static int decode_frame(AVCodecContext *avctx,
 
     unsigned int offset;
     int magic_num, endian;
-    int x, y, stride, i, ret;
+    int x, y, stride, i, j, ret;
     int w, h, bits_per_color, descriptor, elements, packing;
     int encoding, need_align = 0;
 
@@ -268,6 +268,29 @@ static int decode_frame(AVCodecContext *avctx,
         }
     }
 
+    /* color range from television header */
+    if (offset >= 1964 + 4) {
+        buf = avpkt->data + 1952;
+        i = read32(&buf, endian);
+
+        buf = avpkt->data + 1964;
+        j = read32(&buf, endian);
+
+        if (i != 0xFFFFFFFF && j != 0xFFFFFFFF) {
+            float minCV, maxCV;
+            minCV = av_int2float(i);
+            maxCV = av_int2float(j);
+            if (bits_per_color >= 1 &&
+                minCV == 0.0f && maxCV == ((1<<bits_per_color) - 1)) {
+                avctx->color_range = AVCOL_RANGE_JPEG;
+            } else if (bits_per_color >= 8 &&
+                       minCV == (1  <<(bits_per_color - 4)) &&
+                       maxCV == (235<<(bits_per_color - 8))) {
+                avctx->color_range = AVCOL_RANGE_MPEG;
+            }
+        }
+    }
+
     switch (descriptor) {
     case 6:  // Y
         elements = 1;
diff --git a/tests/ref/fate/dpx-probe b/tests/ref/fate/dpx-probe
index 419cd06799..05b1cfcd14 100644
--- a/tests/ref/fate/dpx-probe
+++ b/tests/ref/fate/dpx-probe
@@ -1,6 +1,6 @@
 [FRAME]
 sample_aspect_ratio=1:1
-color_range=unknown
+color_range=pc
 color_space=unknown
 color_primaries=unknown
 color_transfer=unknown



More information about the ffmpeg-cvslog mailing list