diff mbox series

[FFmpeg-devel,4/6] avcodec/dpx: Report color_range from DPX header

Message ID 20201207103214.75790-4-harry.mallon@codex.online
State Superseded
Headers show
Series [FFmpeg-devel,1/6] fate: Add dpx-probe test | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Harry Mallon Dec. 7, 2020, 10:32 a.m. UTC
Signed-off-by: Harry Mallon <harry.mallon@codex.online>
---
 libavcodec/dpx.c         | 25 ++++++++++++++++++++++++-
 tests/ref/fate/dpx-probe |  4 ++--
 2 files changed, 26 insertions(+), 3 deletions(-)
diff mbox series

Patch

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 9365bce644..a45990e333 100644
--- a/tests/ref/fate/dpx-probe
+++ b/tests/ref/fate/dpx-probe
@@ -22,7 +22,7 @@  display_picture_number=0
 interlaced_frame=0
 top_field_first=0
 repeat_pict=0
-color_range=unknown
+color_range=pc
 color_space=unknown
 color_primaries=unknown
 color_transfer=unknown
@@ -55,7 +55,7 @@  sample_aspect_ratio=1:1
 display_aspect_ratio=107:60
 pix_fmt=gbrp10le
 level=-99
-color_range=unknown
+color_range=pc
 color_space=unknown
 color_transfer=unknown
 color_primaries=unknown