summaryrefslogtreecommitdiff
path: root/src/static_libs
diff options
context:
space:
mode:
Diffstat (limited to 'src/static_libs')
-rw-r--r--src/static_libs/rg_etc/etc2_encoder.c37
1 files changed, 22 insertions, 15 deletions
diff --git a/src/static_libs/rg_etc/etc2_encoder.c b/src/static_libs/rg_etc/etc2_encoder.c
index 6ac84e8..874904f 100644
--- a/src/static_libs/rg_etc/etc2_encoder.c
+++ b/src/static_libs/rg_etc/etc2_encoder.c
@@ -198,10 +198,10 @@ static int
198_etc2_alpha_encode(uint8_t *etc2_alpha, const uint32_t *bgra, 198_etc2_alpha_encode(uint8_t *etc2_alpha, const uint32_t *bgra,
199 const rg_etc1_pack_params *params) 199 const rg_etc1_pack_params *params)
200{ 200{
201 int alphas[16], avg = 0, diff = 0, maxDiff = INT_MAX, minErr = INT_MAX; 201 int alphas[16], avg = 0, diff = 0, maxDiff = 0, minErr = INT_MAX;
202 int base_codeword; 202 int base_codeword;
203 int multiplier, bestMult = 0; 203 int multiplier, bestMult = 0;
204 int modifierIdx, bestIdx = 0; 204 int modifierIdx, bestIdx = 0, bestBase = 128;
205 int err, base_range, base_step = 1, max_error = 0; 205 int err, base_range, base_step = 1, max_error = 0;
206 206
207 // Try to select the best alpha value (avg) 207 // Try to select the best alpha value (avg)
@@ -215,7 +215,7 @@ _etc2_alpha_encode(uint8_t *etc2_alpha, const uint32_t *bgra,
215 for (int i = 0; i < 16; i++) 215 for (int i = 0; i < 16; i++)
216 { 216 {
217 int thisDiff = ABS(alphas[i] - avg); 217 int thisDiff = ABS(alphas[i] - avg);
218 maxDiff = MIN(thisDiff, maxDiff); 218 maxDiff = MAX(thisDiff, maxDiff);
219 diff += thisDiff; 219 diff += thisDiff;
220 } 220 }
221 221
@@ -234,27 +234,29 @@ _etc2_alpha_encode(uint8_t *etc2_alpha, const uint32_t *bgra,
234 { 234 {
235 // The follow parameters are completely arbitrary. 235 // The follow parameters are completely arbitrary.
236 // Need some real testing. 236 // Need some real testing.
237 case rg_etc1_high_quality: 237 case rg_etc1_high_quality: // exhaustive search
238 base_range = 15; 238 base_range = 255;
239 base_step = 1; 239 base_step = 1;
240 break; 240 break;
241 case rg_etc1_medium_quality: 241 case rg_etc1_medium_quality: // tweaked for "decent" results
242 base_range = 6; 242 base_range = 40;
243 base_step = 2; 243 base_step = 4;
244 break; 244 break;
245 case rg_etc1_low_quality: 245 case rg_etc1_low_quality: // fast (not even fastest)
246 base_range = 0; 246 base_range = 8;
247 base_step = 4;
247 break; 248 break;
248 } 249 }
249 250
250 // for loop avg, avg-1, avg+1, avg-2, avg+2, ... 251 // for loop avg, avg-1, avg+1, avg-2, avg+2, ...
251 for (int step = 0; step < base_range; step += base_step) 252 for (int step = 0; step < base_range; step += base_step)
252 for (base_codeword = avg - step; base_codeword <= avg + step; base_codeword += 2 * step) 253 for (base_codeword = CLAMP(avg - step);
254 base_codeword <= CLAMP(avg + step);)
253 { 255 {
254 for (modifierIdx = 0; modifierIdx < 16; modifierIdx++) 256 for (modifierIdx = 0; modifierIdx < 16; modifierIdx++)
255 for (multiplier = 0; multiplier < 16; multiplier++) 257 for (multiplier = 0; multiplier < 16; multiplier++)
256 { 258 {
257 if ((ABS(multiplier * kAlphaModifiers[modifierIdx][3])) < maxDiff) 259 if ((ABS(multiplier * kAlphaModifiers[modifierIdx][3]) + ABS(base_codeword - avg)) < maxDiff)
258 continue; 260 continue;
259 261
260 err = _etc2_alpha_block_pack(etc2_alpha, base_codeword, 262 err = _etc2_alpha_block_pack(etc2_alpha, base_codeword,
@@ -264,16 +266,21 @@ _etc2_alpha_encode(uint8_t *etc2_alpha, const uint32_t *bgra,
264 minErr = err; 266 minErr = err;
265 bestMult = multiplier; 267 bestMult = multiplier;
266 bestIdx = modifierIdx; 268 bestIdx = modifierIdx;
267 if (err < max_error) 269 bestBase = base_codeword;
270 if (err <= max_error)
268 goto pack_now; 271 goto pack_now;
269 272
270 } 273 }
271 } 274 }
272 if (step <= 0) break; 275 if (step <= 0) break;
276 if (base_codeword < 255)
277 base_codeword = CLAMP(base_codeword + 2 * step);
278 else
279 break;
273 } 280 }
274 281
275pack_now: 282pack_now:
276 err = _etc2_alpha_block_pack(etc2_alpha, base_codeword, 283 err = _etc2_alpha_block_pack(etc2_alpha, bestBase,
277 bestMult, bestIdx, bgra, EINA_TRUE); 284 bestMult, bestIdx, bgra, EINA_TRUE);
278 return err; 285 return err;
279} 286}
@@ -986,7 +993,7 @@ etc2_rgba8_block_pack(unsigned char *etc2, const unsigned int *bgra,
986 993
987#ifdef DEBUG 994#ifdef DEBUG
988 cnt[bestSolution]++; 995 cnt[bestSolution]++;
989 DBG("Block count by mode: ETC1: %d T/H: %d Planar: %d", cnt[0], cnt[1], cnt[2]); 996 DBG("Block count by mode: ETC1: %d T/H: %d Planar: %d. Err %d", cnt[0], cnt[1], cnt[2], minErr);
990#endif 997#endif
991 998
992 return minErr; 999 return minErr;