a dirty up.... nah just kidding, yet another clean up round

svn-id: r6407
This commit is contained in:
Max Horn 2003-01-12 00:55:03 +00:00
parent e907e64628
commit 5ad60a69f3

View File

@ -228,12 +228,12 @@ static byte smush_buf_small[32768];
static int16 smush_table[256]; static int16 smush_table[256];
void Codec47Decoder::makeTables37(int32 param) { void Codec47Decoder::makeTables37(int32 param) {
int32 variable1, variable2, variable3, variable4; int32 variable1, variable2;
int32 tmp_param, b1, b2; int32 b1, b2;
int32 * tmp_table37_1_2, * tmp_table37_1_1, * tmp_table37_2_2, * tmp_table37_2_1; int32 * tmp_table37_1_2, * tmp_table37_1_1, * tmp_table37_2_2, * tmp_table37_2_1;
int32 value_table37_1_2, value_table37_1_1, value_table37_2_2, value_table37_2_1; int32 value_table37_1_2, value_table37_1_1, value_table37_2_2, value_table37_2_1;
int32 table[64], tmp_a, tmp_c, s; int32 table[64], tmp, s;
int32 * table37_1 = 0, * table37_2 = 0, * table_ptr, l; int32 * table37_1 = 0, * table37_2 = 0, * table_ptr;
int i, x, y; int i, x, y;
byte * ptr; byte * ptr;
@ -241,12 +241,12 @@ void Codec47Decoder::makeTables37(int32 param) {
table37_1 = &codec37_table[32]; table37_1 = &codec37_table[32];
table37_2 = &codec37_table[48]; table37_2 = &codec37_table[48];
ptr = smush_buf_big + 384; ptr = smush_buf_big + 384;
for (l = 0; l < 256; l++) { for (i = 0; i < 256; i++) {
*ptr = 0; *ptr = 0;
ptr += 388; ptr += 388;
} }
ptr = smush_buf_big + 385; ptr = smush_buf_big + 385;
for (l = 0; l < 256; l++) { for (i = 0; i < 256; i++) {
*ptr = 0; *ptr = 0;
ptr += 388; ptr += 388;
} }
@ -254,12 +254,12 @@ void Codec47Decoder::makeTables37(int32 param) {
table37_1 = &codec37_table[0]; table37_1 = &codec37_table[0];
table37_2 = &codec37_table[16]; table37_2 = &codec37_table[16];
ptr = smush_buf_small + 96; ptr = smush_buf_small + 96;
for (l = 0; l < 256; l++) { for (i = 0; i < 256; i++) {
*ptr = 0; *ptr = 0;
ptr += 128; ptr += 128;
} }
ptr = smush_buf_small + 97; ptr = smush_buf_small + 97;
for (l = 0; l < 256; l++) { for (i = 0; i < 256; i++) {
*ptr = 0; *ptr = 0;
ptr += 128; ptr += 128;
} }
@ -268,7 +268,6 @@ void Codec47Decoder::makeTables37(int32 param) {
} }
s = 0; s = 0;
tmp_param = param * param;
tmp_table37_1_1 = table37_1; tmp_table37_1_1 = table37_1;
tmp_table37_2_1 = table37_2; tmp_table37_2_1 = table37_2;
for (x = 0; x < 16; x++) { for (x = 0; x < 16; x++) {
@ -283,12 +282,12 @@ void Codec47Decoder::makeTables37(int32 param) {
if (value_table37_2_1 == 0) { if (value_table37_2_1 == 0) {
b1 = 0; b1 = 0;
} else if (param == value_table37_2_1 + 1) { } else if (value_table37_2_1 == param - 1) {
b1 = 1; b1 = 1;
} else { } else {
if (value_table37_1_1 == 0) { if (value_table37_1_1 == 0) {
b1 = 2; b1 = 2;
} else if (param == value_table37_1_1 + 1) { } else if (value_table37_1_1 == param - 1) {
b1 = 3; b1 = 3;
} else { } else {
b1 = 4; b1 = 4;
@ -297,42 +296,38 @@ void Codec47Decoder::makeTables37(int32 param) {
if (value_table37_2_2 == 0) { if (value_table37_2_2 == 0) {
b2 = 0; b2 = 0;
} else if (param == value_table37_2_2 + 1) { } else if (value_table37_2_2 == param - 1) {
b2 = 1; b2 = 1;
} else { } else {
if (value_table37_1_2 == 0) { if (value_table37_1_2 == 0) {
b2 = 2; b2 = 2;
} else if (param == value_table37_1_2 + 1) { } else if (value_table37_1_2 == param - 1) {
b2 = 3; b2 = 3;
} else { } else {
b2 = 4; b2 = 4;
} }
} }
i = tmp_param - 1;
if(i != 0) { memset(table, 0, param * param * 4);
do {
table[i] = 0; variable2 = abs(value_table37_2_2 - value_table37_2_1);
} while (i-- != 0); tmp = abs(value_table37_1_2 - value_table37_1_1);
if (variable2 <= tmp) {
variable2 = tmp;
} }
tmp_c = abs(value_table37_2_2 - value_table37_2_1); for (variable1 = 0; variable1 <= variable2; variable1++) {
tmp_a = abs(value_table37_1_2 - value_table37_1_1); int32 variable3, variable4;
if (tmp_c <= tmp_a) {
tmp_c = tmp_a;
}
variable2 = tmp_c + 1; if (variable2 > 0) {
for (variable1 = 0; variable1 < variable2; variable1++) { int32 tmp_c, tmp_ib;
if (variable2 > 1) {
int32 xyz, tmp_ib;
// This code linearly interpolates between value_table37_1_1 and value_table37_1_2 // This code linearly interpolates between value_table37_1_1 and value_table37_1_2
// respectively value_table37_2_1 and value_table37_2_2. // respectively value_table37_2_1 and value_table37_2_2.
tmp_c = variable2 - variable1 - 1; tmp_c = variable2 - variable1;
tmp_ib = (variable2 - 1) / 2; tmp_ib = variable2 / 2;
xyz = variable2 - 1; variable4 = (value_table37_1_1 * variable1 + value_table37_1_2 * tmp_c + tmp_ib) / variable2;
variable4 = (value_table37_1_1 * variable1 + value_table37_1_2 * tmp_c + tmp_ib) / xyz; variable3 = (value_table37_2_1 * variable1 + value_table37_2_2 * tmp_c + tmp_ib) / variable2;
variable3 = (value_table37_2_1 * variable1 + value_table37_2_2 * tmp_c + tmp_ib) / xyz;
} else { } else {
variable4 = value_table37_1_1; variable4 = value_table37_1_1;
variable3 = value_table37_2_1; variable3 = value_table37_2_1;
@ -431,75 +426,43 @@ void Codec47Decoder::makeTables47(int32 width) {
s = 0; s = 0;
tmp_value = 0; tmp_value = 0;
do { do {
d = 0; for (d = 0; d < smush_buf_small[96 + c]; d++) {
tmp = smush_buf_small[96 + c]; tmp = smush_buf_small[64 + c + d];
if (tmp != 0) { tmp2 = tmp >> 2;
do { tmp &= 3;
tmp = smush_buf_small[64 + c + d]; tmp2 &= 0xFFFF00FF;
tmp2 = tmp; tmp2 = tmp2 * width + tmp;
tmp2 >>= 2; smush_buf_small[(s + d) * 2] = (byte)tmp2;
tmp &= 3; smush_buf_small[(s + d) * 2 + 1] = tmp2 >> 8;
tmp2 &= 0xFFFF00FF;
tmp2 *= (int16)width;
tmp2 += tmp;
smush_buf_small[(s + d) * 2] = (byte)tmp2;
smush_buf_small[(s + d) * 2 + 1] = tmp2 >> 8;
d++;
tmp = smush_buf_small[96 + c];
} while (tmp > d);
} }
d = 0; for (d = 0; d < smush_buf_small[97 + c]; d++) {
tmp = smush_buf_small[97 + c]; tmp = smush_buf_small[80 + c + d];
if (tmp != 0) { tmp2 = tmp >> 2;
do { tmp &= 3;
tmp = smush_buf_small[80 + c + d]; tmp2 &= 0xFFFF00FF;
tmp2 = tmp; tmp2 = tmp2 * width + tmp;
tmp2 >>= 2; smush_buf_small[32 + (s + d) * 2] = (byte)tmp2;
tmp &= 3; smush_buf_small[32 + (s + d) * 2 + 1] = tmp2 >> 8;
tmp2 &= 0xFFFF00FF;
tmp2 *= (int16)width;
tmp2 += tmp;
smush_buf_small[32 + (s + d) * 2] = (byte)tmp2;
smush_buf_small[32 + (s + d) * 2 + 1] = tmp2 >> 8;
d++;
tmp = smush_buf_small[97 + c];
} while (tmp > d);
} }
d = 0; for (d = 0; d < smush_buf_big[384 + a]; d++) {
tmp = smush_buf_big[384 + a]; tmp = smush_buf_big[256 + a + d];
if (tmp != 0) { tmp2 = tmp >> 3;
do { tmp = tmp & 7;
tmp = smush_buf_big[256 + a + d]; tmp2 &= 0xFFFF00FF;
tmp2 = tmp >> 3; tmp2 = tmp2 * width + tmp;
tmp = tmp & 7; tmp_offset = tmp_value + d;
tmp2 &= 0xFFFF00FF; smush_buf_big[tmp_offset * 2] = (byte)tmp2;
tmp2 *= (int16)width; smush_buf_big[tmp_offset * 2 + 1] = tmp2 >> 8;
tmp2 += tmp;
tmp_offset = tmp_value;
tmp_offset += d;
d++;
smush_buf_big[tmp_offset * 2] = (byte)tmp2;
smush_buf_big[tmp_offset * 2 + 1] = tmp2 >> 8;
tmp = smush_buf_big[384 + a];
} while (tmp > d);
} }
d = 0; for (d = 0; d < smush_buf_big[385 + a]; d++) {
tmp = smush_buf_big[385 + a]; tmp = smush_buf_big[320 + a + d];
if (tmp != 0) { tmp2 = tmp >> 3;
do { tmp = tmp & 7;
tmp = smush_buf_big[320 + a + d]; tmp2 &= 0xFFFF00FF;
tmp2 = tmp >> 3; tmp2 = tmp2 * width + tmp;
tmp = tmp & 7; tmp_offset = tmp_value + d;
tmp2 &= 0xFFFF00FF; smush_buf_big[128 + (tmp_offset * 2)] = (byte)tmp2;
tmp2 *= (int16)width; smush_buf_big[128 + (tmp_offset * 2) + 1] = tmp2 >> 8;
tmp2 += tmp;
tmp_offset = tmp_value;
tmp_offset += d;
d++;
smush_buf_big[128 + (tmp_offset * 2)] = (byte)tmp2;
smush_buf_big[128 + (tmp_offset * 2) + 1] = tmp2 >> 8;
tmp = smush_buf_big[385 + a];
} while (tmp > d);
} }
a += 388; a += 388;
@ -525,19 +488,20 @@ void Codec47Decoder::bompDecode(byte *dst, byte *src, int32 len) {
src += num; src += num;
} }
dst += num; dst += num;
} while (len -= num); len -= num;
} while (len > 0);
assert(len == 0);
} }
static int32 codec47_decode2_offset1; static int32 codec47_decode2_offset1;
static int32 codec47_decode2_offset2; static int32 codec47_decode2_offset2;
static int32 d_pitch;
static byte * codec47_decode2_param_ptr; static byte * codec47_decode2_param_ptr;
static int32 codec47_subgfx_width_blocks; static int32 codec47_subgfx_width_blocks;
static int32 codec47_subgfx_height_blocks; static int32 codec47_subgfx_height_blocks;
static int32 codec47_subgfx_width_pixels; static int32 codec47_subgfx_width_pixels;
static byte * d_src; static byte * d_src;
static void codec47_subgfx_lev4(byte * d_dst) { static void codec47_subgfx_lev4(byte * d_dst, const int32 d_pitch) {
int32 tmp; int32 tmp;
byte code = *d_src++; byte code = *d_src++;
@ -566,30 +530,34 @@ static void codec47_subgfx_lev4(byte * d_dst) {
} }
} }
static void codec47_subgfx_lev3(byte * d_dst) { static void codec47_subgfx_lev3(byte * d_dst, const int32 d_pitch) {
int32 tmp; int32 tmp;
byte code = *d_src++; byte code = *d_src++;
int i; int i;
if (code < 0xF8) { if (code < 0xF8) {
tmp = smush_table[code] + codec47_decode2_offset1; tmp = smush_table[code] + codec47_decode2_offset1;
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++) {
*(uint32*)(d_dst + (d_pitch * i)) = *(uint32*)(d_dst + (d_pitch * i) + tmp); *(uint32*)(d_dst) = *(uint32*)(d_dst + tmp);
d_dst += d_pitch;
}
} else if (code == 0xFF) { } else if (code == 0xFF) {
byte * tmp_dst = d_dst; byte * tmp_dst = d_dst;
codec47_subgfx_lev4(d_dst); codec47_subgfx_lev4(d_dst, d_pitch);
d_dst += 2; d_dst += 2;
codec47_subgfx_lev4(d_dst); codec47_subgfx_lev4(d_dst, d_pitch);
d_dst += d_pitch * 2 - 2; d_dst += d_pitch * 2 - 2;
codec47_subgfx_lev4(d_dst); codec47_subgfx_lev4(d_dst, d_pitch);
d_dst += 2; d_dst += 2;
codec47_subgfx_lev4(d_dst); codec47_subgfx_lev4(d_dst, d_pitch);
d_dst = tmp_dst; d_dst = tmp_dst;
} else if (code == 0xFE) { } else if (code == 0xFE) {
byte t = *d_src++; byte t = *d_src++;
uint32 val = t << 24 | t << 16 | t << 8 | t; uint32 val = t << 24 | t << 16 | t << 8 | t;
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++) {
*(uint32*)(d_dst + (d_pitch * i)) = val; *(uint32*)(d_dst) = val;
d_dst += d_pitch;
}
} else if (code == 0xFD) { } else if (code == 0xFD) {
byte * tmp_ptr = (*d_src++ << 7) + smush_buf_small; byte * tmp_ptr = (*d_src++ << 7) + smush_buf_small;
int32 l = *(tmp_ptr + 96); int32 l = *(tmp_ptr + 96);
@ -608,17 +576,21 @@ static void codec47_subgfx_lev3(byte * d_dst) {
} }
} else if (code == 0xFC) { } else if (code == 0xFC) {
tmp = codec47_decode2_offset2; tmp = codec47_decode2_offset2;
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++) {
*(uint32*)(d_dst + (d_pitch * i)) = *(uint32*)(d_dst + (d_pitch * i) + tmp); *(uint32*)(d_dst) = *(uint32*)(d_dst + tmp);
d_dst += d_pitch;
}
} else { } else {
byte t = codec47_decode2_param_ptr[code]; byte t = codec47_decode2_param_ptr[code];
uint32 val = t << 24 | t << 16 | t << 8 | t; uint32 val = t << 24 | t << 16 | t << 8 | t;
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++) {
*(uint32*)(d_dst + (d_pitch * i)) = val; *(uint32*)(d_dst) = val;
d_dst += d_pitch;
}
} }
} }
static void codec47_subgfx_lev2(byte * d_dst) { static void codec47_subgfx_lev2(byte * d_dst, const int32 d_pitch) {
int32 tmp, tmp2; int32 tmp, tmp2;
byte code = *d_src++; byte code = *d_src++;
int i; int i;
@ -626,25 +598,27 @@ static void codec47_subgfx_lev2(byte * d_dst) {
if (code < 0xF8) { if (code < 0xF8) {
tmp2 = smush_table[code] + codec47_decode2_offset1; tmp2 = smush_table[code] + codec47_decode2_offset1;
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
*(uint32*)(d_dst + (d_pitch * i) + 0) = *(uint32*)(d_dst + (d_pitch * i) + tmp2); *(uint32*)(d_dst + 0) = *(uint32*)(d_dst + tmp2);
*(uint32*)(d_dst + (d_pitch * i) + 4) = *(uint32*)(d_dst + (d_pitch * i) + tmp2 + 4); *(uint32*)(d_dst + 4) = *(uint32*)(d_dst + tmp2 + 4);
d_dst += d_pitch;
} }
} else if (code == 0xFF) { } else if (code == 0xFF) {
byte * tmp_dst = d_dst; byte * tmp_dst = d_dst;
codec47_subgfx_lev3(d_dst); codec47_subgfx_lev3(d_dst, d_pitch);
d_dst += 4; d_dst += 4;
codec47_subgfx_lev3(d_dst); codec47_subgfx_lev3(d_dst, d_pitch);
d_dst += d_pitch * 4 - 4; d_dst += d_pitch * 4 - 4;
codec47_subgfx_lev3(d_dst); codec47_subgfx_lev3(d_dst, d_pitch);
d_dst += 4; d_dst += 4;
codec47_subgfx_lev3(d_dst); codec47_subgfx_lev3(d_dst, d_pitch);
d_dst = tmp_dst; d_dst = tmp_dst;
} else if (code == 0xFE) { } else if (code == 0xFE) {
byte t = *d_src++; byte t = *d_src++;
int32 val = t << 24 | t << 16 | t << 8 | t; int32 val = t << 24 | t << 16 | t << 8 | t;
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
*(uint32*)(d_dst + (d_pitch * i)) = val; *(uint32*)(d_dst) = val;
*(uint32*)(d_dst + (d_pitch * i) + 4) = val; *(uint32*)(d_dst + 4) = val;
d_dst += d_pitch;
} }
} else if (code == 0xFD) { } else if (code == 0xFD) {
tmp = *d_src++; tmp = *d_src++;
@ -669,15 +643,17 @@ static void codec47_subgfx_lev2(byte * d_dst) {
} else if (code == 0xFC) { } else if (code == 0xFC) {
tmp2 = codec47_decode2_offset2; tmp2 = codec47_decode2_offset2;
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
*(uint32*)(d_dst + (d_pitch * i) + 0) = *(uint32*)(d_dst + (d_pitch * i) + tmp2); *(uint32*)(d_dst + 0) = *(uint32*)(d_dst + tmp2);
*(uint32*)(d_dst + (d_pitch * i) + 4) = *(uint32*)(d_dst + (d_pitch * i) + tmp2 + 4); *(uint32*)(d_dst + 4) = *(uint32*)(d_dst + tmp2 + 4);
d_dst += d_pitch;
} }
} else { } else {
byte t = *(codec47_decode2_param_ptr + code); byte t = *(codec47_decode2_param_ptr + code);
int32 val = t << 24 | t << 16 | t << 8 | t; int32 val = t << 24 | t << 16 | t << 8 | t;
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
*(uint32*)(d_dst + (d_pitch * i)) = val; *(uint32*)(d_dst) = val;
*(uint32*)(d_dst + (d_pitch * i) + 4) = val; *(uint32*)(d_dst + 4) = val;
d_dst += d_pitch;
} }
} }
} }
@ -688,7 +664,6 @@ void Codec47Decoder::decode2(byte * dst, byte * src, int32 offset1, int32 offset
d_src = src; d_src = src;
codec47_decode2_offset1 = offset1; codec47_decode2_offset1 = offset1;
codec47_decode2_offset2 = offset2; codec47_decode2_offset2 = offset2;
d_pitch = pitch;
codec47_decode2_param_ptr = param_ptr - 0xf8; codec47_decode2_param_ptr = param_ptr - 0xf8;
codec47_subgfx_height_blocks = (height + 7) >> 3; codec47_subgfx_height_blocks = (height + 7) >> 3;
codec47_subgfx_width_blocks = (pitch + 7) >> 3; codec47_subgfx_width_blocks = (pitch + 7) >> 3;
@ -698,7 +673,7 @@ void Codec47Decoder::decode2(byte * dst, byte * src, int32 offset1, int32 offset
do { do {
int32 tmp_codec47_subgfx_width_blocks = codec47_subgfx_width_blocks; int32 tmp_codec47_subgfx_width_blocks = codec47_subgfx_width_blocks;
do { do {
codec47_subgfx_lev2(dst); codec47_subgfx_lev2(dst, pitch);
dst += 8; dst += 8;
} while (--tmp_codec47_subgfx_width_blocks); } while (--tmp_codec47_subgfx_width_blocks);
dst += codec47_subgfx_width_pixels; dst += codec47_subgfx_width_pixels;