From 9362bde2ccec788725ab2fe94959661b12d3cfd9 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 17 Feb 2016 21:16:52 +0100 Subject: VIDEO: In indeo3 codec, use unaligned read functions where necessary This fixes bug #7039. --- image/codecs/indeo3.cpp | 90 ++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 45 deletions(-) (limited to 'image') diff --git a/image/codecs/indeo3.cpp b/image/codecs/indeo3.cpp index af9120ca93..d414de31d1 100644 --- a/image/codecs/indeo3.cpp +++ b/image/codecs/indeo3.cpp @@ -479,7 +479,7 @@ void Indeo3Decoder::decodeChunk(byte *cur, byte *ref, int width, int height, if (cmd == 0 || ref_vectors != NULL) { for (lp1 = 0; lp1 < blks_width; lp1++) { for (i = 0, j = 0; i < blks_height; i++, j += width_tbl[1]) - ((uint32 *)cur_frm_pos)[j] = ((uint32 *)ref_frm_pos)[j]; + ((uint32 *)cur_frm_pos)[j] = READ_UINT32(((uint32 *)ref_frm_pos)+j); cur_frm_pos += 4; ref_frm_pos += 4; } @@ -526,7 +526,7 @@ void Indeo3Decoder::decodeChunk(byte *cur, byte *ref, int width, int height, switch (correction_type_sp[0][k]) { case 0: - *cur_lp = FROM_LE_32(((FROM_LE_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1); + *cur_lp = FROM_LE_32(((READ_LE_UINT32(ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1); lp2++; break; case 1: @@ -540,9 +540,9 @@ void Indeo3Decoder::decodeChunk(byte *cur, byte *ref, int width, int height, //warning("Glitch"); return; } - res = ((FROM_LE_16(((uint16 *)(ref_lp))[0]) >> 1) + correction_lp[lp2 & 0x01][*buf1]) << 1; + res = ((READ_LE_UINT16(((uint16 *)(ref_lp))) >> 1) + correction_lp[lp2 & 0x01][*buf1]) << 1; ((uint16 *)cur_lp)[0] = FROM_LE_16(res); - res = ((FROM_LE_16(((uint16 *)(ref_lp))[1]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1; + res = ((READ_LE_UINT16(((uint16 *)(ref_lp))+1) >> 1) + correction_lp[lp2 & 0x01][k]) << 1; ((uint16 *)cur_lp)[1] = FROM_LE_16(res); buf1++; lp2++; @@ -550,14 +550,14 @@ void Indeo3Decoder::decodeChunk(byte *cur, byte *ref, int width, int height, case 2: if (lp2 == 0) { for (i = 0, j = 0; i < 2; i++, j += width_tbl[1]) - cur_lp[j] = ref_lp[j]; + cur_lp[j] = READ_UINT32(ref_lp+j); lp2 += 2; } break; case 3: if (lp2 < 2) { for (i = 0, j = 0; i < (3 - lp2); i++, j += width_tbl[1]) - cur_lp[j] = ref_lp[j]; + cur_lp[j] = READ_UINT32(ref_lp+j); lp2 = 3; } break; @@ -567,7 +567,7 @@ void Indeo3Decoder::decodeChunk(byte *cur, byte *ref, int width, int height, if (rle_v1 == 1 || ref_vectors != NULL) { for (i = 0, j = 0; i < 4; i++, j += width_tbl[1]) - cur_lp[j] = ref_lp[j]; + cur_lp[j] = READ_UINT32(ref_lp+j); } RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) @@ -580,7 +580,7 @@ void Indeo3Decoder::decodeChunk(byte *cur, byte *ref, int width, int height, LP2_CHECK(buf1,rle_v3,lp2) case 4: for (i = 0, j = 0; i < (4 - lp2); i++, j += width_tbl[1]) - cur_lp[j] = ref_lp[j]; + cur_lp[j] = READ_UINT32(ref_lp+j); lp2 = 4; break; @@ -600,7 +600,7 @@ void Indeo3Decoder::decodeChunk(byte *cur, byte *ref, int width, int height, } if (ref_vectors != NULL) { for (i = 0, j = 0; i < 4; i++, j += width_tbl[1]) - cur_lp[j] = ref_lp[j]; + cur_lp[j] = READ_UINT32(ref_lp+j); } lp2 = 4; break; @@ -645,18 +645,18 @@ void Indeo3Decoder::decodeChunk(byte *cur, byte *ref, int width, int height, switch (correction_type_sp[lp2 & 0x01][k]) { case 0: - cur_lp[width_tbl[1]] = FROM_LE_32(((FROM_LE_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1); + cur_lp[width_tbl[1]] = FROM_LE_32(((READ_LE_UINT32(ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1); if (lp2 > 0 || flag1 == 0 || strip->ypos != 0) cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE; else - cur_lp[0] = FROM_LE_32(((FROM_LE_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1); + cur_lp[0] = FROM_LE_32(((READ_LE_UINT32(ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1); lp2++; break; case 1: - res = ((FROM_LE_16(((uint16 *)ref_lp)[0]) >> 1) + correction_lp[lp2 & 0x01][*buf1]) << 1; + res = ((READ_LE_UINT16(((uint16 *)ref_lp)) >> 1) + correction_lp[lp2 & 0x01][*buf1]) << 1; ((uint16 *)cur_lp)[width_tbl[2]] = FROM_LE_16(res); - res = ((FROM_LE_16(((uint16 *)ref_lp)[1]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1; + res = ((READ_LE_UINT16(((uint16 *)ref_lp)+1) >> 1) + correction_lp[lp2 & 0x01][k]) << 1; ((uint16 *)cur_lp)[width_tbl[2]+1] = FROM_LE_16(res); if (lp2 > 0 || flag1 == 0 || strip->ypos != 0) @@ -670,7 +670,7 @@ void Indeo3Decoder::decodeChunk(byte *cur, byte *ref, int width, int height, case 2: if (lp2 == 0) { for (i = 0, j = 0; i < 4; i++, j += width_tbl[1]) - cur_lp[j] = *ref_lp; + cur_lp[j] = READ_UINT32(ref_lp); lp2 += 2; } break; @@ -678,7 +678,7 @@ void Indeo3Decoder::decodeChunk(byte *cur, byte *ref, int width, int height, case 3: if (lp2 < 2) { for (i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) - cur_lp[j] = *ref_lp; + cur_lp[j] = READ_UINT32(ref_lp); lp2 = 3; } break; @@ -703,7 +703,7 @@ void Indeo3Decoder::decodeChunk(byte *cur, byte *ref, int width, int height, if (rle_v1 == 1) { for (i = 0, j = 0; i < 8; i++, j += width_tbl[1]) - cur_lp[j] = ref_lp[j]; + cur_lp[j] = READ_UINT32(ref_lp+j); } RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) @@ -716,7 +716,7 @@ void Indeo3Decoder::decodeChunk(byte *cur, byte *ref, int width, int height, LP2_CHECK(buf1,rle_v3,lp2) case 4: for (i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) - cur_lp[j] = *ref_lp; + cur_lp[j] = READ_UINT32(ref_lp); lp2 = 4; break; @@ -756,8 +756,8 @@ void Indeo3Decoder::decodeChunk(byte *cur, byte *ref, int width, int height, k = *buf1++; cur_lp = ((uint32 *)cur_frm_pos) + width_tbl[lp2 * 2]; ref_lp = ((uint32 *)cur_frm_pos) + width_tbl[(lp2 * 2) - 1]; - lv1 = ref_lp[0]; - lv2 = ref_lp[1]; + lv1 = READ_UINT32(ref_lp); + lv2 = READ_UINT32(ref_lp+1); if (lp2 == 0 && flag1 != 0) { #if defined(SCUMM_BIG_ENDIAN) lv1 = lv1 & 0xFF00FF00; @@ -936,28 +936,28 @@ void Indeo3Decoder::decodeChunk(byte *cur, byte *ref, int width, int height, case 0: lv1 = correctionloworder_lp[lp2 & 0x01][k]; lv2 = correctionhighorder_lp[lp2 & 0x01][k]; - cur_lp[0] = FROM_LE_32(((FROM_LE_32(ref_lp[0]) >> 1) + lv1) << 1); - cur_lp[1] = FROM_LE_32(((FROM_LE_32(ref_lp[1]) >> 1) + lv2) << 1); - cur_lp[width_tbl[1]] = FROM_LE_32(((FROM_LE_32(ref_lp[width_tbl[1]]) >> 1) + lv1) << 1); - cur_lp[width_tbl[1]+1] = FROM_LE_32(((FROM_LE_32(ref_lp[width_tbl[1]+1]) >> 1) + lv2) << 1); + cur_lp[0] = FROM_LE_32(((READ_LE_UINT32(ref_lp) >> 1) + lv1) << 1); + cur_lp[1] = FROM_LE_32(((READ_LE_UINT32(ref_lp+1) >> 1) + lv2) << 1); + cur_lp[width_tbl[1]] = FROM_LE_32(((READ_LE_UINT32(ref_lp+width_tbl[1]) >> 1) + lv1) << 1); + cur_lp[width_tbl[1]+1] = FROM_LE_32(((READ_LE_UINT32(ref_lp+width_tbl[1]+1) >> 1) + lv2) << 1); lp2++; break; case 1: lv1 = correctionloworder_lp[lp2 & 0x01][*buf1++]; lv2 = correctionloworder_lp[lp2 & 0x01][k]; - cur_lp[0] = FROM_LE_32(((FROM_LE_32(ref_lp[0]) >> 1) + lv1) << 1); - cur_lp[1] = FROM_LE_32(((FROM_LE_32(ref_lp[1]) >> 1) + lv2) << 1); - cur_lp[width_tbl[1]] = FROM_LE_32(((FROM_LE_32(ref_lp[width_tbl[1]]) >> 1) + lv1) << 1); - cur_lp[width_tbl[1]+1] = FROM_LE_32(((FROM_LE_32(ref_lp[width_tbl[1]+1]) >> 1) + lv2) << 1); + cur_lp[0] = FROM_LE_32(((READ_LE_UINT32(ref_lp) >> 1) + lv1) << 1); + cur_lp[1] = FROM_LE_32(((READ_LE_UINT32(ref_lp+1) >> 1) + lv2) << 1); + cur_lp[width_tbl[1]] = FROM_LE_32(((READ_LE_UINT32(ref_lp+width_tbl[1]) >> 1) + lv1) << 1); + cur_lp[width_tbl[1]+1] = FROM_LE_32(((READ_LE_UINT32(ref_lp+width_tbl[1]+1) >> 1) + lv2) << 1); lp2++; break; case 2: if (lp2 == 0) { for (i = 0, j = 0; i < 4; i++, j += width_tbl[1]) { - cur_lp[j] = ref_lp[j]; - cur_lp[j+1] = ref_lp[j+1]; + cur_lp[j] = READ_UINT32(ref_lp+j); + cur_lp[j+1] = READ_UINT32(ref_lp+j+1); } lp2 += 2; } @@ -966,8 +966,8 @@ void Indeo3Decoder::decodeChunk(byte *cur, byte *ref, int width, int height, case 3: if (lp2 < 2) { for (i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) { - cur_lp[j] = ref_lp[j]; - cur_lp[j+1] = ref_lp[j+1]; + cur_lp[j] = READ_UINT32(ref_lp+j); + cur_lp[j+1] = READ_UINT32(ref_lp+j+1); } lp2 = 3; } @@ -977,8 +977,8 @@ void Indeo3Decoder::decodeChunk(byte *cur, byte *ref, int width, int height, if (lp2 == 0) { RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3) for (i = 0, j = 0; i < 8; i++, j += width_tbl[1]) { - ((uint32 *)cur_frm_pos)[j] = ((uint32 *)ref_frm_pos)[j]; - ((uint32 *)cur_frm_pos)[j+1] = ((uint32 *)ref_frm_pos)[j+1]; + ((uint32 *)cur_frm_pos)[j] = READ_UINT32(((uint32 *)ref_frm_pos)+j); + ((uint32 *)cur_frm_pos)[j+1] = READ_UINT32(((uint32 *)ref_frm_pos)+j+1); } RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) break; @@ -992,8 +992,8 @@ void Indeo3Decoder::decodeChunk(byte *cur, byte *ref, int width, int height, case 6: case 4: for (i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) { - cur_lp[j] = ref_lp[j]; - cur_lp[j+1] = ref_lp[j+1]; + cur_lp[j] = READ_UINT32(ref_lp+j); + cur_lp[j+1] = READ_UINT32(ref_lp+j+1); } lp2 = 4; break; @@ -1037,8 +1037,8 @@ void Indeo3Decoder::decodeChunk(byte *cur, byte *ref, int width, int height, switch (correction_type_sp[lp2 & 0x01][k]) { case 0: - cur_lp[0] = FROM_LE_32(((FROM_LE_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1); - cur_lp[width_tbl[1]] = FROM_LE_32(((FROM_LE_32(ref_lp[width_tbl[1]]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1); + cur_lp[0] = FROM_LE_32(((READ_LE_UINT32(ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1); + cur_lp[width_tbl[1]] = FROM_LE_32(((READ_LE_UINT32(ref_lp+width_tbl[1]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1); lp2++; break; @@ -1051,13 +1051,13 @@ void Indeo3Decoder::decodeChunk(byte *cur, byte *ref, int width, int height, lv1 = (uint16)(correction_lp[lp2 & 0x01][*buf1++]); lv2 = (uint16)(correction_lp[lp2 & 0x01][k]); - res = (uint16)(((FROM_LE_16(((uint16 *)ref_lp)[0]) >> 1) + lv1) << 1); + res = (uint16)(((READ_LE_UINT16(((uint16 *)ref_lp)) >> 1) + lv1) << 1); ((uint16 *)cur_lp)[0] = FROM_LE_16(res); - res = (uint16)(((FROM_LE_16(((uint16 *)ref_lp)[1]) >> 1) + lv2) << 1); + res = (uint16)(((READ_LE_UINT16(((uint16 *)ref_lp)+1) >> 1) + lv2) << 1); ((uint16 *)cur_lp)[1] = FROM_LE_16(res); - res = (uint16)(((FROM_LE_16(((uint16 *)ref_lp)[width_tbl[2]]) >> 1) + lv1) << 1); + res = (uint16)(((READ_LE_UINT16(((uint16 *)ref_lp)+width_tbl[2]) >> 1) + lv1) << 1); ((uint16 *)cur_lp)[width_tbl[2]] = FROM_LE_16(res); - res = (uint16)(((FROM_LE_16(((uint16 *)ref_lp)[width_tbl[2]+1]) >> 1) + lv2) << 1); + res = (uint16)(((READ_LE_UINT16(((uint16 *)ref_lp)+width_tbl[2]+1) >> 1) + lv2) << 1); ((uint16 *)cur_lp)[width_tbl[2]+1] = FROM_LE_16(res); lp2++; break; @@ -1065,7 +1065,7 @@ void Indeo3Decoder::decodeChunk(byte *cur, byte *ref, int width, int height, case 2: if (lp2 == 0) { for (i = 0, j = 0; i < 4; i++, j += width_tbl[1]) - cur_lp[j] = ref_lp[j]; + cur_lp[j] = READ_UINT32(ref_lp+j); lp2 += 2; } break; @@ -1073,7 +1073,7 @@ void Indeo3Decoder::decodeChunk(byte *cur, byte *ref, int width, int height, case 3: if (lp2 < 2) { for (i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) - cur_lp[j] = ref_lp[j]; + cur_lp[j] = READ_UINT32(ref_lp+j); lp2 = 3; } break; @@ -1083,7 +1083,7 @@ void Indeo3Decoder::decodeChunk(byte *cur, byte *ref, int width, int height, RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3) for (i = 0, j = 0; i < 8; i++, j += width_tbl[1]) - cur_lp[j] = ref_lp[j]; + cur_lp[j] = READ_UINT32(ref_lp+j); RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) break; @@ -1097,7 +1097,7 @@ void Indeo3Decoder::decodeChunk(byte *cur, byte *ref, int width, int height, case 4: case 6: for (i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) - cur_lp[j] = ref_lp[j]; + cur_lp[j] = READ_UINT32(ref_lp+j); lp2 = 4; break; -- cgit v1.2.3