History

lavc/dxvenc: fix big-endian issues in dxv_compress_dxt1

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.

Emma Worley committed 1 year ago

Commit a4c1a5b1 parent 3be9b3f1 file · +9 −13Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/dxvenc.c+9−13
@@ -100,8 +100,7 @@ static int dxv_compress_dxt1(AVCodecContext *avctx) · 99 unmodified lines
100100 DXVEncContext *ctx = avctx->priv_data;
101101 PutByteContext *pbc = &ctx->pbc;
102102 void *value;
103− uint64_t combo;
104− uint32_t color, lut, idx, combo_idx, prev_pos, old_pos, state = 16, pos = 0, op = 0;
103+ uint32_t idx, combo_idx, prev_pos, old_pos, state = 16, pos = 0, op = 0;
105104
106105 ff_hashtable_clear(ctx->color_ht);
107106 ff_hashtable_clear(ctx->lut_ht);
@@ -117,8 +116,7 @@ static int dxv_compress_dxt1(AVCodecContext *avctx) · 9 unmodified lines
117116 pos++;
118117
119118 while (pos + 2 <= ctx->tex_size / 4) {
120− combo = AV_RL64(ctx->tex_data + pos * 4);
121− combo_idx = ff_hashtable_get(ctx->combo_ht, &combo, &prev_pos) ? pos - prev_pos : 0;
119+ combo_idx = ff_hashtable_get(ctx->combo_ht, ctx->tex_data + pos * 4, &prev_pos) ? pos - prev_pos : 0;
122120 idx = combo_idx;
123121 PUSH_OP(2);
124122 if (pos >= LOOKBACK_WORDS) {
@@ -126,36 +124,34 @@ static int dxv_compress_dxt1(AVCodecContext *avctx) · 1 unmodified line
126124 if (ff_hashtable_get(ctx->combo_ht, ctx->tex_data + old_pos * 4, &prev_pos) && prev_pos <= old_pos)
127125 ff_hashtable_delete(ctx->combo_ht, ctx->tex_data + old_pos * 4);
128126 }
129− ff_hashtable_set(ctx->combo_ht, &combo, &pos);
127+ ff_hashtable_set(ctx->combo_ht, ctx->tex_data + pos * 4, &pos);
130128
131− color = AV_RL32(ctx->tex_data + pos * 4);
132129 if (!combo_idx) {
133− idx = ff_hashtable_get(ctx->color_ht, &color, &prev_pos) ? pos - prev_pos : 0;
130+ idx = ff_hashtable_get(ctx->color_ht, ctx->tex_data + pos * 4, &prev_pos) ? pos - prev_pos : 0;
134131 PUSH_OP(2);
135132 if (!idx)
136− bytestream2_put_le32(pbc, color);
133+ bytestream2_put_le32(pbc, AV_RL32(ctx->tex_data + pos * 4));
137134 }
138135 if (pos >= LOOKBACK_WORDS) {
139136 old_pos = pos - LOOKBACK_WORDS;
140137 if (ff_hashtable_get(ctx->color_ht, ctx->tex_data + old_pos * 4, &prev_pos) && prev_pos <= old_pos)
141138 ff_hashtable_delete(ctx->color_ht, ctx->tex_data + old_pos * 4);
142139 }
143− ff_hashtable_set(ctx->color_ht, &color, &pos);
140+ ff_hashtable_set(ctx->color_ht, ctx->tex_data + pos * 4, &pos);
144141 pos++;
145142
146− lut = AV_RL32(ctx->tex_data + pos * 4);
147143 if (!combo_idx) {
148− idx = ff_hashtable_get(ctx->lut_ht, &lut, &prev_pos) ? pos - prev_pos : 0;
144+ idx = ff_hashtable_get(ctx->lut_ht, ctx->tex_data + pos * 4, &prev_pos) ? pos - prev_pos : 0;
149145 PUSH_OP(2);
150146 if (!idx)
151− bytestream2_put_le32(pbc, lut);
147+ bytestream2_put_le32(pbc, AV_RL32(ctx->tex_data + pos * 4));
152148 }
153149 if (pos >= LOOKBACK_WORDS) {
154150 old_pos = pos - LOOKBACK_WORDS;
155151 if (ff_hashtable_get(ctx->lut_ht, ctx->tex_data + old_pos * 4, &prev_pos) && prev_pos <= old_pos)
156152 ff_hashtable_delete(ctx->lut_ht, ctx->tex_data + old_pos * 4);
157153 }
158− ff_hashtable_set(ctx->lut_ht, &lut, &pos);
154+ ff_hashtable_set(ctx->lut_ht, ctx->tex_data + pos * 4, &pos);
159155 pos++;
160156 }
161157

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t