From a49108fd2923f9444af04727457d14300e96666f Mon Sep 17 00:00:00 2001 From: averne Date: Thu, 31 Jul 2025 16:42:35 +0200 Subject: [PATCH] avcodec/proresdec: Remove grayscale hack This was introduced in commit 9c43703, to support a codec "extension" in the prores_aw encoder. This removes the chroma fill loop, and instead performs the inverse transform on null coefficients, which achieves the same result and fixes an off-by-one in the chroma values produced. Updated test to reflect this change. --- libavcodec/proresdec.c | 30 +++++++++--------------------- tests/ref/fate/prores-gray | 4 ++-- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/libavcodec/proresdec.c b/libavcodec/proresdec.c index 5f917daca1..deaf84bda0 100644 --- a/libavcodec/proresdec.c +++ b/libavcodec/proresdec.c @@ -572,12 +572,15 @@ static int decode_slice_chroma(AVCodecContext *avctx, SliceContext *slice, for (i = 0; i < blocks_per_slice; i++) ctx->bdsp.clear_block(blocks+(i<<6)); - init_get_bits(&gb, buf, buf_size << 3); + /* Some encodes have empty chroma scans to simulate grayscale */ + if (buf_size) { + init_get_bits(&gb, buf, buf_size << 3); - if ((ret = decode_dc_coeffs(&gb, blocks, blocks_per_slice)) < 0) - return ret; - if ((ret = decode_ac_coeffs(avctx, &gb, blocks, blocks_per_slice)) < 0) - return ret; + if ((ret = decode_dc_coeffs(&gb, blocks, blocks_per_slice)) < 0) + return ret; + if ((ret = decode_ac_coeffs(avctx, &gb, blocks, blocks_per_slice)) < 0) + return ret; + } block = blocks; for (i = 0; i < slice->mb_count; i++) { @@ -638,7 +641,6 @@ static int decode_slice_thread(AVCodecContext *avctx, void *arg, int jobnr, int LOCAL_ALIGNED_16(int16_t, qmat_chroma_scaled,[64]); int mb_x_shift; int ret; - uint16_t val_no_chroma; slice->ret = -1; //av_log(avctx, AV_LOG_INFO, "slice %d mb width %d mb x %d y %d\n", @@ -702,7 +704,7 @@ static int decode_slice_thread(AVCodecContext *avctx, void *arg, int jobnr, int if (ret < 0) return ret; - if (!(avctx->flags & AV_CODEC_FLAG_GRAY) && (u_data_size + v_data_size) > 0) { + if (!(avctx->flags & AV_CODEC_FLAG_GRAY)) { ret = decode_slice_chroma(avctx, slice, (uint16_t*)dest_u, chroma_stride, buf + y_data_size, u_data_size, qmat_chroma_scaled, log2_chroma_blocks_per_mb); @@ -715,20 +717,6 @@ static int decode_slice_thread(AVCodecContext *avctx, void *arg, int jobnr, int if (ret < 0) return ret; } - else { - size_t mb_max_x = slice->mb_count << (mb_x_shift - 1); - size_t i, j; - if (avctx->bits_per_raw_sample == 10) { - val_no_chroma = 511; - } else { /* 12b */ - val_no_chroma = 511 * 4; - } - for (i = 0; i < 16; ++i) - for (j = 0; j < mb_max_x; ++j) { - *(uint16_t*)(dest_u + (i * chroma_stride) + (j << 1)) = val_no_chroma; - *(uint16_t*)(dest_v + (i * chroma_stride) + (j << 1)) = val_no_chroma; - } - } /* decode alpha plane if available */ if (ctx->alpha_info && pic->data[3] && a_data_size) { diff --git a/tests/ref/fate/prores-gray b/tests/ref/fate/prores-gray index ae7becc47a..387fecf254 100644 --- a/tests/ref/fate/prores-gray +++ b/tests/ref/fate/prores-gray @@ -8,8 +8,8 @@ #codec_id 1: pcm_s16le #sample_rate 1: 48000 #channel_layout_name 1: stereo -0, 0, 0, 1, 1658880, 0x43d9c9e2 +0, 0, 0, 1, 1658880, 0x365613b9 1, 0, 0, 1024, 4096, 0x543c9a17 1, 1024, 1024, 1024, 4096, 0x9aedadd1 -0, 1, 1, 1, 1658880, 0xa2a72f9b +0, 1, 1, 1, 1658880, 0x95247963 1, 2048, 2048, 1024, 4096, 0xa0c9cd55