summaryrefslogtreecommitdiff
path: root/src/static_libs
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@samsung.com>2014-03-11 19:08:17 +0900
committerCedric BAIL <cedric.bail@free.fr>2014-04-01 22:00:13 +0900
commit4eb983614cf4d251426e2020ff17c3de403fa848 (patch)
treeb03f2cdb4ffc2df64cf7a95a370dbe802bfefa76 /src/static_libs
parentebd318792392ea0bf6093794175b7f191199b6f0 (diff)
rg_etc: fix warning and remove assert.
Diffstat (limited to 'src/static_libs')
-rw-r--r--src/static_libs/rg_etc/rg_etc1.c169
1 files changed, 94 insertions, 75 deletions
diff --git a/src/static_libs/rg_etc/rg_etc1.c b/src/static_libs/rg_etc/rg_etc1.c
index 0550d407d0..af50b6f2a6 100644
--- a/src/static_libs/rg_etc/rg_etc1.c
+++ b/src/static_libs/rg_etc/rg_etc1.c
@@ -12,9 +12,10 @@
12 12
13#include <stdlib.h> 13#include <stdlib.h>
14#include <memory.h> 14#include <memory.h>
15#include <assert.h>
16#include <math.h> 15#include <math.h>
17 16
17#include "Eina.h"
18
18#include "rg_etc1.h" 19#include "rg_etc1.h"
19 20
20#if defined(_DEBUG) || defined(DEBUG) 21#if defined(_DEBUG) || defined(DEBUG)
@@ -28,10 +29,6 @@ typedef unsigned int uint;
28typedef unsigned int uint32; 29typedef unsigned int uint32;
29typedef unsigned char DATA8; 30typedef unsigned char DATA8;
30 31
31#define false 0
32#define true 1
33#define RG_ETC1_ASSERT assert
34
35#define MIN(A, B) ((A < B) ? A : B) 32#define MIN(A, B) ((A < B) ? A : B)
36#define MAX(A, B) ((A > B) ? A : B) 33#define MAX(A, B) ((A > B) ? A : B)
37#define CLAMP(Value, Low, High) ((Value < Low) ? Low : ((Value > High) ? High : Value)) 34#define CLAMP(Value, Low, High) ((Value < Low) ? Low : ((Value > High) ? High : Value))
@@ -126,9 +123,6 @@ enum RG_Etc_Constants
126#define RG_VAL(p) ((DATA16 *)(p)[1]) 123#define RG_VAL(p) ((DATA16 *)(p)[1])
127#endif 124#endif
128 125
129//#define ARGB_JOIN(a,r,g,b) \
130// (((a) << 24) + ((r) << 16) + ((g) << 8) + (b))
131
132#define ARGB_JOIN(a,r,g,b) \ 126#define ARGB_JOIN(a,r,g,b) \
133 (((a) << 24) + ((b) << 16) + ((g) << 8) + (r)) 127 (((a) << 24) + ((b) << 16) + ((g) << 8) + (r))
134static unsigned char rg_etc_quant5_tab[256 + 16]; 128static unsigned char rg_etc_quant5_tab[256 + 16];
@@ -579,7 +573,7 @@ rg_etc1_color_quad_clamp(unsigned int color, unsigned int low, unsigned high)
579 unsigned int i; 573 unsigned int i;
580 574
581 for (i = 0; i < 4; i++) 575 for (i = 0; i < 4; i++)
582 c[i] = clamp(c[i], l[i], h[i]); 576 c[i] = CLAMP(c[i], l[i], h[i]);
583 577
584 return color; 578 return color;
585} 579}
@@ -591,7 +585,7 @@ rg_etc1_color_quad_component_clamp(unsigned int color, unsigned int low, unsigne
591 unsigned int i; 585 unsigned int i;
592 586
593 for (i = 0; i < 4; i++) 587 for (i = 0; i < 4; i++)
594 c[i] = clamp(c[i], low, high); 588 c[i] = CLAMP(c[i], low, high);
595 589
596 return color; 590 return color;
597} 591}
@@ -659,7 +653,7 @@ rg_etc1_color_quad_add(unsigned int color1, unsigned int color2)
659 unsigned short t; 653 unsigned short t;
660 654
661 t = c1[i] + c2[i]; 655 t = c1[i] + c2[i];
662 c1[i] = (unsigned char) (CLAMP(t, 0, 255)); 656 c1[i] = (unsigned char) (MIN(t, 255));
663 } 657 }
664 658
665 return color1; 659 return color1;
@@ -769,7 +763,7 @@ rg_etc1_block_diff_bit_set(unsigned char bytes[8], unsigned char diff)
769static inline void 763static inline void
770rg_etc1_block_clear(unsigned char bytes[8]) 764rg_etc1_block_clear(unsigned char bytes[8])
771{ 765{
772 memset(bytes, 0, sizeof (bytes)); 766 memset(bytes, 0, sizeof (unsigned char) * 8);
773} 767}
774 768
775// Returns intensity modifier table (0-7) used by subblock subblock_id. 769// Returns intensity modifier table (0-7) used by subblock subblock_id.
@@ -778,7 +772,7 @@ static inline unsigned char
778rg_etc1_block_inten_table_get(const unsigned char bytes[8], unsigned char subblock_id) 772rg_etc1_block_inten_table_get(const unsigned char bytes[8], unsigned char subblock_id)
779{ 773{
780 const unsigned char offset = subblock_id ? 2 : 5; 774 const unsigned char offset = subblock_id ? 2 : 5;
781 assert(subblock_id < 2); 775 if (!(subblock_id < 2)) return 0; // ERROR CASE NO ASSERT IN EVAS CODE
782 return (bytes[3] >> offset) & 7; 776 return (bytes[3] >> offset) & 7;
783} 777}
784 778
@@ -787,8 +781,8 @@ static inline void
787rg_etc1_block_inten_table_set(unsigned char bytes[8], unsigned char subblock_id, unsigned char t) 781rg_etc1_block_inten_table_set(unsigned char bytes[8], unsigned char subblock_id, unsigned char t)
788{ 782{
789 const unsigned char offset = subblock_id ? 2 : 5; 783 const unsigned char offset = subblock_id ? 2 : 5;
790 assert(subblock_id < 2); 784 // ERROR CASE NO ASSERT IN EVAS CODE
791 assert(t < 8); 785 if (!(subblock_id < 2) || !(t < 8)) return ;
792 bytes[3] &= ~(7 << offset); 786 bytes[3] &= ~(7 << offset);
793 bytes[3] |= (t << offset); 787 bytes[3] |= (t << offset);
794} 788}
@@ -797,7 +791,8 @@ rg_etc1_block_inten_table_set(unsigned char bytes[8], unsigned char subblock_id,
797static inline unsigned char 791static inline unsigned char
798rg_etc1_block_selector_get(const unsigned char bytes[8], unsigned char x, unsigned char y) 792rg_etc1_block_selector_get(const unsigned char bytes[8], unsigned char x, unsigned char y)
799{ 793{
800 assert((x | y) < 4); 794 // ERROR CASE NO ASSERT IN EVAS CODE
795 if (!((x | y) < 4)) return 0;
801 796
802 const unsigned char bit_index = x * 4 + y; 797 const unsigned char bit_index = x * 4 + y;
803 const unsigned char byte_bit_offset = bit_index & 7; 798 const unsigned char byte_bit_offset = bit_index & 7;
@@ -813,7 +808,8 @@ rg_etc1_block_selector_get(const unsigned char bytes[8], unsigned char x, unsign
813static inline void 808static inline void
814rg_etc1_block_selector_set(unsigned char bytes[8], unsigned char x, unsigned char y, unsigned char val) 809rg_etc1_block_selector_set(unsigned char bytes[8], unsigned char x, unsigned char y, unsigned char val)
815{ 810{
816 assert((x | y) < 4); 811 // ERROR CASE NO ASSERT IN EVAS CODE
812 if (!((x | y) < 4)) return ;
817 813
818 const unsigned char bit_index = x * 4 + y; 814 const unsigned char bit_index = x * 4 + y;
819 815
@@ -968,9 +964,10 @@ rg_etc1_block_color5_unpack(unsigned short packed_color5, unsigned char scaled,
968static inline unsigned int 964static inline unsigned int
969rg_etc1_block_delta3_pack(char r, char g, char b) 965rg_etc1_block_delta3_pack(char r, char g, char b)
970{ 966{
971 assert((r >= cETC1ColorDeltaMin) && (r <= cETC1ColorDeltaMax)); 967 // ERROR CASE NO ASSERT IN EVAS CODE
972 assert((g >= cETC1ColorDeltaMin) && (g <= cETC1ColorDeltaMax)); 968 if (!((r >= cETC1ColorDeltaMin) && (r <= cETC1ColorDeltaMax))) return 0;
973 assert((b >= cETC1ColorDeltaMin) && (b <= cETC1ColorDeltaMax)); 969 if (!((g >= cETC1ColorDeltaMin) && (g <= cETC1ColorDeltaMax))) return 0;
970 if (!((b >= cETC1ColorDeltaMin) && (b <= cETC1ColorDeltaMax))) return 0;
974 971
975 if (r < 0) r += 8; 972 if (r < 0) r += 8;
976 if (g < 0) g += 8; 973 if (g < 0) g += 8;
@@ -1042,7 +1039,7 @@ rg_etc1_block_color4_unpack(unsigned short packed_color4, unsigned char scaled,
1042 1039
1043 rg_etc1_block_color4_component_unpack(&r, &g, &b, packed_color4, scaled); 1040 rg_etc1_block_color4_component_unpack(&r, &g, &b, packed_color4, scaled);
1044 1041
1045 return rg_etc1_color_quad_init(r, g, b, 255); 1042 return rg_etc1_color_quad_init(r, g, b, alpha);
1046} 1043}
1047 1044
1048 1045
@@ -1062,9 +1059,9 @@ rg_etc1_block_color5_delta3_component_unpack(unsigned char *r, unsigned char *g,
1062 if ((*r | *g | *b) > 31) 1059 if ((*r | *g | *b) > 31)
1063 { 1060 {
1064 success = 0; 1061 success = 0;
1065 *r = CLAMP(*r, 0, 31); 1062 *r = MIN(*r, 31);
1066 *g = CLAMP(*g, 0, 31); 1063 *g = MIN(*g, 31);
1067 *b = CLAMP(*b, 0, 31); 1064 *b = MIN(*b, 31);
1068 } 1065 }
1069 1066
1070 if (scaled) 1067 if (scaled)
@@ -1115,7 +1112,8 @@ rg_etc1_block_subblock_color5_diff_get(unsigned int dst[4], unsigned short packe
1115 const int *pInten_modifer_table; 1112 const int *pInten_modifer_table;
1116 unsigned char r, g, b; 1113 unsigned char r, g, b;
1117 1114
1118 assert(table_idx < cETC1IntenModifierValues); 1115 // ERROR CASE NO ASSERT IN EVAS CODE
1116 if (!(table_idx < cETC1IntenModifierValues)) return ;
1119 1117
1120 rg_etc1_block_color5_component_unpack(&r, &g, &b, packed_color5, 1); 1118 rg_etc1_block_color5_component_unpack(&r, &g, &b, packed_color5, 1);
1121 1119
@@ -1132,7 +1130,12 @@ rg_etc1_block_subblock_color5_delta3_diff_get(unsigned int dst[4],
1132 unsigned char r, g, b; 1130 unsigned char r, g, b;
1133 unsigned char success; 1131 unsigned char success;
1134 1132
1135 assert(table_idx < cETC1IntenModifierValues); 1133 // ERROR CASE NO ASSERT IN EVAS CODE
1134 if (!(table_idx < cETC1IntenModifierValues))
1135 {
1136 fprintf(stderr, "table_idx %i < %i\n", table_idx, cETC1IntenModifierValues);
1137 return 0;
1138 }
1136 1139
1137 success = rg_etc1_block_color5_delta3_component_unpack(&r, &g, &b, packed_color5, packed_delta3, 1); 1140 success = rg_etc1_block_color5_delta3_component_unpack(&r, &g, &b, packed_color5, packed_delta3, 1);
1138 1141
@@ -1148,7 +1151,8 @@ rg_etc1_block_subblock_color4_abs_get(unsigned int dst[4], unsigned short packed
1148 const int *pInten_modifer_table; 1151 const int *pInten_modifer_table;
1149 unsigned char r, g, b; 1152 unsigned char r, g, b;
1150 1153
1151 assert(table_idx < cETC1IntenModifierValues); 1154 // ERROR CASE NO ASSERT IN EVAS CODE
1155 if (!(table_idx < cETC1IntenModifierValues)) return ;
1152 1156
1153 rg_etc1_block_color4_component_unpack(&r, &g, &b, packed_color4, 1); 1157 rg_etc1_block_color4_component_unpack(&r, &g, &b, packed_color4, 1);
1154 1158
@@ -1161,8 +1165,8 @@ bool
1161rg_etc1_unpack_block(const void *ETC1_block, unsigned int *pixels, bool preserve_alpha) 1165rg_etc1_unpack_block(const void *ETC1_block, unsigned int *pixels, bool preserve_alpha)
1162{ 1166{
1163 unsigned char diff_flag, flip_flag, table_index0, table_index1; 1167 unsigned char diff_flag, flip_flag, table_index0, table_index1;
1164 unsigned int subblock_colors0[4]; 1168 unsigned int subblock_colors0[4] = { 0 };
1165 unsigned int subblock_colors1[4]; 1169 unsigned int subblock_colors1[4] = { 0 };
1166 unsigned char x, y; 1170 unsigned char x, y;
1167 unsigned char success = 1; 1171 unsigned char success = 1;
1168 1172
@@ -1262,8 +1266,9 @@ rg_etc1_indirect_radix_sort(unsigned int num_indices, unsigned int pIndices0[8],
1262 unsigned int key; 1266 unsigned int key;
1263 unsigned int pass; 1267 unsigned int pass;
1264 1268
1265 assert((key_ofs >= 0) && (key_ofs < sizeof(pIndices0))); 1269 // ERROR CASE NO ASSERT IN EVAS CODE
1266 assert((key_size >= 1) && (key_size <= 4)); 1270 if (!(key_ofs < sizeof(pIndices0))) return NULL;
1271 if (!((key_size >= 1) && (key_size <= 4))) return NULL;
1267 1272
1268 if (init_indices) 1273 if (init_indices)
1269 { 1274 {
@@ -1455,7 +1460,7 @@ static inline void
1455rg_etc1_pack_params_clear(rg_etc1_pack_params *params) 1460rg_etc1_pack_params_clear(rg_etc1_pack_params *params)
1456{ 1461{
1457 params->m_quality = rg_etc1_high_quality; 1462 params->m_quality = rg_etc1_high_quality;
1458 params->m_dithering = false; 1463 params->m_dithering = EINA_FALSE;
1459} 1464}
1460 1465
1461static const int rg_etc1_default_scan_delta[] = { 0 }; 1466static const int rg_etc1_default_scan_delta[] = { 0 };
@@ -1481,12 +1486,12 @@ rg_etc1_optimizer_params_clean(rg_etc1_optimizer_params *params)
1481 params->m_num_src_pixels = 0; 1486 params->m_num_src_pixels = 0;
1482 params->m_pSrc_pixels = 0; 1487 params->m_pSrc_pixels = 0;
1483 1488
1484 params->m_use_color4 = false; 1489 params->m_use_color4 = EINA_FALSE;
1485 params->m_pScan_deltas = rg_etc1_default_scan_delta; 1490 params->m_pScan_deltas = rg_etc1_default_scan_delta;
1486 params->m_scan_delta_size = 1; 1491 params->m_scan_delta_size = 1;
1487 1492
1488 rg_etc1_color_quad_u8_clear(&params->m_base_color5); 1493 rg_etc1_color_quad_u8_clear(&params->m_base_color5);
1489 params->m_constrain_against_base_color5 = false; 1494 params->m_constrain_against_base_color5 = EINA_FALSE;
1490} 1495}
1491 1496
1492static inline void 1497static inline void
@@ -1513,7 +1518,8 @@ rg_etc1_optimizer_results_duplicate(rg_etc1_optimizer_results *dst, const rg_etc
1513 dst->m_block_color4 = src->m_block_color4; 1518 dst->m_block_color4 = src->m_block_color4;
1514 dst->m_block_inten_table = src->m_block_inten_table; 1519 dst->m_block_inten_table = src->m_block_inten_table;
1515 dst->m_error = src->m_error; 1520 dst->m_error = src->m_error;
1516 RG_ETC1_ASSERT(dst->m_n == src->m_n); 1521 // ERROR CASE NO ASSERT IN EVAS CODE
1522 if (!(dst->m_n == src->m_n)) return ;
1517 memcpy(dst->m_pSelectors, src->m_pSelectors, src->m_n); 1523 memcpy(dst->m_pSelectors, src->m_pSelectors, src->m_n);
1518} 1524}
1519 1525
@@ -1530,7 +1536,7 @@ rg_etc1_potential_solution_clear(rg_etc1_potential_solution *solution)
1530{ 1536{
1531 rg_etc1_solution_coordinates_clear(&solution->m_coords); 1537 rg_etc1_solution_coordinates_clear(&solution->m_coords);
1532 solution->m_error = cUINT64_MAX; 1538 solution->m_error = cUINT64_MAX;
1533 solution->m_valid = false; 1539 solution->m_valid = EINA_FALSE;
1534} 1540}
1535 1541
1536typedef struct 1542typedef struct
@@ -1672,16 +1678,16 @@ rg_etc1_optimizer_compute(rg_etc1_optimizer *optimizer)
1672 0, optimizer->m_limit); 1678 0, optimizer->m_limit);
1673 bb1 = (uint)CLAMP(((optimizer->m_avg_color[2] - avg_delta_b_f) * optimizer->m_limit / 255.0f + .5f), 1679 bb1 = (uint)CLAMP(((optimizer->m_avg_color[2] - avg_delta_b_f) * optimizer->m_limit / 255.0f + .5f),
1674 0, optimizer->m_limit); 1680 0, optimizer->m_limit);
1675 skip = false; 1681 skip = EINA_FALSE;
1676 1682
1677 if ((mbr == br1) && (mbg == bg1) && (mbb == bb1)) { 1683 if ((mbr == br1) && (mbg == bg1) && (mbb == bb1)) {
1678 skip = true; 1684 skip = EINA_TRUE;
1679 } else if ((br1 == optimizer->m_best_solution.m_coords.m_unscaled_color.comp.r) && 1685 } else if ((br1 == optimizer->m_best_solution.m_coords.m_unscaled_color.comp.r) &&
1680 (bg1 == optimizer->m_best_solution.m_coords.m_unscaled_color.comp.g) && 1686 (bg1 == optimizer->m_best_solution.m_coords.m_unscaled_color.comp.g) &&
1681 (bb1 == optimizer->m_best_solution.m_coords.m_unscaled_color.comp.b)) { 1687 (bb1 == optimizer->m_best_solution.m_coords.m_unscaled_color.comp.b)) {
1682 skip = true; 1688 skip = EINA_TRUE;
1683 } else if ((optimizer->m_br == br1) && (optimizer->m_bg == bg1) && (optimizer->m_bb == bb1)) { 1689 } else if ((optimizer->m_br == br1) && (optimizer->m_bg == bg1) && (optimizer->m_bb == bb1)) {
1684 skip = true; 1690 skip = EINA_TRUE;
1685 } 1691 }
1686 1692
1687 if (skip) 1693 if (skip)
@@ -1708,7 +1714,7 @@ rg_etc1_optimizer_compute(rg_etc1_optimizer *optimizer)
1708 if (!optimizer->m_best_solution.m_valid) 1714 if (!optimizer->m_best_solution.m_valid)
1709 { 1715 {
1710 optimizer->m_pResult->m_error = cUINT32_MAX; 1716 optimizer->m_pResult->m_error = cUINT32_MAX;
1711 return false; 1717 return EINA_FALSE;
1712 } 1718 }
1713 1719
1714#ifdef RG_ETC1_BUILD_DEBUG 1720#ifdef RG_ETC1_BUILD_DEBUG
@@ -1724,7 +1730,9 @@ rg_etc1_optimizer_compute(rg_etc1_optimizer *optimizer)
1724 for (i = 0; i < n; i++) 1730 for (i = 0; i < n; i++)
1725 actual_error += rg_etc1_color_quad_u8_rgb_squared_distance(pSrc_pixels[i], block_colors[pSelectors[i]]); 1731 actual_error += rg_etc1_color_quad_u8_rgb_squared_distance(pSrc_pixels[i], block_colors[pSelectors[i]]);
1726 1732
1727 RG_ETC1_ASSERT(actual_error == optimizer->m_best_solution.m_error); 1733 // ERROR CASE NO ASSERT IN EVAS CODE
1734 if (actual_error != optimizer->m_best_solution.m_error)
1735 return EINA_FALSE;
1728 } 1736 }
1729#endif 1737#endif
1730 1738
@@ -1735,7 +1743,7 @@ rg_etc1_optimizer_compute(rg_etc1_optimizer *optimizer)
1735 memcpy(optimizer->m_pResult->m_pSelectors, optimizer->m_best_solution.m_selectors, n); 1743 memcpy(optimizer->m_pResult->m_pSelectors, optimizer->m_best_solution.m_selectors, n);
1736 optimizer->m_pResult->m_n = n; 1744 optimizer->m_pResult->m_n = n;
1737 1745
1738 return true; 1746 return EINA_TRUE;
1739} 1747}
1740 1748
1741void 1749void
@@ -1743,7 +1751,8 @@ rg_etc1_optimizer_init(rg_etc1_optimizer *optimizer, const rg_etc1_optimizer_par
1743 rg_etc1_optimizer_results *result) 1751 rg_etc1_optimizer_results *result)
1744{ 1752{
1745 // This version is hardcoded for 8 pixel subblocks. 1753 // This version is hardcoded for 8 pixel subblocks.
1746 RG_ETC1_ASSERT(params->m_num_src_pixels == 8); 1754 // ERROR CASE NO ASSERT IN EVAS CODE
1755 if (params->m_num_src_pixels != 8) return ;
1747 1756
1748 const uint n = 8; 1757 const uint n = 8;
1749 uint i; 1758 uint i;
@@ -1769,15 +1778,15 @@ rg_etc1_optimizer_init(rg_etc1_optimizer *optimizer, const rg_etc1_optimizer_par
1769 rg_etc1_vec_scale(avg_color, (1.0f/(float)(n))); 1778 rg_etc1_vec_scale(avg_color, (1.0f/(float)(n)));
1770 rg_etc1_vec_copy(optimizer->m_avg_color,avg_color); 1779 rg_etc1_vec_copy(optimizer->m_avg_color,avg_color);
1771 1780
1772 optimizer->m_br = CLAMP((uint)(optimizer->m_avg_color[0] * optimizer->m_limit / 255.0f + .5f), 0, optimizer->m_limit); 1781 optimizer->m_br = MIN((int)(optimizer->m_avg_color[0] * optimizer->m_limit / 255.0f + .5f), optimizer->m_limit);
1773 optimizer->m_bg = CLAMP((uint)(optimizer->m_avg_color[1] * optimizer->m_limit / 255.0f + .5f), 0, optimizer->m_limit); 1782 optimizer->m_bg = MIN((int)(optimizer->m_avg_color[1] * optimizer->m_limit / 255.0f + .5f), optimizer->m_limit);
1774 optimizer->m_bb = CLAMP((uint)(optimizer->m_avg_color[2] * optimizer->m_limit / 255.0f + .5f), 0, optimizer->m_limit); 1783 optimizer->m_bb = MIN((int)(optimizer->m_avg_color[2] * optimizer->m_limit / 255.0f + .5f), optimizer->m_limit);
1775 1784
1776 if (optimizer->m_pParams->base_params->m_quality <= rg_etc1_medium_quality) 1785 if (optimizer->m_pParams->base_params->m_quality <= rg_etc1_medium_quality)
1777 { 1786 {
1778 optimizer->m_pSorted_luma_indices = rg_etc1_indirect_radix_sort(n, optimizer->m_sorted_luma[0], 1787 optimizer->m_pSorted_luma_indices = rg_etc1_indirect_radix_sort(n, optimizer->m_sorted_luma[0],
1779 optimizer->m_sorted_luma[1], optimizer->m_luma, 1788 optimizer->m_sorted_luma[1], optimizer->m_luma,
1780 0, sizeof(optimizer->m_luma[0]), false); 1789 0, sizeof(optimizer->m_luma[0]), EINA_FALSE);
1781 optimizer->m_pSorted_luma = optimizer->m_sorted_luma[0]; 1790 optimizer->m_pSorted_luma = optimizer->m_sorted_luma[0];
1782 1791
1783 if (optimizer->m_pSorted_luma_indices == optimizer->m_sorted_luma[0]) 1792 if (optimizer->m_pSorted_luma_indices == optimizer->m_sorted_luma[0])
@@ -1788,7 +1797,7 @@ rg_etc1_optimizer_init(rg_etc1_optimizer *optimizer, const rg_etc1_optimizer_par
1788 } 1797 }
1789 1798
1790 rg_etc1_solution_coordinates_clear(&optimizer->m_best_solution.m_coords); 1799 rg_etc1_solution_coordinates_clear(&optimizer->m_best_solution.m_coords);
1791 optimizer->m_best_solution.m_valid = false; 1800 optimizer->m_best_solution.m_valid = EINA_FALSE;
1792 optimizer->m_best_solution.m_error = cUINT64_MAX; 1801 optimizer->m_best_solution.m_error = cUINT64_MAX;
1793} 1802}
1794 1803
@@ -1799,9 +1808,9 @@ rg_etc1_optimizer_evaluate_solution(rg_etc1_optimizer *optimizer, const Etc1_Sol
1799 color_quad_u8 base_color; 1808 color_quad_u8 base_color;
1800 const uint n = 8; 1809 const uint n = 8;
1801 uint inten_table; 1810 uint inten_table;
1802 bool success = false; 1811 bool success = EINA_FALSE;
1803 1812
1804 trial_solution->m_valid = false; 1813 trial_solution->m_valid = EINA_FALSE;
1805 1814
1806 if (optimizer->m_pParams->m_constrain_against_base_color5) 1815 if (optimizer->m_pParams->m_constrain_against_base_color5)
1807 { 1816 {
@@ -1811,7 +1820,7 @@ rg_etc1_optimizer_evaluate_solution(rg_etc1_optimizer *optimizer, const Etc1_Sol
1811 db = coords->m_unscaled_color.comp.b - optimizer->m_pParams->m_base_color5.comp.b; 1820 db = coords->m_unscaled_color.comp.b - optimizer->m_pParams->m_base_color5.comp.b;
1812 1821
1813 if ((MIN(MIN(dr,dg),db) < cETC1ColorDeltaMin) || (MAX(MAX(dr,dg),db) > cETC1ColorDeltaMax)) 1822 if ((MIN(MIN(dr,dg),db) < cETC1ColorDeltaMin) || (MAX(MAX(dr,dg),db) > cETC1ColorDeltaMax))
1814 return false; 1823 return EINA_FALSE;
1815 } 1824 }
1816 1825
1817 rg_etc1_solution_coordinates_get_scaled_color(&base_color, coords); 1826 rg_etc1_solution_coordinates_get_scaled_color(&base_color, coords);
@@ -1878,7 +1887,7 @@ rg_etc1_optimizer_evaluate_solution(rg_etc1_optimizer *optimizer, const Etc1_Sol
1878 trial_solution->m_error = total_error; 1887 trial_solution->m_error = total_error;
1879 trial_solution->m_coords.m_inten_table = inten_table; 1888 trial_solution->m_coords.m_inten_table = inten_table;
1880 memcpy(trial_solution->m_selectors, optimizer->m_temp_selectors, 8); 1889 memcpy(trial_solution->m_selectors, optimizer->m_temp_selectors, 8);
1881 trial_solution->m_valid = true; 1890 trial_solution->m_valid = EINA_TRUE;
1882 } 1891 }
1883 } 1892 }
1884 rg_etc1_color_quad_u8_copy(&trial_solution->m_coords.m_unscaled_color,&coords->m_unscaled_color); 1893 rg_etc1_color_quad_u8_copy(&trial_solution->m_coords.m_unscaled_color,&coords->m_unscaled_color);
@@ -1889,7 +1898,7 @@ rg_etc1_optimizer_evaluate_solution(rg_etc1_optimizer *optimizer, const Etc1_Sol
1889 if (trial_solution->m_error < pBest_solution->m_error) 1898 if (trial_solution->m_error < pBest_solution->m_error)
1890 { 1899 {
1891 memcpy(pBest_solution,trial_solution,sizeof(rg_etc1_potential_solution)); 1900 memcpy(pBest_solution,trial_solution,sizeof(rg_etc1_potential_solution));
1892 success = true; 1901 success = EINA_TRUE;
1893 } 1902 }
1894 } 1903 }
1895 1904
@@ -1903,7 +1912,7 @@ rg_etc1_optimizer_evaluate_solution_fast(rg_etc1_optimizer *optimizer, const Etc
1903 color_quad_u8 base_color; 1912 color_quad_u8 base_color;
1904 const uint n = 8; 1913 const uint n = 8;
1905 int inten_table; 1914 int inten_table;
1906 bool success = false; 1915 bool success = EINA_FALSE;
1907 1916
1908 if (optimizer->m_pParams->m_constrain_against_base_color5) 1917 if (optimizer->m_pParams->m_constrain_against_base_color5)
1909 { 1918 {
@@ -1915,8 +1924,8 @@ rg_etc1_optimizer_evaluate_solution_fast(rg_etc1_optimizer *optimizer, const Etc
1915 1924
1916 if ((MIN(MIN(dr,dg),db) < cETC1ColorDeltaMin) || (MAX(MAX(dr,dg),db) > cETC1ColorDeltaMax)) 1925 if ((MIN(MIN(dr,dg),db) < cETC1ColorDeltaMin) || (MAX(MAX(dr,dg),db) > cETC1ColorDeltaMax))
1917 { 1926 {
1918 trial_solution->m_valid = false; 1927 trial_solution->m_valid = EINA_FALSE;
1919 return false; 1928 return EINA_FALSE;
1920 } 1929 }
1921 } 1930 }
1922 1931
@@ -2007,7 +2016,7 @@ rg_etc1_optimizer_evaluate_solution_fast(rg_etc1_optimizer *optimizer, const Etc
2007 trial_solution->m_error = total_error; 2016 trial_solution->m_error = total_error;
2008 trial_solution->m_coords.m_inten_table = inten_table; 2017 trial_solution->m_coords.m_inten_table = inten_table;
2009 memcpy(trial_solution->m_selectors, optimizer->m_temp_selectors, n); 2018 memcpy(trial_solution->m_selectors, optimizer->m_temp_selectors, n);
2010 trial_solution->m_valid = true; 2019 trial_solution->m_valid = EINA_TRUE;
2011 if (!total_error) 2020 if (!total_error)
2012 break; 2021 break;
2013 } 2022 }
@@ -2020,7 +2029,7 @@ rg_etc1_optimizer_evaluate_solution_fast(rg_etc1_optimizer *optimizer, const Etc
2020 if (trial_solution->m_error < pBest_solution->m_error) 2029 if (trial_solution->m_error < pBest_solution->m_error)
2021 { 2030 {
2022 memcpy(pBest_solution,trial_solution,sizeof(rg_etc1_potential_solution)); 2031 memcpy(pBest_solution,trial_solution,sizeof(rg_etc1_potential_solution));
2023 success = true; 2032 success = EINA_TRUE;
2024 } 2033 }
2025 } 2034 }
2026 2035
@@ -2031,7 +2040,9 @@ static uint
2031etc1_decode_value(uint diff, uint inten, uint selector, uint packed_c) 2040etc1_decode_value(uint diff, uint inten, uint selector, uint packed_c)
2032{ 2041{
2033 const uint limit = diff ? 32 : 16; 2042 const uint limit = diff ? 32 : 16;
2034 RG_ETC1_ASSERT((diff < 2) && (inten < 8) && (selector < 4) && (packed_c < limit)); 2043 // ERROR CASE NO ASSERT IN EVAS CODE
2044 if (!((diff < 2) && (inten < 8) && (selector < 4) && (packed_c < limit)))
2045 return 0;
2035 int c; 2046 int c;
2036 if (diff) 2047 if (diff)
2037 c = (packed_c >> 2) | (packed_c << 3); 2048 c = (packed_c >> 2) | (packed_c << 3);
@@ -2077,7 +2088,8 @@ void rg_etc1_pack_block_init()
2077 break; 2088 break;
2078 } 2089 }
2079 } 2090 }
2080 RG_ETC1_ASSERT(best_error <= 255); 2091 // ERROR CASE NO ASSERT IN EVAS CODE
2092 if (!(best_error <= 255)) return ;
2081 rg_etc1_inverse_lookup[inverse_table_index][color] = (uint16)(best_packed_c | (best_error << 8)); 2093 rg_etc1_inverse_lookup[inverse_table_index][color] = (uint16)(best_packed_c | (best_error << 8));
2082 } 2094 }
2083 } 2095 }
@@ -2097,9 +2109,10 @@ void rg_etc1_pack_block_init()
2097// Packs solid color blocks efficiently using a set of small precomputed tables. 2109// Packs solid color blocks efficiently using a set of small precomputed tables.
2098// For random 888 inputs, MSE results are better than Erricson's ETC1 packer in "slow" mode ~9.5% of the time, is slightly worse only ~.01% of the time, and is equal the rest of the time. 2110// For random 888 inputs, MSE results are better than Erricson's ETC1 packer in "slow" mode ~9.5% of the time, is slightly worse only ~.01% of the time, and is equal the rest of the time.
2099static uint64 2111static uint64
2100rg_etc1_pack_block_solid_color(unsigned char *block, const uint8* pColor, rg_etc1_pack_params *pack_params) 2112rg_etc1_pack_block_solid_color(unsigned char *block, const uint8* pColor, rg_etc1_pack_params *pack_params EINA_UNUSED)
2101{ 2113{
2102 RG_ETC1_ASSERT(rg_etc1_inverse_lookup[0][255]); 2114 // ERROR CASE NO ASSERT IN EVAS CODE
2115 if (!rg_etc1_inverse_lookup[0][255]) return 0;
2103 2116
2104 static uint s_next_comp[4] = { 1, 2, 0, 1 }; 2117 static uint s_next_comp[4] = { 1, 2, 0, 1 };
2105 2118
@@ -2139,7 +2152,8 @@ rg_etc1_pack_block_solid_color(unsigned char *block, const uint8* pColor, rg_etc
2139 const uint inten = (x >> 1) & 7; 2152 const uint inten = (x >> 1) & 7;
2140 const uint selector = (x >> 4) & 3; 2153 const uint selector = (x >> 4) & 3;
2141 const uint p0 = (x >> 8) & 255; 2154 const uint p0 = (x >> 8) & 255;
2142 RG_ETC1_ASSERT(etc1_decode_value(diff, inten, selector, p0) == (uint)c_plus_delta); 2155 // ERROR CASE NO ASSERT IN EVAS CODE
2156 if (etc1_decode_value(diff, inten, selector, p0) != (uint)c_plus_delta) return 0;
2143#endif 2157#endif
2144 2158
2145 pInverse_table = rg_etc1_inverse_lookup[x & 0xFF]; 2159 pInverse_table = rg_etc1_inverse_lookup[x & 0xFF];
@@ -2194,15 +2208,17 @@ rg_etc1_pack_block_solid_color(unsigned char *block, const uint8* pColor, rg_etc
2194 2208
2195static uint 2209static uint
2196rg_etc1_pack_block_solid_color_constrained(rg_etc1_optimizer_results *results,uint num_colors, 2210rg_etc1_pack_block_solid_color_constrained(rg_etc1_optimizer_results *results,uint num_colors,
2197 const uint8* pColor, rg_etc1_pack_params *pack_params, 2211 const uint8* pColor, rg_etc1_pack_params *pack_params EINA_UNUSED,
2198 bool use_diff, const color_quad_u8* pBase_color5_unscaled) 2212 bool use_diff, const color_quad_u8* pBase_color5_unscaled)
2199{ 2213{
2200 RG_ETC1_ASSERT(rg_etc1_inverse_lookup[0][255]);
2201 static uint s_next_comp[4] = { 1, 2, 0, 1 }; 2214 static uint s_next_comp[4] = { 1, 2, 0, 1 };
2202 uint best_error = cUINT32_MAX, best_i = 0; 2215 uint best_error = cUINT32_MAX, best_i = 0;
2203 int best_x = 0, best_packed_c1 = 0, best_packed_c2 = 0; 2216 int best_x = 0, best_packed_c1 = 0, best_packed_c2 = 0;
2204 uint i; 2217 uint i;
2205 2218
2219 // ERROR CASE NO ASSERT IN EVAS CODE
2220 if (!rg_etc1_inverse_lookup[0][255]) return 0;
2221
2206 // For each possible 8-bit value, there is a precomputed list of diff/inten/selector configurations 2222 // For each possible 8-bit value, there is a precomputed list of diff/inten/selector configurations
2207 // that allow that 8-bit value to be encoded with no error. 2223 // that allow that 8-bit value to be encoded with no error.
2208 for (i = 0; i < 3; i++) 2224 for (i = 0; i < 3; i++)
@@ -2251,7 +2267,8 @@ rg_etc1_pack_block_solid_color_constrained(rg_etc1_optimizer_results *results,ui
2251 const uint inten = (x >> 1) & 7; 2267 const uint inten = (x >> 1) & 7;
2252 const uint selector = (x >> 4) & 3; 2268 const uint selector = (x >> 4) & 3;
2253 const uint p0 = (x >> 8) & 255; 2269 const uint p0 = (x >> 8) & 255;
2254 RG_ETC1_ASSERT(etc1_decode_value(diff, inten, selector, p0) == (uint)c_plus_delta); 2270 // ERROR CASE NO ASSERT IN EVAS CODE
2271 if (etc1_decode_value(diff, inten, selector, p0) != (uint)c_plus_delta) return 0;
2255 } 2272 }
2256#endif 2273#endif
2257 2274
@@ -2368,11 +2385,11 @@ rg_etc1_pack_block(void* pETC1_block, const unsigned int* pSrc_pixels_rgba, rg_e
2368 int r; 2385 int r;
2369 color_quad_u8 dithered_pixels[16], subblock_pixels[8]; 2386 color_quad_u8 dithered_pixels[16], subblock_pixels[8];
2370 uint64 best_error = cUINT64_MAX; 2387 uint64 best_error = cUINT64_MAX;
2371 uint best_use_color4=false; 2388 uint best_use_color4=EINA_FALSE;
2372 uint best_flip=false; 2389 uint best_flip=EINA_FALSE;
2373 uint8 best_selectors[2][8]; 2390 uint8 best_selectors[2][8];
2374 rg_etc1_optimizer optimizer; 2391 rg_etc1_optimizer optimizer;
2375 rg_etc1_optimizer_results best_results[2]; 2392 rg_etc1_optimizer_results best_results[2] = { { 0 } };
2376 rg_etc1_optimizer_results results[3]; 2393 rg_etc1_optimizer_results results[3];
2377 rg_etc1_optimizer_params params; 2394 rg_etc1_optimizer_params params;
2378 uint i, flip; 2395 uint i, flip;
@@ -2382,13 +2399,14 @@ rg_etc1_pack_block(void* pETC1_block, const unsigned int* pSrc_pixels_rgba, rg_e
2382 static const int s_scan_delta_0_to_4[] = { -4, -3, -2, -1, 0, 1, 2, 3, 4 }; 2399 static const int s_scan_delta_0_to_4[] = { -4, -3, -2, -1, 0, 1, 2, 3, 4 };
2383 static const int s_scan_delta_0_to_1[] = { -1, 0, 1 }; 2400 static const int s_scan_delta_0_to_1[] = { -1, 0, 1 };
2384 static const int s_scan_delta_0[] = { 0 }; 2401 static const int s_scan_delta_0[] = { 0 };
2385 first_pixel_u32= pSrc_pixels->m_u32; 2402 first_pixel_u32 = *pSrc_pixels_rgba;
2386 2403
2387#ifdef RG_ETC1_BUILD_DEBUG 2404#ifdef RG_ETC1_BUILD_DEBUG
2388 // Ensure all alpha values are 0xFF. 2405 // Ensure all alpha values are 0xFF.
2389 for (i = 0; i < 16; i++) 2406 for (i = 0; i < 16; i++)
2390 { 2407 {
2391 RG_ETC1_ASSERT(pSrc_pixels[i].comp.a == 255); 2408 // ERROR CASE NO ASSERT IN EVAS CODE
2409 if (pSrc_pixels[i].comp.a != 255) return 0;
2392 } 2410 }
2393#endif 2411#endif
2394 rg_etc1_optimizer_clear(&optimizer); 2412 rg_etc1_optimizer_clear(&optimizer);
@@ -2463,11 +2481,11 @@ rg_etc1_pack_block(void* pETC1_block, const unsigned int* pSrc_pixels_rgba, rg_e
2463 } 2481 }
2464 2482
2465 params.m_use_color4 = (use_color4 != 0); 2483 params.m_use_color4 = (use_color4 != 0);
2466 params.m_constrain_against_base_color5 = false; 2484 params.m_constrain_against_base_color5 = EINA_FALSE;
2467 2485
2468 if ((!use_color4) && (subblock)) 2486 if ((!use_color4) && (subblock))
2469 { 2487 {
2470 params.m_constrain_against_base_color5 = true; 2488 params.m_constrain_against_base_color5 = EINA_TRUE;
2471 rg_etc1_color_quad_u8_copy(&params.m_base_color5,&results[0].m_block_color_unscaled); 2489 rg_etc1_color_quad_u8_copy(&params.m_base_color5,&results[0].m_block_color_unscaled);
2472 } 2490 }
2473 2491
@@ -2547,7 +2565,8 @@ rg_etc1_pack_block(void* pETC1_block, const unsigned int* pSrc_pixels_rgba, rg_e
2547 dr = best_results[1].m_block_color_unscaled.comp.r - best_results[0].m_block_color_unscaled.comp.r; 2565 dr = best_results[1].m_block_color_unscaled.comp.r - best_results[0].m_block_color_unscaled.comp.r;
2548 dg = best_results[1].m_block_color_unscaled.comp.g - best_results[0].m_block_color_unscaled.comp.g; 2566 dg = best_results[1].m_block_color_unscaled.comp.g - best_results[0].m_block_color_unscaled.comp.g;
2549 db = best_results[1].m_block_color_unscaled.comp.b - best_results[0].m_block_color_unscaled.comp.b; 2567 db = best_results[1].m_block_color_unscaled.comp.b - best_results[0].m_block_color_unscaled.comp.b;
2550 RG_ETC1_ASSERT(best_use_color4 || (MIN(MIN(dr, dg), db) >= cETC1ColorDeltaMin) && (MAX(MAX(dr, dg), db) <= cETC1ColorDeltaMax)); 2568 // ERROR CASE NO ASSERT IN EVAS CODE
2569 if (!(best_use_color4 || ((MIN(MIN(dr, dg), db) >= cETC1ColorDeltaMin) && (MAX(MAX(dr, dg), db) <= cETC1ColorDeltaMax)))) return 0;
2551 2570
2552 if (best_use_color4) 2571 if (best_use_color4)
2553 { 2572 {