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

Paul B Mahol onemda at gmail.com
Wed Dec 13 12:59:22 EET 2017


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

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 c6ea7c6296..a04b77fa43 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
@@ -254,7 +254,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
-- 
2.11.0



More information about the ffmpeg-devel mailing list