summaryrefslogtreecommitdiff
path: root/src/static_libs
diff options
context:
space:
mode:
authorJean-Philippe ANDRE <jpeg@videolan.org>2014-06-22 18:23:51 +0900
committerJean-Philippe ANDRE <jpeg@videolan.org>2014-06-22 18:57:41 +0900
commit4d35471e8e7fe91f657c1dca05bbb2dbd6cda8e3 (patch)
treed8e9bad64e32c04ba7bd59a4270585e9165ace1f /src/static_libs
parentd589e760d31ed2cea371eef11bdb82b73181859c (diff)
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.
Diffstat (limited to 'src/static_libs')
-rw-r--r--src/static_libs/rg_etc/etc2_encoder.c148
1 files changed, 68 insertions, 80 deletions
diff --git a/src/static_libs/rg_etc/etc2_encoder.c b/src/static_libs/rg_etc/etc2_encoder.c
index 2928974..d4bc11c 100644
--- a/src/static_libs/rg_etc/etc2_encoder.c
+++ b/src/static_libs/rg_etc/etc2_encoder.c
@@ -105,25 +105,10 @@ static const int kBlockWalk[16] = {
105// Write a BGRA value for output to Evas 105// Write a BGRA value for output to Evas
106#define BGRA(r,g,b,a) ((a << 24) | (r << 16) | (g << 8) | b) 106#define BGRA(r,g,b,a) ((a << 24) | (r << 16) | (g << 8) | b)
107 107
108#ifndef WORDS_BIGENDIAN 108#define A_VAL(v) ((uint8_t) ((v & 0xFF000000) >> 24))
109/* x86 */ 109#define R_VAL(v) ((uint8_t) ((v & 0x00FF0000) >> 16))
110#define A_VAL(p) (((uint8_t *)(p))[3]) 110#define G_VAL(v) ((uint8_t) ((v & 0x0000FF00) >> 8))
111#define R_VAL(p) (((uint8_t *)(p))[2]) 111#define B_VAL(v) ((uint8_t) ((v & 0x000000FF)))
112#define G_VAL(p) (((uint8_t *)(p))[1])
113#define B_VAL(p) (((uint8_t *)(p))[0])
114#define R_IDX 2
115#define G_IDX 1
116#define B_IDX 0
117#else
118/* ppc */
119#define A_VAL(p) (((uint8_t *)(p))[0])
120#define R_VAL(p) (((uint8_t *)(p))[1])
121#define G_VAL(p) (((uint8_t *)(p))[2])
122#define B_VAL(p) (((uint8_t *)(p))[3])
123#define R_IDX 1
124#define G_IDX 2
125#define B_IDX 3
126#endif
127 112
128#ifndef DBG 113#ifndef DBG
129# ifdef DEBUG 114# ifdef DEBUG
@@ -158,7 +143,7 @@ _etc2_alpha_block_pack(uint8_t *etc2_alpha,
158 // Compute alphas now 143 // Compute alphas now
159 for (int i = 0; i < 16; i++) 144 for (int i = 0; i < 16; i++)
160 { 145 {
161 const int realA = A_VAL(bgra + kBlockWalk[i]); 146 const int realA = A_VAL(bgra[kBlockWalk[i]]);
162 int minErr = INT_MAX, idx = 0; 147 int minErr = INT_MAX, idx = 0;
163 148
164 // Brute force -- find modifier index 149 // Brute force -- find modifier index
@@ -206,12 +191,12 @@ _etc2_alpha_encode(uint8_t *etc2_alpha, const uint32_t *bgra,
206 int base_codeword; 191 int base_codeword;
207 int multiplier, bestMult = 0; 192 int multiplier, bestMult = 0;
208 int modifierIdx, bestIdx = 0, bestBase = 128; 193 int modifierIdx, bestIdx = 0, bestBase = 128;
209 int err, base_range, base_step = 1, max_error = 0; 194 int err, base_range = 40, base_step = 4, max_error = 0;
210 195
211 // Try to select the best alpha value (avg) 196 // Try to select the best alpha value (avg)
212 for (int i = 0; i < 16; i++) 197 for (int i = 0; i < 16; i++)
213 { 198 {
214 alphas[i] = A_VAL(bgra + kBlockWalk[i]); 199 alphas[i] = A_VAL(bgra[kBlockWalk[i]]);
215 avg += alphas[i]; 200 avg += alphas[i];
216 } 201 }
217 avg /= 16; 202 avg /= 16;
@@ -294,12 +279,12 @@ _etc2_t_mode_header_pack(uint8_t *etc2,
294 uint32_t color1, uint32_t color2, int distance) 279 uint32_t color1, uint32_t color2, int distance)
295{ 280{
296 // 4 bit colors 281 // 4 bit colors
297 int r1_4 = R_VAL(&color1) >> 4; 282 int r1_4 = R_VAL(color1) >> 4;
298 int g1_4 = G_VAL(&color1) >> 4; 283 int g1_4 = G_VAL(color1) >> 4;
299 int b1_4 = B_VAL(&color1) >> 4; 284 int b1_4 = B_VAL(color1) >> 4;
300 int r2_4 = R_VAL(&color2) >> 4; 285 int r2_4 = R_VAL(color2) >> 4;
301 int g2_4 = G_VAL(&color2) >> 4; 286 int g2_4 = G_VAL(color2) >> 4;
302 int b2_4 = B_VAL(&color2) >> 4; 287 int b2_4 = B_VAL(color2) >> 4;
303 int distanceIdx, R, dR; 288 int distanceIdx, R, dR;
304 289
305 for (distanceIdx = 0; distanceIdx < 8; distanceIdx++) 290 for (distanceIdx = 0; distanceIdx < 8; distanceIdx++)
@@ -378,12 +363,12 @@ _etc2_h_mode_header_pack(uint8_t *etc2, Eina_Bool *swap_colors,
378 *swap_colors = (c1 != color1); 363 *swap_colors = (c1 != color1);
379 364
380 // 4 bit colors 365 // 4 bit colors
381 r1_4 = R_VAL(&c1) >> 4; 366 r1_4 = R_VAL(c1) >> 4;
382 g1_4 = G_VAL(&c1) >> 4; 367 g1_4 = G_VAL(c1) >> 4;
383 b1_4 = B_VAL(&c1) >> 4; 368 b1_4 = B_VAL(c1) >> 4;
384 r2_4 = R_VAL(&c2) >> 4; 369 r2_4 = R_VAL(c2) >> 4;
385 g2_4 = G_VAL(&c2) >> 4; 370 g2_4 = G_VAL(c2) >> 4;
386 b2_4 = B_VAL(&c2) >> 4; 371 b2_4 = B_VAL(c2) >> 4;
387 372
388 // R1 + G1a. R + [dR] must be inside [0..31]. Scanning all values. Not smart. 373 // R1 + G1a. R + [dR] must be inside [0..31]. Scanning all values. Not smart.
389 R = r1_4; 374 R = r1_4;
@@ -431,18 +416,18 @@ _etc2_h_mode_header_pack(uint8_t *etc2, Eina_Bool *swap_colors,
431static inline int 416static inline int
432_rgb_distance_percept(uint32_t color1, uint32_t color2) 417_rgb_distance_percept(uint32_t color1, uint32_t color2)
433{ 418{
434 int R = R_VAL(&color1) - R_VAL(&color2); 419 int R = R_VAL(color1) - R_VAL(color2);
435 int G = G_VAL(&color1) - G_VAL(&color2); 420 int G = G_VAL(color1) - G_VAL(color2);
436 int B = B_VAL(&color1) - B_VAL(&color2); 421 int B = B_VAL(color1) - B_VAL(color2);
437 return (R * R * R_WEIGHT) + (G * G * G_WEIGHT) + (B * B * B_WEIGHT); 422 return (R * R * R_WEIGHT) + (G * G * G_WEIGHT) + (B * B * B_WEIGHT);
438} 423}
439 424
440static inline int 425static inline int
441_rgb_distance_euclid(uint32_t color1, uint32_t color2) 426_rgb_distance_euclid(uint32_t color1, uint32_t color2)
442{ 427{
443 int R = R_VAL(&color1) - R_VAL(&color2); 428 int R = R_VAL(color1) - R_VAL(color2);
444 int G = G_VAL(&color1) - G_VAL(&color2); 429 int G = G_VAL(color1) - G_VAL(color2);
445 int B = B_VAL(&color1) - B_VAL(&color2); 430 int B = B_VAL(color1) - B_VAL(color2);
446 return (R * R) + (G * G) + (B * B); 431 return (R * R) + (G * G) + (B * B);
447} 432}
448 433
@@ -452,7 +437,10 @@ _etc2_th_mode_block_pack(uint8_t *etc2, Eina_Bool h_mode,
452 const uint32_t *bgra, Eina_Bool write, 437 const uint32_t *bgra, Eina_Bool write,
453 Eina_Bool *swap_colors) 438 Eina_Bool *swap_colors)
454{ 439{
455 uint8_t paint_colors[4][4]; 440 union {
441 uint8_t c[4];
442 uint32_t v;
443 } paint_colors[4];
456 int errAcc = 0; 444 int errAcc = 0;
457 445
458 if (write) 446 if (write)
@@ -481,17 +469,17 @@ _etc2_th_mode_block_pack(uint8_t *etc2, Eina_Bool h_mode,
481 { 469 {
482 if (!h_mode) 470 if (!h_mode)
483 { 471 {
484 paint_colors[0][k] = ((uint8_t *) &color1)[k]; 472 paint_colors[0].c[k] = ((uint8_t *) &color1)[k];
485 paint_colors[1][k] = CLAMP(((uint8_t *) &color2)[k] + distance); 473 paint_colors[1].c[k] = CLAMP(((uint8_t *) &color2)[k] + distance);
486 paint_colors[2][k] = ((uint8_t *) &color2)[k]; 474 paint_colors[2].c[k] = ((uint8_t *) &color2)[k];
487 paint_colors[3][k] = CLAMP(((uint8_t *) &color2)[k] - distance); 475 paint_colors[3].c[k] = CLAMP(((uint8_t *) &color2)[k] - distance);
488 } 476 }
489 else 477 else
490 { 478 {
491 paint_colors[0][k] = CLAMP(((uint8_t *) &color1)[k] + distance); 479 paint_colors[0].c[k] = CLAMP(((uint8_t *) &color1)[k] + distance);
492 paint_colors[1][k] = CLAMP(((uint8_t *) &color1)[k] - distance); 480 paint_colors[1].c[k] = CLAMP(((uint8_t *) &color1)[k] - distance);
493 paint_colors[2][k] = CLAMP(((uint8_t *) &color2)[k] + distance); 481 paint_colors[2].c[k] = CLAMP(((uint8_t *) &color2)[k] + distance);
494 paint_colors[3][k] = CLAMP(((uint8_t *) &color2)[k] - distance); 482 paint_colors[3].c[k] = CLAMP(((uint8_t *) &color2)[k] - distance);
495 } 483 }
496 } 484 }
497 485
@@ -503,7 +491,7 @@ _etc2_th_mode_block_pack(uint8_t *etc2, Eina_Bool h_mode,
503 491
504 for (int idx = 0; idx < 4; idx++) 492 for (int idx = 0; idx < 4; idx++)
505 { 493 {
506 int dist = _rgb_distance_euclid(pixel, *((uint32_t *) paint_colors[idx])); 494 int dist = _rgb_distance_euclid(pixel, paint_colors[idx].v);
507 if (dist < bestDist) 495 if (dist < bestDist)
508 { 496 {
509 bestDist = dist; 497 bestDist = dist;
@@ -527,9 +515,9 @@ _etc2_th_mode_block_pack(uint8_t *etc2, Eina_Bool h_mode,
527static uint32_t 515static uint32_t
528_color_reduce_444(uint32_t color) 516_color_reduce_444(uint32_t color)
529{ 517{
530 int R = R_VAL(&color); 518 int R = R_VAL(color);
531 int G = G_VAL(&color); 519 int G = G_VAL(color);
532 int B = B_VAL(&color); 520 int B = B_VAL(color);
533 int R1, R2, G1, G2, B1, B2; 521 int R1, R2, G1, G2, B1, B2;
534 522
535 R1 = (R & 0xF0) | (R >> 4); 523 R1 = (R & 0xF0) | (R >> 4);
@@ -549,9 +537,9 @@ _color_reduce_444(uint32_t color)
549static uint32_t 537static uint32_t
550_color_reduce_676(uint32_t color) 538_color_reduce_676(uint32_t color)
551{ 539{
552 int R = R_VAL(&color); 540 int R = R_VAL(color);
553 int G = G_VAL(&color); 541 int G = G_VAL(color);
554 int B = B_VAL(&color); 542 int B = B_VAL(color);
555 int R1, G1, B1; 543 int R1, G1, B1;
556 544
557 // FIXME: Do we have better candidates to try? 545 // FIXME: Do we have better candidates to try?
@@ -628,16 +616,16 @@ _block_main_colors_find(uint32_t *color1_out, uint32_t *color2_out,
628 // k-means update step 616 // k-means update step
629 for (int k = 0; k < cluster1_cnt; k++) 617 for (int k = 0; k < cluster1_cnt; k++)
630 { 618 {
631 r1 += R_VAL(bgra + cluster1[k]); 619 r1 += R_VAL(bgra[cluster1[k]]);
632 g1 += G_VAL(bgra + cluster1[k]); 620 g1 += G_VAL(bgra[cluster1[k]]);
633 b1 += B_VAL(bgra + cluster1[k]); 621 b1 += B_VAL(bgra[cluster1[k]]);
634 } 622 }
635 623
636 for (int k = 0; k < cluster2_cnt; k++) 624 for (int k = 0; k < cluster2_cnt; k++)
637 { 625 {
638 r2 += R_VAL(bgra + cluster2[k]); 626 r2 += R_VAL(bgra[cluster2[k]]);
639 g2 += G_VAL(bgra + cluster2[k]); 627 g2 += G_VAL(bgra[cluster2[k]]);
640 b2 += B_VAL(bgra + cluster2[k]); 628 b2 += B_VAL(bgra[cluster2[k]]);
641 } 629 }
642 630
643 r1 /= cluster1_cnt; 631 r1 /= cluster1_cnt;
@@ -859,15 +847,15 @@ _etc2_planar_mode_block_pack(uint8_t *etc2,
859 unsigned int err = 0; 847 unsigned int err = 0;
860 uint32_t RO, RH, RV, GO, GH, GV, BO, BH, BV; 848 uint32_t RO, RH, RV, GO, GH, GV, BO, BH, BV;
861 849
862 RO = R_VAL(&Ocol); 850 RO = R_VAL(Ocol);
863 RH = R_VAL(&Hcol); 851 RH = R_VAL(Hcol);
864 RV = R_VAL(&Vcol); 852 RV = R_VAL(Vcol);
865 GO = G_VAL(&Ocol); 853 GO = G_VAL(Ocol);
866 GH = G_VAL(&Hcol); 854 GH = G_VAL(Hcol);
867 GV = G_VAL(&Vcol); 855 GV = G_VAL(Vcol);
868 BO = B_VAL(&Ocol); 856 BO = B_VAL(Ocol);
869 BH = B_VAL(&Hcol); 857 BH = B_VAL(Hcol);
870 BV = B_VAL(&Vcol); 858 BV = B_VAL(Vcol);
871 859
872 if (write) 860 if (write)
873 { 861 {
@@ -908,19 +896,19 @@ _etc2_planar_mode_block_encode(uint8_t *etc2, const uint32_t *bgra,
908 * We extrapolate the values from (0,3) and (3,0). 896 * We extrapolate the values from (0,3) and (3,0).
909 */ 897 */
910 898
911 RO = R_VAL(&(bgra[0])); 899 RO = R_VAL((bgra[0]));
912 GO = G_VAL(&(bgra[0])); 900 GO = G_VAL((bgra[0]));
913 BO = B_VAL(&(bgra[0])); 901 BO = B_VAL((bgra[0]));
914 Ocol = _color_reduce_676(bgra[0]); 902 Ocol = _color_reduce_676(bgra[0]);
915 903
916 Rx = CLAMP(RO + (4 * (R_VAL(&(bgra[3])) - RO)) / 3); 904 Rx = CLAMP(RO + (4 * (R_VAL((bgra[3])) - RO)) / 3);
917 Gx = CLAMP(GO + (4 * (G_VAL(&(bgra[3])) - GO)) / 3); 905 Gx = CLAMP(GO + (4 * (G_VAL((bgra[3])) - GO)) / 3);
918 Bx = CLAMP(BO + (4 * (B_VAL(&(bgra[3])) - BO)) / 3); 906 Bx = CLAMP(BO + (4 * (B_VAL((bgra[3])) - BO)) / 3);
919 Hcol = _color_reduce_676(BGRA(Rx, Gx, Bx, 0xFF)); 907 Hcol = _color_reduce_676(BGRA(Rx, Gx, Bx, 0xFF));
920 908
921 Rx = CLAMP(RO + (4 * (R_VAL(&(bgra[12])) - RO)) / 3); 909 Rx = CLAMP(RO + (4 * (R_VAL((bgra[12])) - RO)) / 3);
922 Gx = CLAMP(GO + (4 * (G_VAL(&(bgra[12])) - GO)) / 3); 910 Gx = CLAMP(GO + (4 * (G_VAL((bgra[12])) - GO)) / 3);
923 Bx = CLAMP(BO + (4 * (B_VAL(&(bgra[12])) - BO)) / 3); 911 Bx = CLAMP(BO + (4 * (B_VAL((bgra[12])) - BO)) / 3);
924 Vcol = _color_reduce_676(BGRA(Rx, Gx, Bx, 0xFF)); 912 Vcol = _color_reduce_676(BGRA(Rx, Gx, Bx, 0xFF));
925 913
926 err = _etc2_planar_mode_block_pack(etc2, Ocol, Hcol, Vcol, bgra, EINA_TRUE); 914 err = _etc2_planar_mode_block_pack(etc2, Ocol, Hcol, Vcol, bgra, EINA_TRUE);