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.
Unified · Split
| @@ -100,8 +100,7 @@ static int dxv_compress_dxt1(AVCodecContext *avctx) · 99 unmodified lines | ||
| 100 | 100 | DXVEncContext *ctx = avctx->priv_data; |
| 101 | 101 | PutByteContext *pbc = &ctx->pbc; |
| 102 | 102 | 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; | |
| 105 | 104 | |
| 106 | 105 | ff_hashtable_clear(ctx->color_ht); |
| 107 | 106 | ff_hashtable_clear(ctx->lut_ht); |
| @@ -117,8 +116,7 @@ static int dxv_compress_dxt1(AVCodecContext *avctx) · 9 unmodified lines | ||
| 117 | 116 | pos++; |
| 118 | 117 | |
| 119 | 118 | 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; | |
| 122 | 120 | idx = combo_idx; |
| 123 | 121 | PUSH_OP(2); |
| 124 | 122 | if (pos >= LOOKBACK_WORDS) { |
| @@ -126,36 +124,34 @@ static int dxv_compress_dxt1(AVCodecContext *avctx) · 1 unmodified line | ||
| 126 | 124 | if (ff_hashtable_get(ctx->combo_ht, ctx->tex_data + old_pos * 4, &prev_pos) && prev_pos <= old_pos) |
| 127 | 125 | ff_hashtable_delete(ctx->combo_ht, ctx->tex_data + old_pos * 4); |
| 128 | 126 | } |
| 129 | − ff_hashtable_set(ctx->combo_ht, &combo, &pos); | |
| 127 | + ff_hashtable_set(ctx->combo_ht, ctx->tex_data + pos * 4, &pos); | |
| 130 | 128 | |
| 131 | − color = AV_RL32(ctx->tex_data + pos * 4); | |
| 132 | 129 | 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; | |
| 134 | 131 | PUSH_OP(2); |
| 135 | 132 | if (!idx) |
| 136 | − bytestream2_put_le32(pbc, color); | |
| 133 | + bytestream2_put_le32(pbc, AV_RL32(ctx->tex_data + pos * 4)); | |
| 137 | 134 | } |
| 138 | 135 | if (pos >= LOOKBACK_WORDS) { |
| 139 | 136 | old_pos = pos - LOOKBACK_WORDS; |
| 140 | 137 | if (ff_hashtable_get(ctx->color_ht, ctx->tex_data + old_pos * 4, &prev_pos) && prev_pos <= old_pos) |
| 141 | 138 | ff_hashtable_delete(ctx->color_ht, ctx->tex_data + old_pos * 4); |
| 142 | 139 | } |
| 143 | − ff_hashtable_set(ctx->color_ht, &color, &pos); | |
| 140 | + ff_hashtable_set(ctx->color_ht, ctx->tex_data + pos * 4, &pos); | |
| 144 | 141 | pos++; |
| 145 | 142 | |
| 146 | − lut = AV_RL32(ctx->tex_data + pos * 4); | |
| 147 | 143 | 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; | |
| 149 | 145 | PUSH_OP(2); |
| 150 | 146 | if (!idx) |
| 151 | − bytestream2_put_le32(pbc, lut); | |
| 147 | + bytestream2_put_le32(pbc, AV_RL32(ctx->tex_data + pos * 4)); | |
| 152 | 148 | } |
| 153 | 149 | if (pos >= LOOKBACK_WORDS) { |
| 154 | 150 | old_pos = pos - LOOKBACK_WORDS; |
| 155 | 151 | if (ff_hashtable_get(ctx->lut_ht, ctx->tex_data + old_pos * 4, &prev_pos) && prev_pos <= old_pos) |
| 156 | 152 | ff_hashtable_delete(ctx->lut_ht, ctx->tex_data + old_pos * 4); |
| 157 | 153 | } |
| 158 | − ff_hashtable_set(ctx->lut_ht, &lut, &pos); | |
| 154 | + ff_hashtable_set(ctx->lut_ht, ctx->tex_data + pos * 4, &pos); | |
| 159 | 155 | pos++; |
| 160 | 156 | } |
| 161 | 157 | |