Removing unused code
diff --git a/basisu_tool.cpp b/basisu_tool.cpp
index e20ed0c..6751d15 100644
--- a/basisu_tool.cpp
+++ b/basisu_tool.cpp
@@ -5146,482 +5146,6 @@
return true;
}
-#if 0
-#include "transcoder/basisu_astc_helpers.h"
-#include "encoder/3rdparty/android_astc_decomp.h"
-
-static void astc_decode_test()
-{
- uint32_t block_size_index = 0;
-
-redo:
- if (block_size_index >= astc_helpers::NUM_ASTC_BLOCK_SIZES)
- block_size_index = 0;
-
- const uint32_t block_w = astc_helpers::g_astc_block_sizes[block_size_index][0], block_h = astc_helpers::g_astc_block_sizes[block_size_index][1];
- block_size_index++;
-
- if (!astc_helpers::is_valid_block_size(block_w, block_h))
- {
- printf("Bad block size\n");
- exit(1);
- }
-
- bool ldr_cems_only = false;
- bool test_srgb = ldr_cems_only && false;
- //decomp_astc_block_init(block_w, block_h, ldr_cems_only ? (test_srgb ? ASTCENC_PRF_LDR_SRGB : ASTCENC_PRF_LDR) : ASTCENC_PRF_HDR);
-
- uint32_t total_modes = 0;
-
- basisu::rand rnd;
- rnd.seed(1000 + block_w * 52772 + block_h * 10055);
-
- for (uint32_t dp = 0; dp < 2; dp++)
- //for (uint32_t dp = 1; dp <= 1; dp++)
- {
- for (uint32_t num_parts = 1; num_parts <= (dp ? 3U : 4U); num_parts++)
- //for (uint32_t num_parts = 1; num_parts <= 1; num_parts++)
- {
- for (uint32_t weight_range = 0; weight_range <= 11; weight_range++)
- //for (uint32_t weight_range = 8; weight_range <= 8; weight_range++)
- {
- for (uint32_t cem0 = 0; cem0 <= 15; cem0++)
- {
- for (uint32_t cem1 = (num_parts >= 2) ? 0 : cem0; cem1 <= ((num_parts >= 2) ? 15 : cem0); cem1++)
- {
- for (uint32_t cem2 = (num_parts >= 3) ? 0 : cem1; cem2 <= ((num_parts >= 3) ? 15 : cem1); cem2++)
- {
- for (uint32_t cem3 = (num_parts >= 4) ? 0 : cem2; cem3 <= ((num_parts == 4) ? 15 : cem2); cem3++)
- {
- for (uint32_t w = 2; w <= block_w; w++)
- //for (uint32_t w = 3; w <= 3; w++)
- {
- for (uint32_t h = 2; h <= block_h; h++)
- //for (uint32_t h = 3; h <= 3; h++)
- {
- const bool is_ldr_cem0 = astc_helpers::is_cem_ldr(cem0);
- const bool is_ldr_cem1 = astc_helpers::is_cem_ldr(cem1);
- const bool is_ldr_cem2 = astc_helpers::is_cem_ldr(cem2);
- const bool is_ldr_cem3 = astc_helpers::is_cem_ldr(cem3);
-
- if (ldr_cems_only)
- {
- if ((!is_ldr_cem0) || (!is_ldr_cem1) || (!is_ldr_cem2) || (!is_ldr_cem3))
- continue;
- }
-
- const uint32_t MAX_TRIES = 2;
- for (uint32_t try_index = 0; try_index < MAX_TRIES; try_index++)
- {
- astc_helpers::log_astc_block log_block;
- log_block.clear();
-
- log_block.m_grid_width = w;
- log_block.m_grid_height = h;
- log_block.m_dual_plane = dp != 0;
- log_block.m_color_component_selector = 0;
- log_block.m_endpoint_ise_range = 20;
- log_block.m_weight_ise_range = weight_range;
- log_block.m_num_partitions = num_parts;
- log_block.m_partition_id = 0;
- log_block.m_color_endpoint_modes[0] = cem0;
- log_block.m_color_endpoint_modes[1] = (num_parts >= 2) ? cem1 : 0;
- log_block.m_color_endpoint_modes[2] = (num_parts >= 3) ? cem2 : 0;
- log_block.m_color_endpoint_modes[3] = (num_parts >= 4) ? cem3 : 0;
-
- uint32_t total_endpoint_vals = 0;
- for (uint32_t i = 0; i < num_parts; i++)
- total_endpoint_vals += astc_helpers::get_num_cem_values(log_block.m_color_endpoint_modes[i]);
- if (total_endpoint_vals > astc_helpers::MAX_ENDPOINTS)
- continue;
-
- uint32_t endpoint_levels = astc_helpers::get_ise_levels(log_block.m_endpoint_ise_range);
- for (uint32_t j = 0; j < total_endpoint_vals; j++)
- log_block.m_endpoints[j] = (uint8_t)rnd.irand(0, endpoint_levels - 1);
-
- const uint32_t weight_levels = astc_helpers::get_ise_levels(log_block.m_weight_ise_range);
- const uint32_t total_weights = (log_block.m_dual_plane ? 2 : 1) * log_block.m_grid_width * log_block.m_grid_height;
- if (total_weights > astc_helpers::MAX_GRID_WEIGHTS)
- continue;
-
- for (uint32_t j = 0; j < total_weights; j++)
- log_block.m_weights[j] = (uint8_t)rnd.irand(0, weight_levels - 1);
-
- astc_helpers::astc_block phys_block;
- int expected_endpoint_range = -1;
- bool status = astc_helpers::pack_astc_block(phys_block, log_block, &expected_endpoint_range);
-
- if (!status)
- {
- if (expected_endpoint_range != -1)
- {
- log_block.m_endpoint_ise_range = expected_endpoint_range;
-
- endpoint_levels = astc_helpers::get_ise_levels(log_block.m_endpoint_ise_range);
- for (uint32_t j = 0; j < total_endpoint_vals; j++)
- log_block.m_endpoints[j] = (uint8_t)rnd.irand(0, endpoint_levels - 1);
-
- status = astc_helpers::pack_astc_block(phys_block, log_block, &expected_endpoint_range);
- }
-
- if (!status)
- continue;
- }
-
- astc_helpers::log_astc_block unpacked_log_blk;
-
- {
- bool q = unpack_block(&phys_block, unpacked_log_blk, block_w, block_h);
- if (!q)
- {
- printf("Failure\n");
- exit(1);
- }
-
- bool same = log_block.m_grid_width == unpacked_log_blk.m_grid_width;
- same = same & (log_block.m_grid_height == unpacked_log_blk.m_grid_height);
- same = same & (log_block.m_dual_plane == unpacked_log_blk.m_dual_plane);
- same = same & (log_block.m_color_component_selector == unpacked_log_blk.m_color_component_selector);
- same = same & (log_block.m_endpoint_ise_range == unpacked_log_blk.m_endpoint_ise_range);
- same = same & (log_block.m_weight_ise_range == unpacked_log_blk.m_weight_ise_range);
- same = same & (log_block.m_num_partitions == unpacked_log_blk.m_num_partitions);
- same = same & (log_block.m_partition_id == unpacked_log_blk.m_partition_id);
- for (uint32_t i = 0; i < log_block.m_num_partitions; i++)
- {
- same = same & (log_block.m_color_endpoint_modes[i] == unpacked_log_blk.m_color_endpoint_modes[i]);
- }
- for (uint32_t i = 0; i < 64; i++)
- {
- same = same & (log_block.m_weights[i] == unpacked_log_blk.m_weights[i]);
- }
- for (uint32_t i = 0; i < 18; i++)
- {
- same = same & (log_block.m_endpoints[i] == unpacked_log_blk.m_endpoints[i]);
- }
- if (!same)
- {
- printf("Failure\n");
- exit(1);
- }
-
- }
-
- if (!is_ldr_cem0 || !is_ldr_cem1 || !is_ldr_cem2 || !is_ldr_cem3)
- {
- // Google's decompressor
- vec4F pixels[12 * 12];
-
- status = basisu_astc::astc::decompress_hdr(&pixels[0][0], (uint8_t*)&phys_block, block_w, block_h);
- if (!status)
- {
- assert(0);
- continue;
- }
-
- // My decompressor
- uint16_t alt_pixels[12 * 12 * 4];
- status = astc_helpers::decode_block(unpacked_log_blk, alt_pixels, block_w, block_h, astc_helpers::cDecodeModeHDR16);
- if (!status)
- {
- assert(0);
- continue;
- }
-
-#if 0
- // ARM's decompressor
- vec4F arm_pixels[12 * 12];
- status = decomp_astc_block_f32((astc_blk&)phys_block, arm_pixels, block_w, block_h);
- if (!status)
- {
- printf("decomp_astc_block() failed!\n");
- exit(1);
- }
-#endif
-
- for (uint32_t y = 0; y < block_h; y++)
- {
- for (uint32_t x = 0; x < block_w; x++)
- {
- for (uint32_t c = 0; c < 4; c++)
- {
- float a = pixels[x + y * block_w][c];
-
- basist::half_float hb = alt_pixels[(x + y * block_w) * 4 + c];
- float b = basist::half_to_float(hb);
-
- //float d = arm_pixels[x + y * block_w][c];
- float d = b;//
-
- if ((a != b) || (a != d))
- {
- printf("Failure\n");
- exit(0);
- }
- }
- }
- }
-
- }
- else
- {
- // Google's decompressor
- uint8_t pixels[12 * 12 * 4];
- status = basisu_astc::astc::decompress_ldr(pixels, (uint8_t*)&phys_block, test_srgb, block_w, block_h);
- if (!status)
- {
- assert(0);
- continue;
- }
-
- // My decompressor
- uint8_t alt_pixels[12 * 12 * 4];
- status = astc_helpers::decode_block(unpacked_log_blk, alt_pixels, block_w, block_h, test_srgb ? astc_helpers::cDecodeModeSRGB8 : astc_helpers::cDecodeModeLDR8);
- if (!status)
- {
- assert(0);
- continue;
- }
-
-#if 0
- // ARM's decompressor
- uint8_t arm_pixels[12 * 12 * 4];
- status = decomp_astc_block_u8((astc_blk&)phys_block, arm_pixels, block_w, block_h);
- if (!status)
- {
- printf("decomp_astc_block() failed!\n");
- exit(1);
- }
-#endif
-
- for (uint32_t y = 0; y < block_h; y++)
- {
- for (uint32_t x = 0; x < block_w; x++)
- {
- for (uint32_t c = 0; c < 4; c++)
- {
- if ((pixels[(x + y * block_w) * 4 + c] != alt_pixels[(x + y * block_w) * 4 + c])
- //|| (iabs(pixels[(x + y * block_w) * 4 + c] - arm_pixels[(x + y * block_w) * 4 + c]) > 1)
- )
- {
- printf("Failure\n");
- exit(0);
- }
- }
- }
- }
- }
-
- printf("%u: blk: %ux%u, cems: %u %u %u %u, grid: %ux%u, dp: %u, parts: %u, endpoint range: %i, endpoint levels: %i, weight range: %u, weight levels: %u\n",
- total_modes,
- block_w, block_h,
- cem0, cem1, cem2, cem3, w, h, dp, num_parts,
- log_block.m_endpoint_ise_range, astc_helpers::get_ise_levels(log_block.m_endpoint_ise_range),
- weight_range, astc_helpers::get_ise_levels(weight_range));
- total_modes++;
-
- } // try_index
-
- } // h
-
- } // w
-
- } // cem 3
- } // cem 2
- } // cem1
- } // cem0
-
- } // weight_range
-
- } // num_parts
- } // dp
- printf("OK\n");
-
- goto redo;
-
- exit(0);
-}
-
-static bool astc_decode_test2()
-{
- uint32_t total_valid_blocks = 0;
-
- basisu::rand rnd;
- rnd.seed(1000);
-
- for (uint32_t t = 0; t < 1000000; t++)
- {
- astc_helpers::astc_block blk;
- for (uint32_t i = 0; i < 16; i++)
- ((uint8_t*)&blk)[i] = rnd.byte();
-
- const uint32_t r = rnd.irand(0, astc_helpers::NUM_ASTC_BLOCK_SIZES - 1);
- const uint32_t W = astc_helpers::g_astc_block_sizes[r][0], H = astc_helpers::g_astc_block_sizes[r][1];
-
- astc_helpers::log_astc_block log_blk;
- bool status1 = astc_helpers::unpack_block(&blk, log_blk, W, H);
-
- basist::half_float pixels1[12 * 12 * 4];
- if (status1)
- {
- status1 = astc_helpers::decode_block(log_blk, pixels1, W, H, astc_helpers::cDecodeModeHDR16);
- }
-
- vec4F pixels2[12 * 12];
- bool status2 = basisu_astc::astc::decompress_hdr(&pixels2[0][0], (uint8_t*)&blk, W, H);
-
- if (status1 && status2)
- {
- total_valid_blocks++;
- if ((total_valid_blocks & 8191) == 8191)
- printf("%u\n", total_valid_blocks);
-
- for (uint32_t i = 0; i < W * H; i++)
- {
- for (uint32_t c = 0; c < 4; c++)
- {
- float a = basist::half_to_float(pixels1[i * 4 + c]);
- float b = pixels2[i][c];
- if (a != b)
- {
- error_printf("ASTC decode mismatch!\n");
- return false;
- }
- }
- }
-
- }
- }
-
- printf("Success\n");
- return true;
-}
-
-static bool astc_decode_test3()
-{
- uint32_t total_valid_blocks = 0;
-
- basisu::rand rnd;
- rnd.seed(1001);
-
- for (uint32_t t = 0; t < 50000000; t++)
- {
- astc_helpers::astc_block blk;
- for (uint32_t i = 0; i < 16; i++)
- ((uint8_t*)&blk)[i] = rnd.byte();
-
- const uint32_t r = rnd.irand(0, astc_helpers::NUM_ASTC_BLOCK_SIZES - 1);
- const uint32_t W = astc_helpers::g_astc_block_sizes[r][0], H = astc_helpers::g_astc_block_sizes[r][1];
-
- astc_helpers::log_astc_block log_blk;
- bool status1 = astc_helpers::unpack_block(&blk, log_blk, W, H);
-
- basist::half_float pixels1[12 * 12 * 4];
- if (status1)
- {
- status1 = astc_helpers::decode_block(log_blk, pixels1, W, H, astc_helpers::cDecodeModeHDR16);
- }
-
- vec4F pixels2[12 * 12];
- bool status2 = basisu_astc::astc::decompress_hdr(&pixels2[0][0], (uint8_t*)&blk, W, H);
-
- if (!status1 || !status2)
- continue;
-
- {
- total_valid_blocks++;
- if ((total_valid_blocks & 8191) == 8191)
- printf("%u\n", total_valid_blocks);
-
- for (uint32_t i = 0; i < W * H; i++)
- {
- for (uint32_t c = 0; c < 4; c++)
- {
- float a = basist::half_to_float(pixels1[i * 4 + c]);
- float b = pixels2[i][c];
- if (a != b)
- {
- error_printf("ASTC decode mismatch!\n");
- return false;
- }
- }
- }
- }
-
- uint32_t pixels3[12 * 12];
- if (status1)
- {
- bool status3 = astc_helpers::decode_block(log_blk, pixels3, W, H, astc_helpers::cDecodeModeRGB9E5);
- assert(status1 == status3);
- BASISU_NOTE_UNUSED(status3);
- }
-
- for (uint32_t i = 0; i < W * H; i++)
- {
- float rc, gc, bc;
- astc_helpers::unpack_rgb9e5(pixels3[i], rc, gc, bc);
-
- float comp_r = clamp<float>(pixels2[i][0], 0.0f, astc_helpers::MAX_RGB9E5);
- float comp_g = clamp<float>(pixels2[i][1], 0.0f, astc_helpers::MAX_RGB9E5);
- float comp_b = clamp<float>(pixels2[i][2], 0.0f, astc_helpers::MAX_RGB9E5);
-
- const float D = maximum(comp_r, comp_g, comp_b) / 256.0f;
- if ((fabs(rc - comp_r) > D) || (fabs(gc - comp_g) > D) || (fabs(bc - comp_b) > D))
- {
- printf("!");
- }
- }
-
- //printf(".");
- }
-
- printf("Success\n");
- return true;
-}
-#endif
-
-#if 0
-#define BCDEC_IMPLEMENTATION
-#include "bcdec.h"
-
-void bc6h_decode_test()
-{
- basisu::rand rnd;
- rnd.seed(2000);
-
- for (uint32_t t = 0; t < 100000000; t++)
- {
- basist::bc6h_block blk;
- for (uint32_t i = 0; i < sizeof(blk); i++)
- ((uint8_t*)&blk)[i] = rnd.byte();
-
- basist::half_float d1[16 * 3];
- bool res0 = bcdec_bc6h_half(&blk, d1, 4 * 3, false);
-
- basist::half_float d2[16 * 3];
- bool res1 = unpack_bc6h(&blk, d2, false, 4 * 3);
-
- assert(res0 == res1);
-
- if ((!res0) || (!res1))
- {
- //printf("!");
- continue;
- }
-
- for (uint32_t i = 0; i < 16 * 3; i++)
- {
- if (d1[i] != d2[i])
- {
- printf("failure\n");
- exit(1);
- }
- }
- }
-
- printf("Success\n");
-}
-#endif
-
#ifdef FORCE_SAN_FAILURE
static void force_san_failure()
{