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.
Showing the changes to libavcodec (1 of 1 file). Show all
Unified · Split
| @@ -100,8 +100,7 @@ static int dxv_compress_dxt1(AVCodecContext *avctx) · 99 unmodified lines | |||
| 100 | DXVEncContext *ctx = avctx->priv_data; | 100 | DXVEncContext *ctx = avctx->priv_data; |
| 101 | PutByteContext *pbc = &ctx->pbc; | 101 | PutByteContext *pbc = &ctx->pbc; |
| 102 | void *value; | 102 | void *value; |
| 103 | uint64_t combo; | 103 | uint32_t idx, combo_idx, prev_pos, old_pos, state = 16, pos = 0, op = 0; |
| 104 | uint32_t color, lut, idx, combo_idx, prev_pos, old_pos, state = 16, pos = 0, op = 0; | ||
| 105 | 104 | ||
| 106 | ff_hashtable_clear(ctx->color_ht); | 105 | ff_hashtable_clear(ctx->color_ht); |
| 107 | ff_hashtable_clear(ctx->lut_ht); | 106 | ff_hashtable_clear(ctx->lut_ht); |
| @@ -117,8 +116,7 @@ static int dxv_compress_dxt1(AVCodecContext *avctx) · 9 unmodified lines | |||
| 117 | pos++; | 116 | pos++; |
| 118 | 117 | ||
| 119 | while (pos + 2 <= ctx->tex_size / 4) { | 118 | while (pos + 2 <= ctx->tex_size / 4) { |
| 120 | combo = AV_RL64(ctx->tex_data + pos * 4); | 119 | combo_idx = ff_hashtable_get(ctx->combo_ht, ctx->tex_data + pos * 4, &prev_pos) ? pos - prev_pos : 0; |
| 121 | combo_idx = ff_hashtable_get(ctx->combo_ht, &combo, &prev_pos) ? pos - prev_pos : 0; | ||
| 122 | idx = combo_idx; | 120 | idx = combo_idx; |
| 123 | PUSH_OP(2); | 121 | PUSH_OP(2); |
| 124 | if (pos >= LOOKBACK_WORDS) { | 122 | if (pos >= LOOKBACK_WORDS) { |
| @@ -126,36 +124,34 @@ static int dxv_compress_dxt1(AVCodecContext *avctx) · 1 unmodified line | |||
| 126 | if (ff_hashtable_get(ctx->combo_ht, ctx->tex_data + old_pos * 4, &prev_pos) && prev_pos <= old_pos) | 124 | if (ff_hashtable_get(ctx->combo_ht, ctx->tex_data + old_pos * 4, &prev_pos) && prev_pos <= old_pos) |
| 127 | ff_hashtable_delete(ctx->combo_ht, ctx->tex_data + old_pos * 4); | 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 | if (!combo_idx) { | 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 | PUSH_OP(2); | 131 | PUSH_OP(2); |
| 135 | if (!idx) | 132 | if (!idx) |
| 136 | bytestream2_put_le32(pbc, color); | 133 | bytestream2_put_le32(pbc, AV_RL32(ctx->tex_data + pos * 4)); |
| 137 | } | 134 | } |
| 138 | if (pos >= LOOKBACK_WORDS) { | 135 | if (pos >= LOOKBACK_WORDS) { |
| 139 | old_pos = pos - LOOKBACK_WORDS; | 136 | old_pos = pos - LOOKBACK_WORDS; |
| 140 | if (ff_hashtable_get(ctx->color_ht, ctx->tex_data + old_pos * 4, &prev_pos) && prev_pos <= old_pos) | 137 | if (ff_hashtable_get(ctx->color_ht, ctx->tex_data + old_pos * 4, &prev_pos) && prev_pos <= old_pos) |
| 141 | ff_hashtable_delete(ctx->color_ht, ctx->tex_data + old_pos * 4); | 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 | pos++; | 141 | pos++; |
| 145 | 142 | ||
| 146 | lut = AV_RL32(ctx->tex_data + pos * 4); | ||
| 147 | if (!combo_idx) { | 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 | PUSH_OP(2); | 145 | PUSH_OP(2); |
| 150 | if (!idx) | 146 | if (!idx) |
| 151 | bytestream2_put_le32(pbc, lut); | 147 | bytestream2_put_le32(pbc, AV_RL32(ctx->tex_data + pos * 4)); |
| 152 | } | 148 | } |
| 153 | if (pos >= LOOKBACK_WORDS) { | 149 | if (pos >= LOOKBACK_WORDS) { |
| 154 | old_pos = pos - LOOKBACK_WORDS; | 150 | old_pos = pos - LOOKBACK_WORDS; |
| 155 | if (ff_hashtable_get(ctx->lut_ht, ctx->tex_data + old_pos * 4, &prev_pos) && prev_pos <= old_pos) | 151 | if (ff_hashtable_get(ctx->lut_ht, ctx->tex_data + old_pos * 4, &prev_pos) && prev_pos <= old_pos) |
| 156 | ff_hashtable_delete(ctx->lut_ht, ctx->tex_data + old_pos * 4); | 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 | pos++; | 155 | pos++; |
| 160 | } | 156 | } |
| 161 | 157 | ||