diff mbox series

[FFmpeg-devel,4/4] dnxhddec: partial alpha support

Message ID 20210130091906.312-5-christophe.gisquet@gmail.com
State New
Headers show
Series Better colorspace support in dnxhddec | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Christophe Gisquet Jan. 30, 2021, 9:19 a.m. UTC
From: Christophe Gisquet <c.gisquet@ateme.com>

This consists in just ignoring the alpha at the end of the bitstream
---
 libavcodec/dnxhddec.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/dnxhddec.c b/libavcodec/dnxhddec.c
index 11da1c286c..1de95996cf 100644
--- a/libavcodec/dnxhddec.c
+++ b/libavcodec/dnxhddec.c
@@ -202,7 +202,7 @@  static int dnxhd_decode_header(DNXHDContext *ctx, AVFrame *frame,
         ctx->cur_field = 0;
     }
     ctx->mbaff = (buf[0x6] >> 5) & 1;
-    ctx->alpha = buf[0x7] & 1;
+    ctx->alpha = buf[0x7] & 5;
     ctx->lla   = (buf[0x7] >> 1) & 1;
     if (ctx->alpha)
         avpriv_request_sample(ctx->avctx, "alpha");
@@ -249,10 +249,14 @@  static int dnxhd_decode_header(DNXHDContext *ctx, AVFrame *frame,
             return AVERROR_INVALIDDATA;
         } else if (bitdepth == 10) {
             ctx->decode_dct_block = dnxhd_decode_dct_block_10_444;
-            ctx->pix_fmt = ctx->act ? AV_PIX_FMT_GBRP10 : AV_PIX_FMT_YUV444P10;
+            ctx->pix_fmt = ctx->act
+                         ? (/*ctx->alpha ? AV_PIX_FMT_GBRAP10LE :*/ AV_PIX_FMT_GBRP10)
+                         : (/*ctx->alpha ? AV_PIX_FMT_YUVA444P10LE :*/ AV_PIX_FMT_YUV444P10);
         } else {
             ctx->decode_dct_block = dnxhd_decode_dct_block_12_444;
-            ctx->pix_fmt = ctx->act ? AV_PIX_FMT_GBRP12 : AV_PIX_FMT_YUV444P12;
+            ctx->pix_fmt = ctx->act
+                         ? (/*ctx->alpha ? AV_PIX_FMT_GBRAP12LE :*/ AV_PIX_FMT_GBRP12)
+                         : (/*ctx->alpha ? AV_PIX_FMT_YUVA444P12LE :*/ AV_PIX_FMT_YUV444P12);
         }
     } else if (bitdepth == 12) {
         ctx->decode_dct_block = dnxhd_decode_dct_block_12;
@@ -337,7 +341,7 @@  static int dnxhd_decode_header(DNXHDContext *ctx, AVFrame *frame,
                 i, 0x170 + (i << 2), ctx->mb_scan_index[i]);
         if (buf_size - ctx->data_offset < ctx->mb_scan_index[i]) {
             av_log(ctx->avctx, AV_LOG_ERROR,
-                   "invalid mb scan index (%"PRIu32" vs %u).\n",
+                   "invalid mb %i scan index (%"PRIu32" vs %u).\n", i,
                    ctx->mb_scan_index[i], buf_size - ctx->data_offset);
             return AVERROR_INVALIDDATA;
         }
@@ -642,6 +646,12 @@  static int dnxhd_decode_row(AVCodecContext *avctx, void *data,
         }
     }
 
+    /* alpha decoding goes there */
+    if (ctx->alpha) {
+       ff_dlog(ctx->avctx, "Row %d: %d left\n", rownb,
+               ((rownb < ctx->mb_height-1 ? ctx->mb_scan_index[rownb+1] : ctx->buf_size) - offset) * 8 - get_bits_count(&row->gb));
+    }
+
     return 0;
 }
 
@@ -735,11 +745,13 @@  decode_coding_unit:
         case -1:
         case 0:
             ctx->pix_fmt = ctx->bit_depth==10
-                         ? AV_PIX_FMT_GBRP10 : AV_PIX_FMT_GBRP12;
+                         ? (/*ctx->alpha ? AV_PIX_FMT_GBRAP10 :*/ AV_PIX_FMT_GBRP10)
+                         : (/*ctx->alpha ? AV_PIX_FMT_GBRAP12 :*/ AV_PIX_FMT_GBRP12);
             break;
         case 1:
             ctx->pix_fmt = ctx->bit_depth==10
-                         ? AV_PIX_FMT_YUV444P10 : AV_PIX_FMT_YUV444P12;
+                         ? (/*ctx->alpha ? AV_PIX_FMT_YUVA444P10 :*/ AV_PIX_FMT_YUV444P10)
+                         : (/*ctx->alpha ? AV_PIX_FMT_YUVA444P12 :*/ AV_PIX_FMT_YUV444P12);
             break;
         }
     }