diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index d812ffd348..d1aae4c70e 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -661,8 +661,13 @@ static int populate_avctx_color_fields(AVCodecContext *avctx, AVFrame *frame) av_log(avctx, AV_LOG_WARNING, "unrecognized cICP transfer\n"); else avctx->color_trc = frame->color_trc = s->cicp_trc; - if (s->cicp_range == 0) - av_log(avctx, AV_LOG_WARNING, "unsupported tv-range cICP chunk\n"); + if (s->cicp_range == 0) { + av_log(avctx, AV_LOG_WARNING, "tv-range cICP tag found. Colors may be wrong\n"); + avctx->color_range = frame->color_range = AVCOL_RANGE_MPEG; + } else if (s->cicp_range != 1) { + /* we already printed a warning when parsing the cICP chunk */ + avctx->color_range = frame->color_range = AVCOL_RANGE_UNSPECIFIED; + } } else if (s->iccp_data) { AVFrameSideData *sd = av_frame_new_side_data(frame, AV_FRAME_DATA_ICC_PROFILE, s->iccp_data_len); if (!sd) @@ -713,9 +718,10 @@ static int populate_avctx_color_fields(AVCodecContext *avctx, AVFrame *frame) avctx->color_trc = frame->color_trc = AVCOL_TRC_LINEAR; } - /* we only support pc-range RGB */ + /* PNG only supports RGB */ avctx->colorspace = frame->colorspace = AVCOL_SPC_RGB; - avctx->color_range = frame->color_range = AVCOL_RANGE_JPEG; + if (!s->have_cicp || s->cicp_range == 1) + avctx->color_range = frame->color_range = AVCOL_RANGE_JPEG; /* * tRNS sets alpha depth to full, so we ignore sBIT if set. @@ -1455,11 +1461,8 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s, if (bytestream2_get_byte(&gb_chunk) != 0) av_log(avctx, AV_LOG_WARNING, "nonzero cICP matrix\n"); s->cicp_range = bytestream2_get_byte(&gb_chunk); - if (s->cicp_range != 0 && s->cicp_range != 1) { - av_log(avctx, AV_LOG_ERROR, "invalid cICP range: %d\n", s->cicp_range); - ret = AVERROR_INVALIDDATA; - goto fail; - } + if (s->cicp_range != 0 && s->cicp_range != 1) + av_log(avctx, AV_LOG_WARNING, "invalid cICP range: %d\n", s->cicp_range); s->have_cicp = 1; break; case MKTAG('s', 'R', 'G', 'B'): @@ -1814,8 +1817,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->last_picture.f = av_frame_alloc(); s->picture.f = av_frame_alloc();