summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2014-04-18 18:17:57 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2014-04-18 18:46:55 +0900
commite120d42742b583dbe797170dd8f64022b2d11ea8 (patch)
treee95da3548b1a0808e8819d8f204b945f57221ca5
parent356939a8fdd7b7e30acfb0826d5c37d5661da179 (diff)
rg_etc1: Fix rare artifacts + add comments
Add some comments as I'm reading and understanding the code. Fix some rare artifacts happening mostly with medium quality encoding, where a few pixels (2x2, 2x4 or 4x2) will have a horrible contrast with their surroundings (eg. pink over black).
-rw-r--r--src/static_libs/rg_etc/rg_etc1.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/static_libs/rg_etc/rg_etc1.c b/src/static_libs/rg_etc/rg_etc1.c
index 5be83fd..32d3f9e 100644
--- a/src/static_libs/rg_etc/rg_etc1.c
+++ b/src/static_libs/rg_etc/rg_etc1.c
@@ -2119,7 +2119,7 @@ rg_etc1_pack_block_solid_color(unsigned char *block, const uint8* pColor, rg_etc
2119 2119
2120 if (!rg_etc1_inverse_lookup[0][255]) 2120 if (!rg_etc1_inverse_lookup[0][255])
2121 { 2121 {
2122 fprintf(stderr, "ETC1: Inverse lookup table not set!\n"); 2122 fprintf(stderr, "ETC1: Inverse lookup table not set (in %s)!\n", __FUNCTION__);
2123 return 0; 2123 return 0;
2124 } 2124 }
2125 2125
@@ -2226,8 +2226,14 @@ rg_etc1_pack_block_solid_color_constrained(rg_etc1_optimizer_results *results,ui
2226 int best_x = 0, best_packed_c1 = 0, best_packed_c2 = 0; 2226 int best_x = 0, best_packed_c1 = 0, best_packed_c2 = 0;
2227 uint i; 2227 uint i;
2228 2228
2229 // ERROR CASE NO ASSERT IN EVAS CODE 2229 if (!rg_etc1_inverse_lookup[0][255])
2230 if (!rg_etc1_inverse_lookup[0][255]) return 0; 2230 rg_etc1_pack_block_init();
2231
2232 if (!rg_etc1_inverse_lookup[0][255])
2233 {
2234 fprintf(stderr, "ETC1: Inverse lookup table not set (in %s)!\n", __FUNCTION__);
2235 return 0;
2236 }
2231 2237
2232 // For each possible 8-bit value, there is a precomputed list of diff/inten/selector configurations 2238 // For each possible 8-bit value, there is a precomputed list of diff/inten/selector configurations
2233 // that allow that 8-bit value to be encoded with no error. 2239 // that allow that 8-bit value to be encoded with no error.
@@ -2398,9 +2404,9 @@ rg_etc1_pack_block(void* pETC1_block, const unsigned int* pSrc_pixels_rgba, rg_e
2398 uint best_use_color4=EINA_FALSE; 2404 uint best_use_color4=EINA_FALSE;
2399 uint best_flip=EINA_FALSE; 2405 uint best_flip=EINA_FALSE;
2400 uint8 best_selectors[2][8]; 2406 uint8 best_selectors[2][8];
2401 rg_etc1_optimizer optimizer; 2407 rg_etc1_optimizer optimizer = { 0 };
2402 rg_etc1_optimizer_results best_results[2] = { { 0 } }; 2408 rg_etc1_optimizer_results best_results[2] = { { 0 } };
2403 rg_etc1_optimizer_results results[3]; 2409 rg_etc1_optimizer_results results[3] = { { 0 } };
2404 rg_etc1_optimizer_params params; 2410 rg_etc1_optimizer_params params;
2405 uint i, flip; 2411 uint i, flip;
2406 uint8 selectors[3][8]; 2412 uint8 selectors[3][8];
@@ -2427,6 +2433,8 @@ rg_etc1_pack_block(void* pETC1_block, const unsigned int* pSrc_pixels_rgba, rg_e
2427 break; 2433 break;
2428 if (!r) 2434 if (!r)
2429 return (unsigned int)(16 * rg_etc1_pack_block_solid_color(dst_block, &pSrc_pixels[0].comp.r, pack_params)); 2435 return (unsigned int)(16 * rg_etc1_pack_block_solid_color(dst_block, &pSrc_pixels[0].comp.r, pack_params));
2436
2437 // Dithering gives mitigated results... It would be nice to know when to use it.
2430 if (pack_params->m_dithering) 2438 if (pack_params->m_dithering)
2431 { 2439 {
2432 rg_etc1_dither_block_555(dithered_pixels, pSrc_pixels); 2440 rg_etc1_dither_block_555(dithered_pixels, pSrc_pixels);
@@ -2450,20 +2458,25 @@ rg_etc1_pack_block(void* pETC1_block, const unsigned int* pSrc_pixels_rgba, rg_e
2450 params.m_num_src_pixels = 8; 2458 params.m_num_src_pixels = 8;
2451 params.m_pSrc_pixels = subblock_pixels; 2459 params.m_pSrc_pixels = subblock_pixels;
2452 2460
2461 // try horizontal VS. vertical split
2453 for (flip = 0; flip < 2; flip++) 2462 for (flip = 0; flip < 2; flip++)
2454 { 2463 {
2464 // try two color types: RGB555 + diff333 or RGB444 & RGB444
2455 uint use_color4; 2465 uint use_color4;
2456 for (use_color4 = 0; use_color4 < 2; use_color4++) 2466 for (use_color4 = 0; use_color4 < 2; use_color4++)
2457 { 2467 {
2458 uint64 trial_error = 0; 2468 uint64 trial_error = 0;
2459 2469
2470 // subblock is either top/bottom or left/right
2460 uint subblock; 2471 uint subblock;
2461 for (subblock = 0; subblock < 2; subblock++) 2472 for (subblock = 0; subblock < 2; subblock++)
2462 { 2473 {
2463 if (flip) 2474 if (flip)
2475 // subblock is top or bottom, copy source
2464 memcpy(subblock_pixels, pSrc_pixels + subblock * 8, sizeof(color_quad_u8) * 8); 2476 memcpy(subblock_pixels, pSrc_pixels + subblock * 8, sizeof(color_quad_u8) * 8);
2465 else 2477 else
2466 { 2478 {
2479 // subblock = 1 : left, subblock = 2 : right, copy source
2467 const color_quad_u8* pSrc_col = pSrc_pixels + subblock * 2; 2480 const color_quad_u8* pSrc_col = pSrc_pixels + subblock * 2;
2468 rg_etc1_color_quad_u8_copy(&subblock_pixels[0], &pSrc_col[0]); 2481 rg_etc1_color_quad_u8_copy(&subblock_pixels[0], &pSrc_col[0]);
2469 rg_etc1_color_quad_u8_copy(&subblock_pixels[1], &pSrc_col[4]); 2482 rg_etc1_color_quad_u8_copy(&subblock_pixels[1], &pSrc_col[4]);
@@ -2479,11 +2492,12 @@ rg_etc1_pack_block(void* pETC1_block, const unsigned int* pSrc_pixels_rgba, rg_e
2479 if ((params.base_params->m_quality >= rg_etc1_medium_quality) && ((subblock) || (use_color4))) 2492 if ((params.base_params->m_quality >= rg_etc1_medium_quality) && ((subblock) || (use_color4)))
2480 { 2493 {
2481 const uint32 subblock_pixel0_u32 = subblock_pixels[0].m_u32; 2494 const uint32 subblock_pixel0_u32 = subblock_pixels[0].m_u32;
2482 for (r = 7; r >= 1; --r) 2495 for (r = 7; r >= 0; --r)
2483 if (subblock_pixels[r].m_u32 != subblock_pixel0_u32) 2496 if (subblock_pixels[r].m_u32 != subblock_pixel0_u32)
2484 break; 2497 break;
2485 if (!r) 2498 if (!r)
2486 { 2499 {
2500 // all pixels in subblock have the same color
2487 rg_etc1_pack_block_solid_color_constrained(&results[2], 8, &subblock_pixels[0].comp.r, 2501 rg_etc1_pack_block_solid_color_constrained(&results[2], 8, &subblock_pixels[0].comp.r,
2488 pack_params, !use_color4, 2502 pack_params, !use_color4,
2489 (subblock && !use_color4) ? &results[0].m_block_color_unscaled : NULL); 2503 (subblock && !use_color4) ? &results[0].m_block_color_unscaled : NULL);