Evas ETC2: Fix horrible warnings in etc2_encoder

So I guess always compiling with debug flags and no
optimizations isn't the best idea as some really bad warnings
can be hidden. Thanks raster for the notice.
This commit is contained in:
Jean-Philippe ANDRE 2014-06-22 18:23:51 +09:00
parent d589e760d3
commit 4d35471e8e
1 changed files with 68 additions and 80 deletions

View File

@ -105,25 +105,10 @@ static const int kBlockWalk[16] = {
// Write a BGRA value for output to Evas // Write a BGRA value for output to Evas
#define BGRA(r,g,b,a) ((a << 24) | (r << 16) | (g << 8) | b) #define BGRA(r,g,b,a) ((a << 24) | (r << 16) | (g << 8) | b)
#ifndef WORDS_BIGENDIAN #define A_VAL(v) ((uint8_t) ((v & 0xFF000000) >> 24))
/* x86 */ #define R_VAL(v) ((uint8_t) ((v & 0x00FF0000) >> 16))
#define A_VAL(p) (((uint8_t *)(p))[3]) #define G_VAL(v) ((uint8_t) ((v & 0x0000FF00) >> 8))
#define R_VAL(p) (((uint8_t *)(p))[2]) #define B_VAL(v) ((uint8_t) ((v & 0x000000FF)))
#define G_VAL(p) (((uint8_t *)(p))[1])
#define B_VAL(p) (((uint8_t *)(p))[0])
#define R_IDX 2
#define G_IDX 1
#define B_IDX 0
#else
/* ppc */
#define A_VAL(p) (((uint8_t *)(p))[0])
#define R_VAL(p) (((uint8_t *)(p))[1])
#define G_VAL(p) (((uint8_t *)(p))[2])
#define B_VAL(p) (((uint8_t *)(p))[3])
#define R_IDX 1
#define G_IDX 2
#define B_IDX 3
#endif
#ifndef DBG #ifndef DBG
# ifdef DEBUG # ifdef DEBUG
@ -158,7 +143,7 @@ _etc2_alpha_block_pack(uint8_t *etc2_alpha,
// Compute alphas now // Compute alphas now
for (int i = 0; i < 16; i++) for (int i = 0; i < 16; i++)
{ {
const int realA = A_VAL(bgra + kBlockWalk[i]); const int realA = A_VAL(bgra[kBlockWalk[i]]);
int minErr = INT_MAX, idx = 0; int minErr = INT_MAX, idx = 0;
// Brute force -- find modifier index // Brute force -- find modifier index
@ -206,12 +191,12 @@ _etc2_alpha_encode(uint8_t *etc2_alpha, const uint32_t *bgra,
int base_codeword; int base_codeword;
int multiplier, bestMult = 0; int multiplier, bestMult = 0;
int modifierIdx, bestIdx = 0, bestBase = 128; int modifierIdx, bestIdx = 0, bestBase = 128;
int err, base_range, base_step = 1, max_error = 0; int err, base_range = 40, base_step = 4, max_error = 0;
// Try to select the best alpha value (avg) // Try to select the best alpha value (avg)
for (int i = 0; i < 16; i++) for (int i = 0; i < 16; i++)
{ {
alphas[i] = A_VAL(bgra + kBlockWalk[i]); alphas[i] = A_VAL(bgra[kBlockWalk[i]]);
avg += alphas[i]; avg += alphas[i];
} }
avg /= 16; avg /= 16;
@ -294,12 +279,12 @@ _etc2_t_mode_header_pack(uint8_t *etc2,
uint32_t color1, uint32_t color2, int distance) uint32_t color1, uint32_t color2, int distance)
{ {
// 4 bit colors // 4 bit colors
int r1_4 = R_VAL(&color1) >> 4; int r1_4 = R_VAL(color1) >> 4;
int g1_4 = G_VAL(&color1) >> 4; int g1_4 = G_VAL(color1) >> 4;
int b1_4 = B_VAL(&color1) >> 4; int b1_4 = B_VAL(color1) >> 4;
int r2_4 = R_VAL(&color2) >> 4; int r2_4 = R_VAL(color2) >> 4;
int g2_4 = G_VAL(&color2) >> 4; int g2_4 = G_VAL(color2) >> 4;
int b2_4 = B_VAL(&color2) >> 4; int b2_4 = B_VAL(color2) >> 4;
int distanceIdx, R, dR; int distanceIdx, R, dR;
for (distanceIdx = 0; distanceIdx < 8; distanceIdx++) for (distanceIdx = 0; distanceIdx < 8; distanceIdx++)
@ -378,12 +363,12 @@ _etc2_h_mode_header_pack(uint8_t *etc2, Eina_Bool *swap_colors,
*swap_colors = (c1 != color1); *swap_colors = (c1 != color1);
// 4 bit colors // 4 bit colors
r1_4 = R_VAL(&c1) >> 4; r1_4 = R_VAL(c1) >> 4;
g1_4 = G_VAL(&c1) >> 4; g1_4 = G_VAL(c1) >> 4;
b1_4 = B_VAL(&c1) >> 4; b1_4 = B_VAL(c1) >> 4;
r2_4 = R_VAL(&c2) >> 4; r2_4 = R_VAL(c2) >> 4;
g2_4 = G_VAL(&c2) >> 4; g2_4 = G_VAL(c2) >> 4;
b2_4 = B_VAL(&c2) >> 4; b2_4 = B_VAL(c2) >> 4;
// R1 + G1a. R + [dR] must be inside [0..31]. Scanning all values. Not smart. // R1 + G1a. R + [dR] must be inside [0..31]. Scanning all values. Not smart.
R = r1_4; R = r1_4;
@ -431,18 +416,18 @@ _etc2_h_mode_header_pack(uint8_t *etc2, Eina_Bool *swap_colors,
static inline int static inline int
_rgb_distance_percept(uint32_t color1, uint32_t color2) _rgb_distance_percept(uint32_t color1, uint32_t color2)
{ {
int R = R_VAL(&color1) - R_VAL(&color2); int R = R_VAL(color1) - R_VAL(color2);
int G = G_VAL(&color1) - G_VAL(&color2); int G = G_VAL(color1) - G_VAL(color2);
int B = B_VAL(&color1) - B_VAL(&color2); int B = B_VAL(color1) - B_VAL(color2);
return (R * R * R_WEIGHT) + (G * G * G_WEIGHT) + (B * B * B_WEIGHT); return (R * R * R_WEIGHT) + (G * G * G_WEIGHT) + (B * B * B_WEIGHT);
} }
static inline int static inline int
_rgb_distance_euclid(uint32_t color1, uint32_t color2) _rgb_distance_euclid(uint32_t color1, uint32_t color2)
{ {
int R = R_VAL(&color1) - R_VAL(&color2); int R = R_VAL(color1) - R_VAL(color2);
int G = G_VAL(&color1) - G_VAL(&color2); int G = G_VAL(color1) - G_VAL(color2);
int B = B_VAL(&color1) - B_VAL(&color2); int B = B_VAL(color1) - B_VAL(color2);
return (R * R) + (G * G) + (B * B); return (R * R) + (G * G) + (B * B);
} }
@ -452,7 +437,10 @@ _etc2_th_mode_block_pack(uint8_t *etc2, Eina_Bool h_mode,
const uint32_t *bgra, Eina_Bool write, const uint32_t *bgra, Eina_Bool write,
Eina_Bool *swap_colors) Eina_Bool *swap_colors)
{ {
uint8_t paint_colors[4][4]; union {
uint8_t c[4];
uint32_t v;
} paint_colors[4];
int errAcc = 0; int errAcc = 0;
if (write) if (write)
@ -481,17 +469,17 @@ _etc2_th_mode_block_pack(uint8_t *etc2, Eina_Bool h_mode,
{ {
if (!h_mode) if (!h_mode)
{ {
paint_colors[0][k] = ((uint8_t *) &color1)[k]; paint_colors[0].c[k] = ((uint8_t *) &color1)[k];
paint_colors[1][k] = CLAMP(((uint8_t *) &color2)[k] + distance); paint_colors[1].c[k] = CLAMP(((uint8_t *) &color2)[k] + distance);
paint_colors[2][k] = ((uint8_t *) &color2)[k]; paint_colors[2].c[k] = ((uint8_t *) &color2)[k];
paint_colors[3][k] = CLAMP(((uint8_t *) &color2)[k] - distance); paint_colors[3].c[k] = CLAMP(((uint8_t *) &color2)[k] - distance);
} }
else else
{ {
paint_colors[0][k] = CLAMP(((uint8_t *) &color1)[k] + distance); paint_colors[0].c[k] = CLAMP(((uint8_t *) &color1)[k] + distance);
paint_colors[1][k] = CLAMP(((uint8_t *) &color1)[k] - distance); paint_colors[1].c[k] = CLAMP(((uint8_t *) &color1)[k] - distance);
paint_colors[2][k] = CLAMP(((uint8_t *) &color2)[k] + distance); paint_colors[2].c[k] = CLAMP(((uint8_t *) &color2)[k] + distance);
paint_colors[3][k] = CLAMP(((uint8_t *) &color2)[k] - distance); paint_colors[3].c[k] = CLAMP(((uint8_t *) &color2)[k] - distance);
} }
} }
@ -503,7 +491,7 @@ _etc2_th_mode_block_pack(uint8_t *etc2, Eina_Bool h_mode,
for (int idx = 0; idx < 4; idx++) for (int idx = 0; idx < 4; idx++)
{ {
int dist = _rgb_distance_euclid(pixel, *((uint32_t *) paint_colors[idx])); int dist = _rgb_distance_euclid(pixel, paint_colors[idx].v);
if (dist < bestDist) if (dist < bestDist)
{ {
bestDist = dist; bestDist = dist;
@ -527,9 +515,9 @@ _etc2_th_mode_block_pack(uint8_t *etc2, Eina_Bool h_mode,
static uint32_t static uint32_t
_color_reduce_444(uint32_t color) _color_reduce_444(uint32_t color)
{ {
int R = R_VAL(&color); int R = R_VAL(color);
int G = G_VAL(&color); int G = G_VAL(color);
int B = B_VAL(&color); int B = B_VAL(color);
int R1, R2, G1, G2, B1, B2; int R1, R2, G1, G2, B1, B2;
R1 = (R & 0xF0) | (R >> 4); R1 = (R & 0xF0) | (R >> 4);
@ -549,9 +537,9 @@ _color_reduce_444(uint32_t color)
static uint32_t static uint32_t
_color_reduce_676(uint32_t color) _color_reduce_676(uint32_t color)
{ {
int R = R_VAL(&color); int R = R_VAL(color);
int G = G_VAL(&color); int G = G_VAL(color);
int B = B_VAL(&color); int B = B_VAL(color);
int R1, G1, B1; int R1, G1, B1;
// FIXME: Do we have better candidates to try? // FIXME: Do we have better candidates to try?
@ -628,16 +616,16 @@ _block_main_colors_find(uint32_t *color1_out, uint32_t *color2_out,
// k-means update step // k-means update step
for (int k = 0; k < cluster1_cnt; k++) for (int k = 0; k < cluster1_cnt; k++)
{ {
r1 += R_VAL(bgra + cluster1[k]); r1 += R_VAL(bgra[cluster1[k]]);
g1 += G_VAL(bgra + cluster1[k]); g1 += G_VAL(bgra[cluster1[k]]);
b1 += B_VAL(bgra + cluster1[k]); b1 += B_VAL(bgra[cluster1[k]]);
} }
for (int k = 0; k < cluster2_cnt; k++) for (int k = 0; k < cluster2_cnt; k++)
{ {
r2 += R_VAL(bgra + cluster2[k]); r2 += R_VAL(bgra[cluster2[k]]);
g2 += G_VAL(bgra + cluster2[k]); g2 += G_VAL(bgra[cluster2[k]]);
b2 += B_VAL(bgra + cluster2[k]); b2 += B_VAL(bgra[cluster2[k]]);
} }
r1 /= cluster1_cnt; r1 /= cluster1_cnt;
@ -859,15 +847,15 @@ _etc2_planar_mode_block_pack(uint8_t *etc2,
unsigned int err = 0; unsigned int err = 0;
uint32_t RO, RH, RV, GO, GH, GV, BO, BH, BV; uint32_t RO, RH, RV, GO, GH, GV, BO, BH, BV;
RO = R_VAL(&Ocol); RO = R_VAL(Ocol);
RH = R_VAL(&Hcol); RH = R_VAL(Hcol);
RV = R_VAL(&Vcol); RV = R_VAL(Vcol);
GO = G_VAL(&Ocol); GO = G_VAL(Ocol);
GH = G_VAL(&Hcol); GH = G_VAL(Hcol);
GV = G_VAL(&Vcol); GV = G_VAL(Vcol);
BO = B_VAL(&Ocol); BO = B_VAL(Ocol);
BH = B_VAL(&Hcol); BH = B_VAL(Hcol);
BV = B_VAL(&Vcol); BV = B_VAL(Vcol);
if (write) if (write)
{ {
@ -908,19 +896,19 @@ _etc2_planar_mode_block_encode(uint8_t *etc2, const uint32_t *bgra,
* We extrapolate the values from (0,3) and (3,0). * We extrapolate the values from (0,3) and (3,0).
*/ */
RO = R_VAL(&(bgra[0])); RO = R_VAL((bgra[0]));
GO = G_VAL(&(bgra[0])); GO = G_VAL((bgra[0]));
BO = B_VAL(&(bgra[0])); BO = B_VAL((bgra[0]));
Ocol = _color_reduce_676(bgra[0]); Ocol = _color_reduce_676(bgra[0]);
Rx = CLAMP(RO + (4 * (R_VAL(&(bgra[3])) - RO)) / 3); Rx = CLAMP(RO + (4 * (R_VAL((bgra[3])) - RO)) / 3);
Gx = CLAMP(GO + (4 * (G_VAL(&(bgra[3])) - GO)) / 3); Gx = CLAMP(GO + (4 * (G_VAL((bgra[3])) - GO)) / 3);
Bx = CLAMP(BO + (4 * (B_VAL(&(bgra[3])) - BO)) / 3); Bx = CLAMP(BO + (4 * (B_VAL((bgra[3])) - BO)) / 3);
Hcol = _color_reduce_676(BGRA(Rx, Gx, Bx, 0xFF)); Hcol = _color_reduce_676(BGRA(Rx, Gx, Bx, 0xFF));
Rx = CLAMP(RO + (4 * (R_VAL(&(bgra[12])) - RO)) / 3); Rx = CLAMP(RO + (4 * (R_VAL((bgra[12])) - RO)) / 3);
Gx = CLAMP(GO + (4 * (G_VAL(&(bgra[12])) - GO)) / 3); Gx = CLAMP(GO + (4 * (G_VAL((bgra[12])) - GO)) / 3);
Bx = CLAMP(BO + (4 * (B_VAL(&(bgra[12])) - BO)) / 3); Bx = CLAMP(BO + (4 * (B_VAL((bgra[12])) - BO)) / 3);
Vcol = _color_reduce_676(BGRA(Rx, Gx, Bx, 0xFF)); Vcol = _color_reduce_676(BGRA(Rx, Gx, Bx, 0xFF));
err = _etc2_planar_mode_block_pack(etc2, Ocol, Hcol, Vcol, bgra, EINA_TRUE); err = _etc2_planar_mode_block_pack(etc2, Ocol, Hcol, Vcol, bgra, EINA_TRUE);