[FFmpeg-devel,06/24] avcodec/pngdec: set full color range only for gray formats

Submitted by Paul B Mahol on May 1, 2018, 7:39 p.m.

Details

Message ID 20180501194013.9552-6-onemda@gmail.com
State New
Headers show

Commit Message

Paul B Mahol May 1, 2018, 7:39 p.m.
Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavcodec/pngdec.c                | 8 ++++++--
 tests/ref/fate/api-png-codec-param | 4 ++--
 2 files changed, 8 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index f93f200bb1..dbf986de50 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -641,9 +641,11 @@  static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s,
         } else if ((s->bit_depth == 2 || s->bit_depth == 4 || s->bit_depth == 8) &&
                 s->color_type == PNG_COLOR_TYPE_GRAY) {
             avctx->pix_fmt = AV_PIX_FMT_GRAY8;
+            avctx->color_range = AVCOL_RANGE_JPEG;
         } else if (s->bit_depth == 16 &&
                 s->color_type == PNG_COLOR_TYPE_GRAY) {
             avctx->pix_fmt = AV_PIX_FMT_GRAY16BE;
+            avctx->color_range = AVCOL_RANGE_JPEG;
         } else if (s->bit_depth == 16 &&
                 s->color_type == PNG_COLOR_TYPE_RGB) {
             avctx->pix_fmt = AV_PIX_FMT_RGB48BE;
@@ -658,9 +660,11 @@  static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s,
         } else if (s->bit_depth == 8 &&
                 s->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
             avctx->pix_fmt = AV_PIX_FMT_YA8;
+            avctx->color_range = AVCOL_RANGE_JPEG;
         } else if (s->bit_depth == 16 &&
                 s->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
             avctx->pix_fmt = AV_PIX_FMT_YA16BE;
+            avctx->color_range = AVCOL_RANGE_JPEG;
         } else {
             avpriv_report_missing_feature(avctx,
                                           "Bit depth %d color type %d",
@@ -680,10 +684,12 @@  static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s,
 
             case AV_PIX_FMT_GRAY8:
                 avctx->pix_fmt = AV_PIX_FMT_YA8;
+                avctx->color_range = AVCOL_RANGE_JPEG;
                 break;
 
             case AV_PIX_FMT_GRAY16BE:
                 avctx->pix_fmt = AV_PIX_FMT_YA16BE;
+                avctx->color_range = AVCOL_RANGE_JPEG;
                 break;
 
             default:
@@ -1575,8 +1581,6 @@  static av_cold int png_dec_init(AVCodecContext *avctx)
 {
     PNGDecContext *s = avctx->priv_data;
 
-    avctx->color_range = AVCOL_RANGE_JPEG;
-
     s->avctx = avctx;
     s->previous_picture.f = av_frame_alloc();
     s->last_picture.f = av_frame_alloc();
diff --git a/tests/ref/fate/api-png-codec-param b/tests/ref/fate/api-png-codec-param
index f04ffa757d..a8c991270f 100644
--- a/tests/ref/fate/api-png-codec-param
+++ b/tests/ref/fate/api-png-codec-param
@@ -115,7 +115,7 @@  stream=0, decode=0
     color_primaries=2
     color_trc=2
     colorspace=2
-    color_range=2
+    color_range=0
     chroma_sample_location=0
     log_level_offset=0
     slices=0
@@ -255,7 +255,7 @@  stream=0, decode=1
     color_primaries=2
     color_trc=2
     colorspace=2
-    color_range=2
+    color_range=0
     chroma_sample_location=0
     log_level_offset=0
     slices=0