Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Emma Worley <emma@emma.gg>
To: ffmpeg-devel@ffmpeg.org
Cc: Emma Worley <emma@emma.gg>
Subject: [FFmpeg-devel] [PATCH] lavc/dxvenc: fix big-endian issues in dxv_compress_dxt1
Date: Tue,  3 Jun 2025 22:38:21 -0700
Message-ID: <20250604053821.33129-1-emma@emma.gg> (raw)

We were using a mix of pointers to local variables read via AV_RL32/64 and
pointers directly to the texture buffer as keys to interact with the lookback
hashtables. On big-endian systems, these produced different values. This change
makes all hashtable interactions use direct pointers to the texture buffer and
only invokves AV_RL32 in the event of a lookback hashtable miss.

Signed-off-by: Emma Worley <emma@emma.gg>
---
 libavcodec/dxvenc.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
index ee6a0a5b36..f5cef4f2e1 100644
--- a/libavcodec/dxvenc.c
+++ b/libavcodec/dxvenc.c
@@ -100,8 +100,7 @@ static int dxv_compress_dxt1(AVCodecContext *avctx)
     DXVEncContext *ctx = avctx->priv_data;
     PutByteContext *pbc = &ctx->pbc;
     void *value;
-    uint64_t combo;
-    uint32_t color, lut, idx, combo_idx, prev_pos, old_pos, state = 16, pos = 0, op = 0;
+    uint32_t idx, combo_idx, prev_pos, old_pos, state = 16, pos = 0, op = 0;
 
     ff_hashtable_clear(ctx->color_ht);
     ff_hashtable_clear(ctx->lut_ht);
@@ -117,8 +116,7 @@ static int dxv_compress_dxt1(AVCodecContext *avctx)
     pos++;
 
     while (pos + 2 <= ctx->tex_size / 4) {
-        combo = AV_RL64(ctx->tex_data + pos * 4);
-        combo_idx = ff_hashtable_get(ctx->combo_ht, &combo, &prev_pos) ? pos - prev_pos : 0;
+        combo_idx = ff_hashtable_get(ctx->combo_ht, ctx->tex_data + pos * 4, &prev_pos) ? pos - prev_pos : 0;
         idx = combo_idx;
         PUSH_OP(2);
         if (pos >= LOOKBACK_WORDS) {
@@ -126,36 +124,34 @@ static int dxv_compress_dxt1(AVCodecContext *avctx)
             if (ff_hashtable_get(ctx->combo_ht, ctx->tex_data + old_pos * 4, &prev_pos) && prev_pos <= old_pos)
                 ff_hashtable_delete(ctx->combo_ht, ctx->tex_data + old_pos * 4);
         }
-        ff_hashtable_set(ctx->combo_ht, &combo, &pos);
+        ff_hashtable_set(ctx->combo_ht, ctx->tex_data + pos * 4, &pos);
 
-        color = AV_RL32(ctx->tex_data + pos * 4);
         if (!combo_idx) {
-            idx = ff_hashtable_get(ctx->color_ht, &color, &prev_pos) ? pos - prev_pos : 0;
+            idx = ff_hashtable_get(ctx->color_ht, ctx->tex_data + pos * 4, &prev_pos) ? pos - prev_pos : 0;
             PUSH_OP(2);
             if (!idx)
-                bytestream2_put_le32(pbc, color);
+                bytestream2_put_le32(pbc, AV_RL32(ctx->tex_data + pos * 4));
         }
         if (pos >= LOOKBACK_WORDS) {
             old_pos = pos - LOOKBACK_WORDS;
             if (ff_hashtable_get(ctx->color_ht, ctx->tex_data + old_pos * 4, &prev_pos) && prev_pos <= old_pos)
                 ff_hashtable_delete(ctx->color_ht, ctx->tex_data + old_pos * 4);
         }
-        ff_hashtable_set(ctx->color_ht, &color, &pos);
+        ff_hashtable_set(ctx->color_ht, ctx->tex_data + pos * 4, &pos);
         pos++;
 
-        lut = AV_RL32(ctx->tex_data + pos * 4);
         if (!combo_idx) {
-            idx = ff_hashtable_get(ctx->lut_ht, &lut, &prev_pos) ? pos - prev_pos : 0;
+            idx = ff_hashtable_get(ctx->lut_ht, ctx->tex_data + pos * 4, &prev_pos) ? pos - prev_pos : 0;
             PUSH_OP(2);
             if (!idx)
-                bytestream2_put_le32(pbc, lut);
+                bytestream2_put_le32(pbc, AV_RL32(ctx->tex_data + pos * 4));
         }
         if (pos >= LOOKBACK_WORDS) {
             old_pos = pos - LOOKBACK_WORDS;
             if (ff_hashtable_get(ctx->lut_ht, ctx->tex_data + old_pos * 4, &prev_pos) && prev_pos <= old_pos)
                 ff_hashtable_delete(ctx->lut_ht, ctx->tex_data + old_pos * 4);
         }
-        ff_hashtable_set(ctx->lut_ht, &lut, &pos);
+        ff_hashtable_set(ctx->lut_ht, ctx->tex_data + pos * 4, &pos);
         pos++;
     }
 
-- 
2.48.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

                 reply	other threads:[~2025-06-04  5:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250604053821.33129-1-emma@emma.gg \
    --to=emma@emma.gg \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git