[PR] avcodec/dnxhd: extract component calculation for DNxHD decoding (PR #24270)
AJGranowski via ffmpeg-devel <[email protected]>
| Newsgroups | gmane.comp.video.ffmpeg.devel |
|---|---|
| Message-ID | <[email protected]> |
PR #24270 opened by AJGranowski URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24270 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24270.patch # Summary of changes This is an incremental change towards adding DCT block alpha decoding for the DNxHD codec. No behavioral changes in this PR. The DCT block alpha decoding algorithm is the same as the DCT decode function used to decode the Y channel. (https://pub.smpte.org/doc/st2019-1/20160518-pub/ 8.1.2) Exposing the component as a parameter in the DCT decode function *should* be a step in the right direction for adding eventual alpha decode support. Also made the `avpriv_request_sample` more verbose, since I'd imagine we're going to incrementally add alpha support starting with just DCT block alpha. Related tickets: https://trac.ffmpeg.org/ticket/3707 >From aa335745d34da01826fbde5f940e5f0a2283df41 Mon Sep 17 00:00:00 2001 From: AJ Granowski <[email protected]> Date: Tue, 25 Aug 2026 15:04:06 -0500 Subject: [PATCH] Extract component calculation for DNxHD decoding This is an incremental change towards adding DCT block alpha decoding support for the DNxHD codec. The DCT block alpha decoding algorithm is the same as the DCT decode function used to decode the Y channel. (https://pub.smpte.org/doc/st2019-1/20160518-pub/ 8.1.2) Exposing the component as a parameter in the DCT decode function *should* be a step in the right direction for adding eventual alpha decode support. Related tickets: https://trac.ffmpeg.org/ticket/3707 --- libavcodec/dnxhddec.c | 66 ++++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/libavcodec/dnxhddec.c b/libavcodec/dnxhddec.c index 7ec61f9ebd..abc11114d1 100644 --- a/libavcodec/dnxhddec.c +++ b/libavcodec/dnxhddec.c @@ -72,6 +72,7 @@ typedef struct DNXHDContext { int is_444; int alpha; int lla; + int pma; int mbaff; int act; int (*decode_dct_block)(const struct DNXHDContext *ctx, @@ -208,8 +209,19 @@ static int dnxhd_decode_header(DNXHDContext *ctx, AVFrame *frame, ctx->mbaff = (buf[0x6] >> 5) & 1; ctx->alpha = buf[0x7] & 1; ctx->lla = (buf[0x7] >> 1) & 1; - if (ctx->alpha) - avpriv_request_sample(ctx->avctx, "alpha"); + ctx->pma = (buf[0x7] >> 2) & 1; + av_log(ctx->avctx, AV_LOG_DEBUG, "ALP=%d, LLA=%d, PMA=%d\n", ctx->alpha, ctx->lla, ctx->pma); + + if (ctx->alpha) { + if (ctx->pma) + avpriv_request_sample(ctx->avctx, "pre-multiplied alpha (out-of-band encoding) decoding"); + + if (ctx->lla) { + avpriv_request_sample(ctx->avctx, "RLE block alpha decoding"); + } else { + avpriv_request_sample(ctx->avctx, "DCT block alpha decoding"); + } + } ctx->height = AV_RB16(buf + 0x18); ctx->width = AV_RB16(buf + 0x1a); @@ -352,16 +364,17 @@ static int dnxhd_decode_header(DNXHDContext *ctx, AVFrame *frame, return 0; } -static av_always_inline int dnxhd_decode_dct_block(const DNXHDContext *ctx, +static av_always_inline int dnxhd_decode_dct_block_component(const DNXHDContext *ctx, RowContext *row, int n, + int component, int index_bits, int level_bias, int level_shift, int dc_shift) { int i, j, index1, len, flags; - int level, component, sign; + int level, sign; const int *scale; const uint8_t *weight_matrix; const uint8_t *ac_info = ctx->cid_table->ac_info; @@ -372,25 +385,12 @@ static av_always_inline int dnxhd_decode_dct_block(const DNXHDContext *ctx, ctx->bdsp.clear_block(block); - if (!ctx->is_444) { - if (n & 2) { - component = 1 + (n & 1); - scale = row->chroma_scale; - weight_matrix = ctx->cid_table->chroma_weight; - } else { - component = 0; - scale = row->luma_scale; - weight_matrix = ctx->cid_table->luma_weight; - } + if (component) { + scale = row->chroma_scale; + weight_matrix = ctx->cid_table->chroma_weight; } else { - component = (n >> 1) % 3; - if (component) { - scale = row->chroma_scale; - weight_matrix = ctx->cid_table->chroma_weight; - } else { - scale = row->luma_scale; - weight_matrix = ctx->cid_table->luma_weight; - } + scale = row->luma_scale; + weight_matrix = ctx->cid_table->luma_weight; } UPDATE_CACHE(bs, &row->gb); @@ -458,6 +458,28 @@ error: return ret; } +static av_always_inline int dnxhd_decode_dct_block(const DNXHDContext *ctx, + RowContext *row, + int n, + int index_bits, + int level_bias, + int level_shift, + int dc_shift) +{ + int component; + if (!ctx->is_444) { + if (n & 2) { + component = 1 + (n & 1); + } else { + component = 0; + } + } else { + component = (n >> 1) % 3; + } + + return dnxhd_decode_dct_block_component(ctx, row, n, component, index_bits, level_bias, level_shift, dc_shift); +} + static int dnxhd_decode_dct_block_8(const DNXHDContext *ctx, RowContext *row, int n) { -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]