This change decouples the frame dimensions from avctx, which is useful
for DXV decoding, and fixes incorrect behavior in the existing
implementation.
Tested with `make fate THREADS=7` and
`make fate THREADS=7 THREAD_TYPE=slice`.
Signed-off-by: Connor Worley
---
libavcodec/dds.c | 2 ++
libavcodec/dxv.c | 19 ++-
libavcodec/dxvenc.c | 2 ++
libavcodec/hapdec.c | 2 ++
libavcodec/hapenc.c | 2 ++
libavcodec/texturedsp.h | 1 +
libavcodec/texturedsp_template.c | 4 ++--
libavcodec/vbndec.c | 2 ++
libavcodec/vbnenc.c | 2 ++
9 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/libavcodec/dds.c b/libavcodec/dds.c
index 67e2325a2a..89cf225f25 100644
--- a/libavcodec/dds.c
+++ b/libavcodec/dds.c
@@ -636,6 +636,8 @@ static int dds_decode(AVCodecContext *avctx, AVFrame *frame,
ctx->dec.tex_data.in = gbc->buffer;
ctx->dec.frame_data.out = frame->data[0];
ctx->dec.stride = frame->linesize[0];
+ctx->dec.width = avctx->coded_width;
+ctx->dec.height = avctx->coded_height;
ff_texturedsp_exec_decompress_threads(avctx, &ctx->dec);
} else if (!ctx->paletted && ctx->bpp == 4 && avctx->pix_fmt ==
AV_PIX_FMT_PAL8) {
uint8_t *dst = frame->data[0];
diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c
index 2eca14c129..b5553a0c86 100644
--- a/libavcodec/dxv.c
+++ b/libavcodec/dxv.c
@@ -843,7 +843,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame,
{
DXVContext *ctx = avctx->priv_data;
GetByteContext *gbc = &ctx->gbc;
-AVCodecContext cavctx = *avctx;
TextureDSPThreadContext texdsp_ctx, ctexdsp_ctx;
int (*decompress_tex)(AVCodecContext *avctx);
const char *msgcomp, *msgtext;
@@ -854,9 +853,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame,
bytestream2_init(gbc, avpkt->data, avpkt->size);
-cavctx.coded_height = avctx->coded_height / 2;
-cavctx.coded_width = avctx->coded_width / 2;
-
avctx->pix_fmt = AV_PIX_FMT_RGBA;
avctx->colorspace = AVCOL_SPC_RGB;
@@ -943,7 +939,8 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame,
texdsp_ctx.slice_count = av_clip(avctx->thread_count, 1,
avctx->coded_height / TEXTURE_BLOCK_H);
ctexdsp_ctx.slice_count = av_clip(avctx->thread_count, 1,
- cavctx.coded_height / TEXTURE_BLOCK_H);
+ avctx->coded_height / 2 /
TEXTURE_BLOCK_H);
+
/* New header is 12 bytes long. */
if (!old_type) {
version_major = bytestream2_get_byte(gbc) - 1;
@@ -979,8 +976,8 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame,
if (avctx->pix_fmt != AV_PIX_FMT_RGBA) {
int i;
-ctx->ctex_size = cavctx.coded_width / ctexdsp_ctx.raw_ratio *
- cavctx.coded_height / TEXTURE_BLOCK_H *
+ctx->ctex_size = avctx->coded_width / 2 / ctexdsp_ctx.raw_ratio *
+ avctx->coded_height / 2 / TEXTURE_BLOCK_H *
ctexdsp_ctx.tex_ratio;
ctx->op_size[0] = avctx->coded_width * avctx->coded_height / 16;
@@ -1007,6 +1004,10 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame
*frame,
if (ret < 0)
return ret;
+texdsp_ctx.width = avctx->coded_width;
+texdsp_ctx.height = avctx->coded_height;
+ctexdsp_ctx.width = avctx->coded_width / 2;
+ctexdsp_ctx.height = avctx->coded_height / 2;
switch (tag) {
case DXV_FMT_YG10:
/* BC5 texture with alpha in the second half of each block */
@@ -1022,13 +1023,13 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame
*frame,
ctexdsp_ctx.tex_data.in= ctx->ctex_data;
ctexdsp_ctx.frame_data.out = frame->data[2];
ctexdsp_ctx.stride = frame->linesize[2];
-ret = ff_texturedsp_exec_decompress_threads(&cavctx, &ctexdsp_ctx);
+ret = ff_texturedsp_exec_decompress_threads(avctx, &ctexdsp_ctx);
if (ret < 0)
return ret;
ctexdsp_ctx.tex_data.in= ctx->ctex_data + ctexdsp_ctx.tex_ratio /
2;
ctexdsp_ctx.frame_data.out = frame->data[1];
ctexdsp_ctx.stride = frame->linesize[1];
-ret = ff_texturedsp_exec_decompress_threads(&cavctx, &ctexdsp_ctx);
+ret = ff_texturedsp_exec_decompress_threads(avctx, &ctexdsp_ctx);
if (ret < 0)
return ret;
/* fallthrough */
diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
index bb2c2f8526..85cbca2be8 100644
--- a/libavcodec/dxvenc.c
+++ b/libavcodec/dxvenc.c
@@ -233,6 +233,8 @@ static int dxv_encode(AVCodecContext *avctx, AVPacket *pkt,
ctx->enc.tex_data.out = ctx->tex_data;
ctx->enc.frame_data.in = frame->data[0];
ctx->enc.stride = frame->linesize[0];
+ctx->enc.width = avctx->width;
+