diff --git a/3rdparty/astc-encoder/source/astcenc_block_sizes.cpp b/3rdparty/astc-encoder/source/astcenc_block_sizes.cpp index 3e70d78..b3e2efb 100644 --- a/3rdparty/astc-encoder/source/astcenc_block_sizes.cpp +++ b/3rdparty/astc-encoder/source/astcenc_block_sizes.cpp @@ -1006,7 +1006,7 @@ static void construct_block_size_descriptor_2d( } /** - * @brief Allocate block modes and decimation tables for a single £D block size. + * @brief Allocate block modes and decimation tables for a single 3D block size. * * TODO: This function doesn't include all of the heuristics that we use for 2D block sizes such as * the percentile mode cutoffs. If 3D becomes more widely used we should look at this. diff --git a/3rdparty/astc-encoder/source/astcenc_color_quantize.cpp b/3rdparty/astc-encoder/source/astcenc_color_quantize.cpp index 278f334..1f5a4d9 100644 --- a/3rdparty/astc-encoder/source/astcenc_color_quantize.cpp +++ b/3rdparty/astc-encoder/source/astcenc_color_quantize.cpp @@ -40,24 +40,6 @@ #include "astcenc_internal.h" -/** - * @brief Determine the quantized value given a quantization level. - * - * @param quant_level The quantization level to use. - * @param value The value to convert. This may be outside of the 0-255 range and will be - * clamped before the value is looked up. - * - * @return The encoded quantized value. These are not necessarily in order; the compressor - * scrambles the values slightly to make hardware implementation easier. - */ -static inline int quant_color_clamp( - quant_method quant_level, - int value -) { - value = astc::clamp(value, 0, 255); - return color_quant_tables[quant_level - QUANT_6][value]; -} - /** * @brief Determine the quantized value given a quantization level. * @@ -72,23 +54,7 @@ static inline uint8_t quant_color( quant_method quant_level, int value ) { - return color_quant_tables[quant_level - QUANT_6][value]; -} - -/** - * @brief Determine the unquantized value given a quantization level. - * - * @param quant_level The quantization level to use. - * @param value The value to convert. - * - * @return The encoded quantized value. These are not necessarily in order; the compressor - * scrambles the values slightly to make hardware implementation easier. - */ -static inline uint8_t unquant_color( - quant_method quant_level, - int value -) { - return color_unquant_tables[quant_level - QUANT_6][value]; + return color_unquant_to_uquant_tables[quant_level - QUANT_6][value]; } /** @@ -120,28 +86,20 @@ static void quantize_rgb( float b1 = astc::clamp255f(color1.lane<2>() * scale); int ri0, gi0, bi0, ri1, gi1, bi1; - int ri0b, gi0b, bi0b, ri1b, gi1b, bi1b; float rgb0_addon = 0.5f; float rgb1_addon = 0.5f; do { - ri0 = quant_color_clamp(quant_level, astc::flt2int_rd(r0 + rgb0_addon)); - gi0 = quant_color_clamp(quant_level, astc::flt2int_rd(g0 + rgb0_addon)); - bi0 = quant_color_clamp(quant_level, astc::flt2int_rd(b0 + rgb0_addon)); - ri1 = quant_color_clamp(quant_level, astc::flt2int_rd(r1 + rgb1_addon)); - gi1 = quant_color_clamp(quant_level, astc::flt2int_rd(g1 + rgb1_addon)); - bi1 = quant_color_clamp(quant_level, astc::flt2int_rd(b1 + rgb1_addon)); - - ri0b = unquant_color(quant_level, ri0); - gi0b = unquant_color(quant_level, gi0); - bi0b = unquant_color(quant_level, bi0); - ri1b = unquant_color(quant_level, ri1); - gi1b = unquant_color(quant_level, gi1); - bi1b = unquant_color(quant_level, bi1); + ri0 = quant_color(quant_level, astc::max(astc::flt2int_rd(r0 + rgb0_addon), 0)); + gi0 = quant_color(quant_level, astc::max(astc::flt2int_rd(g0 + rgb0_addon), 0)); + bi0 = quant_color(quant_level, astc::max(astc::flt2int_rd(b0 + rgb0_addon), 0)); + ri1 = quant_color(quant_level, astc::min(astc::flt2int_rd(r1 + rgb1_addon), 255)); + gi1 = quant_color(quant_level, astc::min(astc::flt2int_rd(g1 + rgb1_addon), 255)); + bi1 = quant_color(quant_level, astc::min(astc::flt2int_rd(b1 + rgb1_addon), 255)); rgb0_addon -= 0.2f; rgb1_addon += 0.2f; - } while (ri0b + gi0b + bi0b > ri1b + gi1b + bi1b); + } while (ri0 + gi0 + bi0 > ri1 + gi1 + bi1); output[0] = static_cast(ri0); output[1] = static_cast(ri1); @@ -230,18 +188,9 @@ static bool try_quantize_rgb_blue_contract( int gi1 = quant_color(quant_level, astc::flt2int_rtn(g1)); int bi1 = quant_color(quant_level, astc::flt2int_rtn(b1)); - // Then unquantize again - int ru0 = unquant_color(quant_level, ri0); - int gu0 = unquant_color(quant_level, gi0); - int bu0 = unquant_color(quant_level, bi0); - - int ru1 = unquant_color(quant_level, ri1); - int gu1 = unquant_color(quant_level, gi1); - int bu1 = unquant_color(quant_level, bi1); - // If color #1 is not larger than color #0 then blue-contraction cannot be used. Note that - // blue-contraction and quantization change this order, which is why we must test aftwards. - if (ru1 + gu1 + bu1 <= ru0 + gu0 + bu0) + // blue-contraction and quantization change this order, which is why we must test afterwards. + if (ri1 + gi1 + bi1 <= ri0 + gi0 + bi0) { return false; } @@ -334,13 +283,9 @@ static bool try_quantize_rgb_delta( int g0be = quant_color(quant_level, g0b); int b0be = quant_color(quant_level, b0b); - int r0bu = unquant_color(quant_level, r0be); - int g0bu = unquant_color(quant_level, g0be); - int b0bu = unquant_color(quant_level, b0be); - - r0b = r0bu | (r0a & 0x100); - g0b = g0bu | (g0a & 0x100); - b0b = b0bu | (b0a & 0x100); + r0b = r0be | (r0a & 0x100); + g0b = g0be | (g0a & 0x100); + b0b = b0be | (b0a & 0x100); // Get hold of the second value int r1d = astc::flt2int_rtn(r1); @@ -377,18 +322,14 @@ static bool try_quantize_rgb_delta( int g1de = quant_color(quant_level, g1d); int b1de = quant_color(quant_level, b1d); - int r1du = unquant_color(quant_level, r1de); - int g1du = unquant_color(quant_level, g1de); - int b1du = unquant_color(quant_level, b1de); - - if (((r1d ^ r1du) | (g1d ^ g1du) | (b1d ^ b1du)) & 0xC0) + if (((r1d ^ r1de) | (g1d ^ g1de) | (b1d ^ b1de)) & 0xC0) { return false; } // If the sum of offsets triggers blue-contraction then encoding fails - vint4 ep0(r0bu, g0bu, b0bu, 0); - vint4 ep1(r1du, g1du, b1du, 0); + vint4 ep0(r0be, g0be, b0be, 0); + vint4 ep1(r1de, g1de, b1de, 0); bit_transfer_signed(ep1, ep0); if (hadd_rgb_s(ep1) < 0) { @@ -459,13 +400,9 @@ static bool try_quantize_rgb_delta_blue_contract( int g0be = quant_color(quant_level, g0b); int b0be = quant_color(quant_level, b0b); - int r0bu = unquant_color(quant_level, r0be); - int g0bu = unquant_color(quant_level, g0be); - int b0bu = unquant_color(quant_level, b0be); - - r0b = r0bu | (r0a & 0x100); - g0b = g0bu | (g0a & 0x100); - b0b = b0bu | (b0a & 0x100); + r0b = r0be | (r0a & 0x100); + g0b = g0be | (g0a & 0x100); + b0b = b0be | (b0a & 0x100); // Get hold of the second value int r1d = astc::flt2int_rtn(r1); @@ -503,18 +440,14 @@ static bool try_quantize_rgb_delta_blue_contract( int g1de = quant_color(quant_level, g1d); int b1de = quant_color(quant_level, b1d); - int r1du = unquant_color(quant_level, r1de); - int g1du = unquant_color(quant_level, g1de); - int b1du = unquant_color(quant_level, b1de); - - if (((r1d ^ r1du) | (g1d ^ g1du) | (b1d ^ b1du)) & 0xC0) + if (((r1d ^ r1de) | (g1d ^ g1de) | (b1d ^ b1de)) & 0xC0) { return false; } // If the sum of offsets does not trigger blue-contraction then encoding fails - vint4 ep0(r0bu, g0bu, b0bu, 0); - vint4 ep1(r1du, g1du, b1du, 0); + vint4 ep0(r0be, g0be, b0be, 0); + vint4 ep1(r1de, g1de, b1de, 0); bit_transfer_signed(ep1, ep0); if (hadd_rgb_s(ep1) >= 0) { @@ -569,7 +502,7 @@ static bool try_quantize_alpha_delta( a0a <<= 1; int a0b = a0a & 0xFF; int a0be = quant_color(quant_level, a0b); - a0b = unquant_color(quant_level, a0be); + a0b = a0be; a0b |= a0a & 0x100; int a1d = astc::flt2int_rtn(a1); a1d <<= 1; @@ -584,7 +517,7 @@ static bool try_quantize_alpha_delta( a1d |= (a0b & 0x100) >> 1; int a1de = quant_color(quant_level, a1d); - int a1du = unquant_color(quant_level, a1de); + int a1du = a1de; if ((a1d ^ a1du) & 0xC0) { return false; @@ -647,8 +580,8 @@ static bool try_quantize_luminance_alpha_delta( int a0b = a0a & 0xFF; int l0be = quant_color(quant_level, l0b); int a0be = quant_color(quant_level, a0b); - l0b = unquant_color(quant_level, l0be); - a0b = unquant_color(quant_level, a0be); + l0b = l0be; + a0b = a0be; l0b |= l0a & 0x100; a0b |= a0a & 0x100; @@ -676,8 +609,8 @@ static bool try_quantize_luminance_alpha_delta( int l1de = quant_color(quant_level, l1d); int a1de = quant_color(quant_level, a1d); - int l1du = unquant_color(quant_level, l1de); - int a1du = unquant_color(quant_level, a1de); + int l1du = l1de; + int a1du = a1de; if ((l1d ^ l1du) & 0xC0) { @@ -799,12 +732,8 @@ static void quantize_rgbs( int gi = quant_color(quant_level, astc::flt2int_rtn(g)); int bi = quant_color(quant_level, astc::flt2int_rtn(b)); - int ru = unquant_color(quant_level, ri); - int gu = unquant_color(quant_level, gi); - int bu = unquant_color(quant_level, bi); - float oldcolorsum = hadd_rgb_s(color) * scale; - float newcolorsum = static_cast(ru + gu + bu); + float newcolorsum = static_cast(ri + gi + bi); float scalea = astc::clamp1f(color.lane<3>() * (oldcolorsum + 1e-10f) / (newcolorsum + 1e-10f)); int scale_idx = astc::flt2int_rtn(scalea * 256.0f); @@ -949,33 +878,29 @@ static void quantize_luminance_alpha( * @param quant_level The quantization level to use. * @param value The input unquantized value. * @param[out] quant_value The quantized value. - * @param[out] unquant_value The unquantized value after quantization. */ static inline void quantize_and_unquantize_retain_top_two_bits( quant_method quant_level, uint8_t value, - uint8_t& quant_value, - uint8_t& unquant_value + uint8_t& quant_value ) { int perform_loop; uint8_t quantval; - uint8_t uquantval; do { quantval = quant_color(quant_level, value); - uquantval = unquant_color(quant_level, quantval); // Perform looping if the top two bits were modified by quant/unquant - perform_loop = (value & 0xC0) != (uquantval & 0xC0); + perform_loop = (value & 0xC0) != (quantval & 0xC0); - if ((uquantval & 0xC0) > (value & 0xC0)) + if ((quantval & 0xC0) > (value & 0xC0)) { // Quant/unquant rounded UP so that the top two bits changed; // decrement the input in hopes that this will avoid rounding up. value--; } - else if ((uquantval & 0xC0) < (value & 0xC0)) + else if ((quantval & 0xC0) < (value & 0xC0)) { // Quant/unquant rounded DOWN so that the top two bits changed; // decrement the input in hopes that this will avoid rounding down. @@ -984,7 +909,6 @@ static inline void quantize_and_unquantize_retain_top_two_bits( } while (perform_loop); quant_value = quantval; - unquant_value = uquantval; } /** @@ -992,34 +916,29 @@ static inline void quantize_and_unquantize_retain_top_two_bits( * * @param quant_level The quantization level to use. * @param value The input unquantized value. - * @param[out] quant_value The quantized value. - * @param[out] unquant_value The unquantized value after quantization. + * @param[out] quant_value The quantized value in 0-255 range. */ static inline void quantize_and_unquantize_retain_top_four_bits( quant_method quant_level, uint8_t value, - uint8_t& quant_value, - uint8_t& unquant_value + uint8_t& quant_value ) { uint8_t perform_loop; uint8_t quantval; - uint8_t uquantval; do { quantval = quant_color(quant_level, value); - uquantval = unquant_color(quant_level, quantval); - // Perform looping if the top four bits were modified by quant/unquant - perform_loop = (value & 0xF0) != (uquantval & 0xF0); + perform_loop = (value & 0xF0) != (quantval & 0xF0); - if ((uquantval & 0xF0) > (value & 0xF0)) + if ((quantval & 0xF0) > (value & 0xF0)) { // Quant/unquant rounded UP so that the top four bits changed; // decrement the input value in hopes that this will avoid rounding up. value--; } - else if ((uquantval & 0xF0) < (value & 0xF0)) + else if ((quantval & 0xF0) < (value & 0xF0)) { // Quant/unquant rounded DOWN so that the top four bits changed; // decrement the input value in hopes that this will avoid rounding down. @@ -1028,7 +947,6 @@ static inline void quantize_and_unquantize_retain_top_four_bits( } while (perform_loop); quant_value = quantval; - unquant_value = uquantval; } /** @@ -1139,11 +1057,10 @@ static void quantize_hdr_rgbo( r_lowbits |= (mode_enc & 3) << 6; uint8_t r_quantval; - uint8_t r_uquantval; quantize_and_unquantize_retain_top_two_bits( - quant_level, static_cast(r_lowbits), r_quantval, r_uquantval); + quant_level, static_cast(r_lowbits), r_quantval); - r_intval = (r_intval & ~0x3f) | (r_uquantval & 0x3f); + r_intval = (r_intval & ~0x3f) | (r_quantval & 0x3f); float r_fval = static_cast(r_intval) * mode_rscale; // Recompute G and B, then quantize and unquantize them @@ -1239,16 +1156,14 @@ static void quantize_hdr_rgbo( uint8_t g_quantval; uint8_t b_quantval; - uint8_t g_uquantval; - uint8_t b_uquantval; quantize_and_unquantize_retain_top_four_bits( - quant_level, static_cast(g_lowbits), g_quantval, g_uquantval); + quant_level, static_cast(g_lowbits), g_quantval); quantize_and_unquantize_retain_top_four_bits( - quant_level, static_cast(b_lowbits), b_quantval, b_uquantval); + quant_level, static_cast(b_lowbits), b_quantval); - g_intval = (g_intval & ~0x1f) | (g_uquantval & 0x1f); - b_intval = (b_intval & ~0x1f) | (b_uquantval & 0x1f); + g_intval = (g_intval & ~0x1f) | (g_quantval & 0x1f); + b_intval = (b_intval & ~0x1f) | (b_quantval & 0x1f); g_fval = static_cast(g_intval) * mode_rscale; b_fval = static_cast(b_intval) * mode_rscale; @@ -1312,10 +1227,9 @@ static void quantize_hdr_rgbo( s_lowbits |= bit4 << 7; uint8_t s_quantval; - uint8_t s_uquantval; quantize_and_unquantize_retain_top_four_bits( - quant_level, static_cast(s_lowbits), s_quantval, s_uquantval); + quant_level, static_cast(s_lowbits), s_quantval); output[0] = r_quantval; output[1] = g_quantval; @@ -1355,9 +1269,8 @@ static void quantize_hdr_rgbo( for (uint8_t i = 0; i < 4; i++) { - uint8_t dummy; quantize_and_unquantize_retain_top_four_bits( - quant_level, static_cast(encvals[i]), output[i], dummy); + quant_level, static_cast(encvals[i]), output[i]); } return; @@ -1497,7 +1410,7 @@ static void quantize_hdr_rgb( int a_lowbits = a_intval & 0xFF; int a_quantval = quant_color(quant_level, a_lowbits); - int a_uquantval = unquant_color(quant_level, a_quantval); + int a_uquantval = a_quantval; a_intval = (a_intval & ~0xFF) | a_uquantval; float a_fval = static_cast(a_intval) * mode_rscale; @@ -1518,12 +1431,11 @@ static void quantize_hdr_rgb( c_lowbits |= (a_intval & 0x100) >> 2; uint8_t c_quantval; - uint8_t c_uquantval; quantize_and_unquantize_retain_top_two_bits( - quant_level, static_cast(c_lowbits), c_quantval, c_uquantval); + quant_level, static_cast(c_lowbits), c_quantval); - c_intval = (c_intval & ~0x3F) | (c_uquantval & 0x3F); + c_intval = (c_intval & ~0x3F) | (c_quantval & 0x3F); c_fval = static_cast(c_intval) * mode_rscale; // Recompute B0 and B1, then quantize and unquantize them @@ -1587,16 +1499,14 @@ static void quantize_hdr_rgb( uint8_t b0_quantval; uint8_t b1_quantval; - uint8_t b0_uquantval; - uint8_t b1_uquantval; quantize_and_unquantize_retain_top_two_bits( - quant_level, static_cast(b0_lowbits), b0_quantval, b0_uquantval); + quant_level, static_cast(b0_lowbits), b0_quantval); quantize_and_unquantize_retain_top_two_bits( - quant_level, static_cast(b1_lowbits), b1_quantval, b1_uquantval); + quant_level, static_cast(b1_lowbits), b1_quantval); - b0_intval = (b0_intval & ~0x3f) | (b0_uquantval & 0x3f); - b1_intval = (b1_intval & ~0x3f) | (b1_uquantval & 0x3f); + b0_intval = (b0_intval & ~0x3f) | (b0_quantval & 0x3f); + b1_intval = (b1_intval & ~0x3f) | (b1_quantval & 0x3f); b0_fval = static_cast(b0_intval) * mode_rscale; b1_fval = static_cast(b1_intval) * mode_rscale; @@ -1684,13 +1594,11 @@ static void quantize_hdr_rgb( uint8_t d0_quantval; uint8_t d1_quantval; - uint8_t d0_uquantval; - uint8_t d1_uquantval; quantize_and_unquantize_retain_top_four_bits( - quant_level, static_cast(d0_lowbits), d0_quantval, d0_uquantval); + quant_level, static_cast(d0_lowbits), d0_quantval); quantize_and_unquantize_retain_top_four_bits( - quant_level, static_cast(d1_lowbits), d1_quantval, d1_uquantval); + quant_level, static_cast(d1_lowbits), d1_quantval); output[0] = static_cast(a_quantval); output[1] = c_quantval; @@ -1726,10 +1634,9 @@ static void quantize_hdr_rgb( for (int i = 4; i < 6; i++) { - uint8_t dummy; int idx = astc::flt2int_rtn(vals[i] * 1.0f / 512.0f) + 128; quantize_and_unquantize_retain_top_two_bits( - quant_level, static_cast(idx), output[i], dummy); + quant_level, static_cast(idx), output[i]); } return; @@ -1881,7 +1788,7 @@ static bool try_quantize_hdr_luminance_small_range( v0 = lowval & 0x7F; v0e = quant_color(quant_level, v0); - v0d = unquant_color(quant_level, v0e); + v0d = v0e; if (v0d < 0x80) { @@ -1891,7 +1798,7 @@ static bool try_quantize_hdr_luminance_small_range( { v1 = ((lowval >> 3) & 0xF0) | diffval; v1e = quant_color(quant_level, v1); - v1d = unquant_color(quant_level, v1e); + v1d = v1e; if ((v1d & 0xF0) == (v1 & 0xF0)) { output[0] = static_cast(v0e); @@ -1910,7 +1817,7 @@ static bool try_quantize_hdr_luminance_small_range( v0 = (lowval & 0x7F) | 0x80; v0e = quant_color(quant_level, v0); - v0d = unquant_color(quant_level, v0e); + v0d = v0e; if ((v0d & 0x80) == 0) { return false; @@ -1925,7 +1832,7 @@ static bool try_quantize_hdr_luminance_small_range( v1 = ((lowval >> 2) & 0xE0) | diffval; v1e = quant_color(quant_level, v1); - v1d = unquant_color(quant_level, v1e); + v1d = v1e; if ((v1d & 0xE0) != (v1 & 0xE0)) { return false; @@ -1969,7 +1876,7 @@ static void quantize_hdr_alpha( v6 = (val0 & 0x7F) | ((i & 1) << 7); v6e = quant_color(quant_level, v6); - v6d = unquant_color(quant_level, v6e); + v6d = v6e; if ((v6 ^ v6d) & 0x80) { @@ -1988,7 +1895,7 @@ static void quantize_hdr_alpha( v7 = ((i & 2) << 6) | ((val0 >> 7) << (6 - i)) | (diffval & mask); v7e = quant_color(quant_level, v7); - v7d = unquant_color(quant_level, v7e); + v7d = v7e; static const int testbits[3] { 0xE0, 0xF0, 0xF8 }; diff --git a/3rdparty/astc-encoder/source/astcenc_color_unquantize.cpp b/3rdparty/astc-encoder/source/astcenc_color_unquantize.cpp index 203615c..d31895a 100644 --- a/3rdparty/astc-encoder/source/astcenc_color_unquantize.cpp +++ b/3rdparty/astc-encoder/source/astcenc_color_unquantize.cpp @@ -23,43 +23,6 @@ #include "astcenc_internal.h" -/** - * @brief Unquantize a color. - * - * This function uses a lookup table as the quantization is encoded to make - * hardware implementations easier, and is not a simple lerp. - * - * @param quant_level The quantization level to use. - * @param inputq The input quantized color. - * - * @return The unquantized color. - */ -static ASTCENC_SIMD_INLINE vint4 unquant_color( - quant_method quant_level, - vint4 inputq -) { - const uint8_t* unq = color_unquant_tables[quant_level - QUANT_6]; - return vint4(unq[inputq.lane<0>()], unq[inputq.lane<1>()], - unq[inputq.lane<2>()], unq[inputq.lane<3>()]); -} - -/** - * @brief Determine the quantized value given a quantization level. - * - * @param quant_level The quantization level to use. - * @param value The value to convert. This may be outside of the 0-255 range and will be - * clamped before the value is looked up. - * - * @return The encoded quantized value. These are not necessarily in order; the compressor - * scrambles the values slightly to make hardware implementation easier. - */ -static inline uint8_t unquant_color( - quant_method quant_level, - int value -) { - return color_unquant_tables[quant_level - QUANT_6][value]; -} - /** * @brief Un-blue-contract a color. * @@ -80,23 +43,17 @@ static ASTCENC_SIMD_INLINE vint4 uncontract_color( /** * @brief Unpack an LDR RGBA color that uses delta encoding. * - * @param input0q The raw quantized endpoint 0 color. - * @param input1q The raw quantized endpoint 1 color deltas. - * @param quant_level The quantization level to use. - * @param[out] output0 The unpacked and unquantized endpoint 0 color. - * @param[out] output1 The unpacked and unquantized endpoint 1 color. + * @param input0 The packed endpoint 0 color. + * @param input1 The packed endpoint 1 color deltas. + * @param[out] output0 The unpacked endpoint 0 color. + * @param[out] output1 The unpacked endpoint 1 color. */ static void rgba_delta_unpack( - vint4 input0q, - vint4 input1q, - quant_method quant_level, + vint4 input0, + vint4 input1, vint4& output0, vint4& output1 ) { - // Unquantize color endpoints - vint4 input0 = unquant_color(quant_level, input0q); - vint4 input1 = unquant_color(quant_level, input1q); - // Apply bit transfer bit_transfer_signed(input1, input0); @@ -119,20 +76,18 @@ static void rgba_delta_unpack( * * Output alpha set to 255. * - * @param input0q The raw quantized endpoint 0 color. - * @param input1q The raw quantized endpoint 1 color deltas. - * @param quant_level The quantization level to use. - * @param[out] output0 The unpacked and unquantized endpoint 0 color. - * @param[out] output1 The unpacked and unquantized endpoint 1 color. + * @param input0 The packed endpoint 0 color. + * @param input1 The packed endpoint 1 color deltas. + * @param[out] output0 The unpacked endpoint 0 color. + * @param[out] output1 The unpacked endpoint 1 color. */ static void rgb_delta_unpack( - vint4 input0q, - vint4 input1q, - quant_method quant_level, + vint4 input0, + vint4 input1, vint4& output0, vint4& output1 ) { - rgba_delta_unpack(input0q, input1q, quant_level, output0, output1); + rgba_delta_unpack(input0, input1, output0, output1); output0.set_lane<3>(255); output1.set_lane<3>(255); } @@ -140,23 +95,17 @@ static void rgb_delta_unpack( /** * @brief Unpack an LDR RGBA color that uses direct encoding. * - * @param input0q The raw quantized endpoint 0 color. - * @param input1q The raw quantized endpoint 1 color. - * @param quant_level The quantization level to use. - * @param[out] output0 The unpacked and unquantized endpoint 0 color. - * @param[out] output1 The unpacked and unquantized endpoint 1 color. + * @param input0 The packed endpoint 0 color. + * @param input1 The packed endpoint 1 color. + * @param[out] output0 The unpacked endpoint 0 color. + * @param[out] output1 The unpacked endpoint 1 color. */ static void rgba_unpack( - vint4 input0q, - vint4 input1q, - quant_method quant_level, + vint4 input0, + vint4 input1, vint4& output0, vint4& output1 ) { - // Unquantize color endpoints - vint4 input0 = unquant_color(quant_level, input0q); - vint4 input1 = unquant_color(quant_level, input1q); - // Apply blue-uncontraction if needed if (hadd_rgb_s(input0) > hadd_rgb_s(input1)) { @@ -174,20 +123,18 @@ static void rgba_unpack( * * Output alpha set to 255. * - * @param input0q The raw quantized endpoint 0 color. - * @param input1q The raw quantized endpoint 1 color. - * @param quant_level The quantization level to use. - * @param[out] output0 The unpacked and unquantized endpoint 0 color. - * @param[out] output1 The unpacked and unquantized endpoint 1 color. + * @param input0 The packed endpoint 0 color. + * @param input1 The packed endpoint 1 color. + * @param[out] output0 The unpacked endpoint 0 color. + * @param[out] output1 The unpacked endpoint 1 color. */ static void rgb_unpack( - vint4 input0q, - vint4 input1q, - quant_method quant_level, + vint4 input0, + vint4 input1, vint4& output0, vint4& output1 ) { - rgba_unpack(input0q, input1q, quant_level, output0, output1); + rgba_unpack(input0, input1, output0, output1); output0.set_lane<3>(255); output1.set_lane<3>(255); } @@ -197,31 +144,24 @@ static void rgb_unpack( * * Note only the RGB channels use the scaled encoding, alpha uses direct. * - * @param input0q The raw quantized endpoint 0 color. - * @param alpha1q The raw quantized endpoint 1 alpha value. - * @param scaleq The raw quantized scale. - * @param quant_level The quantization level to use. - * @param[out] output0 The unpacked and unquantized endpoint 0 color. - * @param[out] output1 The unpacked and unquantized endpoint 1 color. + * @param input0 The packed endpoint 0 color. + * @param alpha1 The packed endpoint 1 alpha value. + * @param scale The packed quantized scale. + * @param[out] output0 The unpacked endpoint 0 color. + * @param[out] output1 The unpacked endpoint 1 color. */ static void rgb_scale_alpha_unpack( - vint4 input0q, - uint8_t alpha1q, - uint8_t scaleq, - quant_method quant_level, + vint4 input0, + uint8_t alpha1, + uint8_t scale, vint4& output0, vint4& output1 ) { - // Unquantize color endpoints - vint4 input = unquant_color(quant_level, input0q); - uint8_t alpha1 = unquant_color(quant_level, alpha1q); - uint8_t scale = unquant_color(quant_level, scaleq); - - output1 = input; + output1 = input0; output1.set_lane<3>(alpha1); - output0 = asr<8>(input * scale); - output0.set_lane<3>(input.lane<3>()); + output0 = asr<8>(input0 * scale); + output0.set_lane<3>(input0.lane<3>()); } /** @@ -229,26 +169,21 @@ static void rgb_scale_alpha_unpack( * * Output alpha is 255. * - * @param input0q The raw quantized endpoint 0 color. - * @param scaleq The raw quantized scale. - * @param quant_level The quantization level to use. - * @param[out] output0 The unpacked and unquantized endpoint 0 color. - * @param[out] output1 The unpacked and unquantized endpoint 1 color. + * @param input0 The packed endpoint 0 color. + * @param scale The packed scale. + * @param[out] output0 The unpacked endpoint 0 color. + * @param[out] output1 The unpacked endpoint 1 color. */ static void rgb_scale_unpack( - vint4 input0q, - int scaleq, - quant_method quant_level, + vint4 input0, + int scale, vint4& output0, vint4& output1 ) { - vint4 input = unquant_color(quant_level, input0q); - int scale = unquant_color(quant_level, scaleq); - - output1 = input; + output1 = input0; output1.set_lane<3>(255); - output0 = asr<8>(input * scale); + output0 = asr<8>(input0 * scale); output0.set_lane<3>(255); } @@ -257,19 +192,17 @@ static void rgb_scale_unpack( * * Output alpha is 255. * - * @param input The raw quantized endpoints. - * @param quant_level The quantization level to use. - * @param[out] output0 The unpacked and unquantized endpoint 0 color. - * @param[out] output1 The unpacked and unquantized endpoint 1 color. + * @param input The packed endpoints. + * @param[out] output0 The unpacked endpoint 0 color. + * @param[out] output1 The unpacked endpoint 1 color. */ static void luminance_unpack( const uint8_t input[2], - quant_method quant_level, vint4& output0, vint4& output1 ) { - int lum0 = unquant_color(quant_level, input[0]); - int lum1 = unquant_color(quant_level, input[1]); + int lum0 = input[0]; + int lum1 = input[1]; output0 = vint4(lum0, lum0, lum0, 255); output1 = vint4(lum1, lum1, lum1, 255); } @@ -279,19 +212,17 @@ static void luminance_unpack( * * Output alpha is 255. * - * @param input The raw quantized endpoints (L0, L1). - * @param quant_level The quantization level to use. - * @param[out] output0 The unpacked and unquantized endpoint 0 color. - * @param[out] output1 The unpacked and unquantized endpoint 1 color. + * @param input The packed endpoints (L0, L1). + * @param[out] output0 The unpacked endpoint 0 color. + * @param[out] output1 The unpacked endpoint 1 color. */ static void luminance_delta_unpack( const uint8_t input[2], - quant_method quant_level, vint4& output0, vint4& output1 ) { - int v0 = unquant_color(quant_level, input[0]); - int v1 = unquant_color(quant_level, input[1]); + int v0 = input[0]; + int v1 = input[1]; int l0 = (v0 >> 2) | (v1 & 0xC0); int l1 = l0 + (v1 & 0x3F); @@ -304,21 +235,19 @@ static void luminance_delta_unpack( /** * @brief Unpack an LDR LA color that uses direct encoding. * - * @param input The raw quantized endpoints (L0, L1, A0, A1). - * @param quant_level The quantization level to use. - * @param[out] output0 The unpacked and unquantized endpoint 0 color. - * @param[out] output1 The unpacked and unquantized endpoint 1 color. + * @param input The packed endpoints (L0, L1, A0, A1). + * @param[out] output0 The unpacked endpoint 0 color. + * @param[out] output1 The unpacked endpoint 1 color. */ static void luminance_alpha_unpack( const uint8_t input[4], - quant_method quant_level, vint4& output0, vint4& output1 ) { - int lum0 = unquant_color(quant_level, input[0]); - int lum1 = unquant_color(quant_level, input[1]); - int alpha0 = unquant_color(quant_level, input[2]); - int alpha1 = unquant_color(quant_level, input[3]); + int lum0 = input[0]; + int lum1 = input[1]; + int alpha0 = input[2]; + int alpha1 = input[3]; output0 = vint4(lum0, lum0, lum0, alpha0); output1 = vint4(lum1, lum1, lum1, alpha1); } @@ -326,30 +255,34 @@ static void luminance_alpha_unpack( /** * @brief Unpack an LDR LA color that uses delta encoding. * - * @param input The raw quantized endpoints (L0, L1, A0, A1). - * @param quant_level The quantization level to use. - * @param[out] output0 The unpacked and unquantized endpoint 0 color. - * @param[out] output1 The unpacked and unquantized endpoint 1 color. + * @param input The packed endpoints (L0, L1, A0, A1). + * @param[out] output0 The unpacked endpoint 0 color. + * @param[out] output1 The unpacked endpoint 1 color. */ static void luminance_alpha_delta_unpack( const uint8_t input[4], - quant_method quant_level, vint4& output0, vint4& output1 ) { - int lum0 = unquant_color(quant_level, input[0]); - int lum1 = unquant_color(quant_level, input[1]); - int alpha0 = unquant_color(quant_level, input[2]); - int alpha1 = unquant_color(quant_level, input[3]); + int lum0 = input[0]; + int lum1 = input[1]; + int alpha0 = input[2]; + int alpha1 = input[3]; lum0 |= (lum1 & 0x80) << 1; alpha0 |= (alpha1 & 0x80) << 1; lum1 &= 0x7F; alpha1 &= 0x7F; + if (lum1 & 0x40) + { lum1 -= 0x80; + } + if (alpha1 & 0x40) + { alpha1 -= 0x80; + } lum0 >>= 1; lum1 >>= 1; @@ -368,21 +301,19 @@ static void luminance_alpha_delta_unpack( /** * @brief Unpack an HDR RGB + offset encoding. * - * @param input The raw quantized endpoints (packed and modal). - * @param quant_level The quantization level to use. - * @param[out] output0 The unpacked and unquantized endpoint 0 color. - * @param[out] output1 The unpacked and unquantized endpoint 1 color. + * @param input The packed endpoints (packed and modal). + * @param[out] output0 The unpacked endpoint 0 color. + * @param[out] output1 The unpacked endpoint 1 color. */ static void hdr_rgbo_unpack( const uint8_t input[4], - quant_method quant_level, vint4& output0, vint4& output1 ) { - int v0 = unquant_color(quant_level, input[0]); - int v1 = unquant_color(quant_level, input[1]); - int v2 = unquant_color(quant_level, input[2]); - int v3 = unquant_color(quant_level, input[3]); + int v0 = input[0]; + int v1 = input[1]; + int v2 = input[2]; + int v3 = input[3]; int modeval = ((v0 & 0xC0) >> 6) | (((v1 & 0x80) >> 7) << 2) | (((v2 & 0x80) >> 7) << 3); @@ -520,24 +451,22 @@ static void hdr_rgbo_unpack( /** * @brief Unpack an HDR RGB direct encoding. * - * @param input The raw quantized endpoints (packed and modal). - * @param quant_level The quantization level to use. - * @param[out] output0 The unpacked and unquantized endpoint 0 color. - * @param[out] output1 The unpacked and unquantized endpoint 1 color. + * @param input The packed endpoints (packed and modal). + * @param[out] output0 The unpacked endpoint 0 color. + * @param[out] output1 The unpacked endpoint 1 color. */ static void hdr_rgb_unpack( const uint8_t input[6], - quant_method quant_level, vint4& output0, vint4& output1 ) { - int v0 = unquant_color(quant_level, input[0]); - int v1 = unquant_color(quant_level, input[1]); - int v2 = unquant_color(quant_level, input[2]); - int v3 = unquant_color(quant_level, input[3]); - int v4 = unquant_color(quant_level, input[4]); - int v5 = unquant_color(quant_level, input[5]); + int v0 = input[0]; + int v1 = input[1]; + int v2 = input[2]; + int v3 = input[3]; + int v4 = input[4]; + int v5 = input[5]; // extract all the fixed-placement bitfields int modeval = ((v1 & 0x80) >> 7) | (((v2 & 0x80) >> 7) << 1) | (((v3 & 0x80) >> 7) << 2); @@ -688,21 +617,19 @@ static void hdr_rgb_unpack( /** * @brief Unpack an HDR RGB + LDR A direct encoding. * - * @param input The raw quantized endpoints (packed and modal). - * @param quant_level The quantization level to use. - * @param[out] output0 The unpacked and unquantized endpoint 0 color. - * @param[out] output1 The unpacked and unquantized endpoint 1 color. + * @param input The packed endpoints (packed and modal). + * @param[out] output0 The unpacked endpoint 0 color. + * @param[out] output1 The unpacked endpoint 1 color. */ static void hdr_rgb_ldr_alpha_unpack( const uint8_t input[8], - quant_method quant_level, vint4& output0, vint4& output1 ) { - hdr_rgb_unpack(input, quant_level, output0, output1); + hdr_rgb_unpack(input, output0, output1); - int v6 = unquant_color(quant_level, input[6]); - int v7 = unquant_color(quant_level, input[7]); + int v6 = input[6]; + int v7 = input[7]; output0.set_lane<3>(v6); output1.set_lane<3>(v7); } @@ -710,19 +637,17 @@ static void hdr_rgb_ldr_alpha_unpack( /** * @brief Unpack an HDR L (small range) direct encoding. * - * @param input The raw quantized endpoints (packed and modal). - * @param quant_level The quantization level to use. - * @param[out] output0 The unpacked and unquantized endpoint 0 color. - * @param[out] output1 The unpacked and unquantized endpoint 1 color. + * @param input The packed endpoints (packed and modal). + * @param[out] output0 The unpacked endpoint 0 color. + * @param[out] output1 The unpacked endpoint 1 color. */ static void hdr_luminance_small_range_unpack( const uint8_t input[2], - quant_method quant_level, vint4& output0, vint4& output1 ) { - int v0 = unquant_color(quant_level, input[0]); - int v1 = unquant_color(quant_level, input[1]); + int v0 = input[0]; + int v1 = input[1]; int y0, y1; if (v0 & 0x80) @@ -738,7 +663,9 @@ static void hdr_luminance_small_range_unpack( y1 += y0; if (y1 > 0xFFF) + { y1 = 0xFFF; + } output0 = vint4(y0 << 4, y0 << 4, y0 << 4, 0x7800); output1 = vint4(y1 << 4, y1 << 4, y1 << 4, 0x7800); @@ -747,19 +674,17 @@ static void hdr_luminance_small_range_unpack( /** * @brief Unpack an HDR L (large range) direct encoding. * - * @param input The raw quantized endpoints (packed and modal). - * @param quant_level The quantization level to use. - * @param[out] output0 The unpacked and unquantized endpoint 0 color. - * @param[out] output1 The unpacked and unquantized endpoint 1 color. + * @param input The packed endpoints (packed and modal). + * @param[out] output0 The unpacked endpoint 0 color. + * @param[out] output1 The unpacked endpoint 1 color. */ static void hdr_luminance_large_range_unpack( const uint8_t input[2], - quant_method quant_level, vint4& output0, vint4& output1 ) { - int v0 = unquant_color(quant_level, input[0]); - int v1 = unquant_color(quant_level, input[1]); + int v0 = input[0]; + int v1 = input[1]; int y0, y1; if (v1 >= v0) @@ -780,20 +705,18 @@ static void hdr_luminance_large_range_unpack( /** * @brief Unpack an HDR A direct encoding. * - * @param input The raw quantized endpoints (packed and modal). - * @param quant_level The quantization level to use. - * @param[out] output0 The unpacked and unquantized endpoint 0 color. - * @param[out] output1 The unpacked and unquantized endpoint 1 color. + * @param input The packed endpoints (packed and modal). + * @param[out] output0 The unpacked endpoint 0 color. + * @param[out] output1 The unpacked endpoint 1 color. */ static void hdr_alpha_unpack( const uint8_t input[2], - quant_method quant_level, int& output0, int& output1 ) { - int v6 = unquant_color(quant_level, input[0]); - int v7 = unquant_color(quant_level, input[1]); + int v6 = input[0]; + int v7 = input[1]; int selector = ((v6 >> 7) & 1) | ((v7 >> 6) & 2); v6 &= 0x7F; @@ -814,9 +737,13 @@ static void hdr_alpha_unpack( v7 += v6; if (v7 < 0) + { v7 = 0; + } else if (v7 > 0xFFF) + { v7 = 0xFFF; + } output0 = v6; output1 = v7; @@ -829,21 +756,19 @@ static void hdr_alpha_unpack( /** * @brief Unpack an HDR RGBA direct encoding. * - * @param input The raw quantized endpoints (packed and modal). - * @param quant_level The quantization level to use. - * @param[out] output0 The unpacked and unquantized endpoint 0 color. - * @param[out] output1 The unpacked and unquantized endpoint 1 color. + * @param input The packed endpoints (packed and modal). + * @param[out] output0 The unpacked endpoint 0 color. + * @param[out] output1 The unpacked endpoint 1 color. */ static void hdr_rgb_hdr_alpha_unpack( const uint8_t input[8], - quant_method quant_level, vint4& output0, vint4& output1 ) { - hdr_rgb_unpack(input, quant_level, output0, output1); + hdr_rgb_unpack(input, output0, output1); int alpha0, alpha1; - hdr_alpha_unpack(input + 6, quant_level, alpha0, alpha1); + hdr_alpha_unpack(input + 6, alpha0, alpha1); output0.set_lane<3>(alpha0); output1.set_lane<3>(alpha1); @@ -853,7 +778,6 @@ static void hdr_rgb_hdr_alpha_unpack( void unpack_color_endpoints( astcenc_profile decode_mode, int format, - quant_method quant_level, const uint8_t* input, bool& rgb_hdr, bool& alpha_hdr, @@ -869,38 +793,38 @@ void unpack_color_endpoints( switch (format) { case FMT_LUMINANCE: - luminance_unpack(input, quant_level, output0, output1); + luminance_unpack(input, output0, output1); break; case FMT_LUMINANCE_DELTA: - luminance_delta_unpack(input, quant_level, output0, output1); + luminance_delta_unpack(input, output0, output1); break; case FMT_HDR_LUMINANCE_SMALL_RANGE: rgb_hdr = true; alpha_hdr_default = true; - hdr_luminance_small_range_unpack(input, quant_level, output0, output1); + hdr_luminance_small_range_unpack(input, output0, output1); break; case FMT_HDR_LUMINANCE_LARGE_RANGE: rgb_hdr = true; alpha_hdr_default = true; - hdr_luminance_large_range_unpack(input, quant_level, output0, output1); + hdr_luminance_large_range_unpack(input, output0, output1); break; case FMT_LUMINANCE_ALPHA: - luminance_alpha_unpack(input, quant_level, output0, output1); + luminance_alpha_unpack(input, output0, output1); break; case FMT_LUMINANCE_ALPHA_DELTA: - luminance_alpha_delta_unpack(input, quant_level, output0, output1); + luminance_alpha_delta_unpack(input, output0, output1); break; case FMT_RGB_SCALE: { vint4 input0q(input[0], input[1], input[2], 0); uint8_t scale = input[3]; - rgb_scale_unpack(input0q, scale, quant_level, output0, output1); + rgb_scale_unpack(input0q, scale, output0, output1); } break; @@ -909,21 +833,21 @@ void unpack_color_endpoints( vint4 input0q(input[0], input[1], input[2], input[4]); uint8_t alpha1q = input[5]; uint8_t scaleq = input[3]; - rgb_scale_alpha_unpack(input0q, alpha1q, scaleq, quant_level, output0, output1); + rgb_scale_alpha_unpack(input0q, alpha1q, scaleq, output0, output1); } break; case FMT_HDR_RGB_SCALE: rgb_hdr = true; alpha_hdr_default = true; - hdr_rgbo_unpack(input, quant_level,output0, output1); + hdr_rgbo_unpack(input, output0, output1); break; case FMT_RGB: { vint4 input0q(input[0], input[2], input[4], 0); vint4 input1q(input[1], input[3], input[5], 0); - rgb_unpack(input0q, input1q, quant_level, output0, output1); + rgb_unpack(input0q, input1q, output0, output1); } break; @@ -931,21 +855,21 @@ void unpack_color_endpoints( { vint4 input0q(input[0], input[2], input[4], 0); vint4 input1q(input[1], input[3], input[5], 0); - rgb_delta_unpack(input0q, input1q, quant_level, output0, output1); + rgb_delta_unpack(input0q, input1q, output0, output1); } break; case FMT_HDR_RGB: rgb_hdr = true; alpha_hdr_default = true; - hdr_rgb_unpack(input, quant_level, output0, output1); + hdr_rgb_unpack(input, output0, output1); break; case FMT_RGBA: { vint4 input0q(input[0], input[2], input[4], input[6]); vint4 input1q(input[1], input[3], input[5], input[7]); - rgba_unpack(input0q, input1q, quant_level, output0, output1); + rgba_unpack(input0q, input1q, output0, output1); } break; @@ -953,19 +877,19 @@ void unpack_color_endpoints( { vint4 input0q(input[0], input[2], input[4], input[6]); vint4 input1q(input[1], input[3], input[5], input[7]); - rgba_delta_unpack(input0q, input1q, quant_level, output0, output1); + rgba_delta_unpack(input0q, input1q, output0, output1); } break; case FMT_HDR_RGB_LDR_ALPHA: rgb_hdr = true; - hdr_rgb_ldr_alpha_unpack(input, quant_level, output0, output1); + hdr_rgb_ldr_alpha_unpack(input, output0, output1); break; case FMT_HDR_RGBA: rgb_hdr = true; alpha_hdr = true; - hdr_rgb_hdr_alpha_unpack(input, quant_level, output0, output1); + hdr_rgb_hdr_alpha_unpack(input, output0, output1); break; } diff --git a/3rdparty/astc-encoder/source/astcenc_compress_symbolic.cpp b/3rdparty/astc-encoder/source/astcenc_compress_symbolic.cpp index 68bde08..4dbe6f1 100644 --- a/3rdparty/astc-encoder/source/astcenc_compress_symbolic.cpp +++ b/3rdparty/astc-encoder/source/astcenc_compress_symbolic.cpp @@ -99,7 +99,6 @@ static bool realign_weights_undecimated( { unpack_color_endpoints(decode_mode, scb.color_formats[pa_idx], - scb.get_color_quant_mode(), scb.color_values[pa_idx], rgb_hdr, alpha_hdr, endpnt0[pa_idx], @@ -225,7 +224,6 @@ static bool realign_weights_decimated( { unpack_color_endpoints(decode_mode, scb.color_formats[pa_idx], - scb.get_color_quant_mode(), scb.color_values[pa_idx], rgb_hdr, alpha_hdr, endpnt0[pa_idx], diff --git a/3rdparty/astc-encoder/source/astcenc_decompress_symbolic.cpp b/3rdparty/astc-encoder/source/astcenc_decompress_symbolic.cpp index 02c91af..8be222b 100644 --- a/3rdparty/astc-encoder/source/astcenc_decompress_symbolic.cpp +++ b/3rdparty/astc-encoder/source/astcenc_decompress_symbolic.cpp @@ -299,7 +299,6 @@ void decompress_symbolic_block( unpack_color_endpoints(decode_mode, scb.color_formats[i], - scb.get_color_quant_mode(), scb.color_values[i], rgb_lns, a_lns, ep0, ep1); @@ -362,7 +361,6 @@ float compute_symbolic_block_difference_2plane( unpack_color_endpoints(config.profile, scb.color_formats[0], - scb.get_color_quant_mode(), scb.color_values[0], rgb_lns, a_lns, ep0, ep1); @@ -457,7 +455,6 @@ float compute_symbolic_block_difference_1plane( unpack_color_endpoints(config.profile, scb.color_formats[i], - scb.get_color_quant_mode(), scb.color_values[i], rgb_lns, a_lns, ep0, ep1); @@ -546,7 +543,6 @@ float compute_symbolic_block_difference_1plane_1partition( unpack_color_endpoints(config.profile, scb.color_formats[0], - scb.get_color_quant_mode(), scb.color_values[0], rgb_lns, a_lns, ep0, ep1); diff --git a/3rdparty/astc-encoder/source/astcenc_entry.cpp b/3rdparty/astc-encoder/source/astcenc_entry.cpp index 6491c4e..95125b3 100644 --- a/3rdparty/astc-encoder/source/astcenc_entry.cpp +++ b/3rdparty/astc-encoder/source/astcenc_entry.cpp @@ -1357,7 +1357,6 @@ astcenc_error astcenc_get_block_info( unpack_color_endpoints(ctx->config.profile, scb.color_formats[i], - scb.get_color_quant_mode(), scb.color_values[i], rgb_hdr, a_hdr, endpnt[0], endpnt[1]); diff --git a/3rdparty/astc-encoder/source/astcenc_find_best_partitioning.cpp b/3rdparty/astc-encoder/source/astcenc_find_best_partitioning.cpp index c9e1835..c59e093 100644 --- a/3rdparty/astc-encoder/source/astcenc_find_best_partitioning.cpp +++ b/3rdparty/astc-encoder/source/astcenc_find_best_partitioning.cpp @@ -536,7 +536,7 @@ unsigned int find_best_partition_candidates( const image_block& blk, unsigned int partition_count, unsigned int partition_search_limit, - unsigned int best_partitions[BLOCK_MAX_PARTITIONINGS], + unsigned int best_partitions[TUNE_MAX_PARTITIIONING_CANDIDATES], unsigned int requested_candidates ) { // Constant used to estimate quantization error for a given partitioning; the optimal value for diff --git a/3rdparty/astc-encoder/source/astcenc_ideal_endpoints_and_weights.cpp b/3rdparty/astc-encoder/source/astcenc_ideal_endpoints_and_weights.cpp index 23483a3..3c18e87 100644 --- a/3rdparty/astc-encoder/source/astcenc_ideal_endpoints_and_weights.cpp +++ b/3rdparty/astc-encoder/source/astcenc_ideal_endpoints_and_weights.cpp @@ -691,7 +691,6 @@ float compute_error_of_weight_set_1plane( const float* dec_weight_quant_uvalue ) { vfloatacc error_summav = vfloatacc::zero(); - float error_summa = 0.0f; unsigned int texel_count = di.texel_count; // Process SIMD-width chunks, safe to over-fetch - the extra space is zero initialized @@ -745,7 +744,7 @@ float compute_error_of_weight_set_1plane( } // Resolve the final scalar accumulator sum - return error_summa = hadd_s(error_summav); + return hadd_s(error_summav); } /* See header for documentation. */ diff --git a/3rdparty/astc-encoder/source/astcenc_internal.h b/3rdparty/astc-encoder/source/astcenc_internal.h index 6ec395f..0fa8ec6 100644 --- a/3rdparty/astc-encoder/source/astcenc_internal.h +++ b/3rdparty/astc-encoder/source/astcenc_internal.h @@ -1322,20 +1322,32 @@ bool is_legal_3d_block_size( /** * @brief The precomputed table for quantizing color values. * - * Returned value is in the ASTC BISE scrambled order. + * Converts unquant value in 0-255 range into quant value in 0-255 range. + * No BISE scrambling is applied at this stage. * * Indexed by [quant_mode - 4][data_value]. */ -extern const uint8_t color_quant_tables[17][256]; +extern const uint8_t color_unquant_to_uquant_tables[17][256]; /** - * @brief The precomputed table for unquantizing color values. + * @brief The precomputed table for packing quantized color values. * - * Returned value is in the ASTC BISE scrambled order. + * Converts quant value in 0-255 range into packed quant value in 0-N range, + * with BISE scrambling applied. * * Indexed by [quant_mode - 4][data_value]. */ -extern const uint8_t color_unquant_tables[17][256]; +extern const uint8_t color_uquant_to_scrambled_pquant_tables[17][256]; + +/** + * @brief The precomputed table for unpacking color values. + * + * Converts quant value in 0-N range into unpacked value in 0-255 range, + * with BISE unscrambling applied. + * + * Indexed by [quant_mode - 4][data_value]. + */ +extern const uint8_t* color_scrambled_pquant_to_uquant_tables[17]; /** * @brief The precomputed quant mode storage table. @@ -1532,8 +1544,8 @@ void compute_error_squared_rgba( * @param partition_count The number of partitions in the block. * @param partition_search_limit The number of candidate partition encodings to trial. * @param[out] best_partitions The best partition candidates. - * @param requested_candidates The number of requsted partitionings. May return fewer if - * candidates are not avaiable. + * @param requested_candidates The number of requested partitionings. May return fewer if + * candidates are not available. * * @return The actual number of candidates returned. */ @@ -1798,11 +1810,12 @@ uint8_t pack_color_endpoints( quant_method quant_level); /** - * @brief Unpack a single pair of encoded and quantized color endpoints. + * @brief Unpack a single pair of encoded endpoints. + * + * Endpoints must be unscrambled and converted into the 0-255 range before calling this functions. * * @param decode_mode The decode mode (LDR, HDR). * @param format The color endpoint mode used. - * @param quant_level The quantization level used. * @param input The raw array of encoded input integers. The length of this array * depends on @c format; it can be safely assumed to be large enough. * @param[out] rgb_hdr Is the endpoint using HDR for the RGB channels? @@ -1813,7 +1826,6 @@ uint8_t pack_color_endpoints( void unpack_color_endpoints( astcenc_profile decode_mode, int format, - quant_method quant_level, const uint8_t* input, bool& rgb_hdr, bool& alpha_hdr, diff --git a/3rdparty/astc-encoder/source/astcenc_quantization.cpp b/3rdparty/astc-encoder/source/astcenc_quantization.cpp index da8367b..478a21e 100644 --- a/3rdparty/astc-encoder/source/astcenc_quantization.cpp +++ b/3rdparty/astc-encoder/source/astcenc_quantization.cpp @@ -23,305 +23,616 @@ #if !defined(ASTCENC_DECOMPRESS_ONLY) +// Starts from QUANT_6 +// Not scrambled +const uint8_t color_unquant_to_uquant_tables[17][256] { + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 51, 51, 51, 51, 51, 51, + 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, + 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, + 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 102, 102, 102, + 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, + 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, + 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, + 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, + 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, + 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, + 153, 153, 153, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, + 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, + 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, + 204, 204, 204, 204, 204, 204, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 + }, + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, + 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, + 36, 36, 36, 36, 36, 36, 36, 73, 73, 73, 73, 73, 73, 73, 73, 73, + 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, + 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 109, 109, 109, 109, + 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, + 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, + 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, + 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, + 146, 146, 146, 146, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, + 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, + 182, 182, 182, 182, 182, 182, 182, 182, 182, 219, 219, 219, 219, 219, 219, 219, + 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, + 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 219, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 + }, + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, + 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, + 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 84, 84, 84, 84, 84, 84, 84, 84, 84, + 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, + 84, 84, 84, 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, + 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, + 142, 142, 142, 142, 142, 142, 142, 142, 142, 142, 142, 142, 142, 142, 142, 142, + 142, 142, 142, 142, 142, 142, 142, 142, 142, 142, 142, 142, 142, 171, 171, 171, + 171, 171, 171, 171, 171, 171, 171, 171, 171, 171, 171, 171, 171, 171, 171, 171, + 171, 171, 171, 171, 171, 171, 171, 171, 171, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, + 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, 227, + 227, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 + }, + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, + 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 69, 69, 69, 69, 69, 69, + 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, + 69, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, + 92, 92, 92, 92, 92, 92, 92, 92, 92, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, + 139, 139, 139, 139, 139, 139, 139, 163, 163, 163, 163, 163, 163, 163, 163, 163, + 163, 163, 163, 163, 163, 163, 163, 163, 163, 163, 163, 163, 163, 163, 163, 186, + 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, + 186, 186, 186, 186, 186, 186, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, + 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 232, 232, 232, + 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, + 232, 232, 232, 232, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 + }, + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 34, 34, 34, 34, 34, 34, + 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 51, 51, 51, 51, 51, + 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 68, 68, 68, 68, + 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 85, 85, 85, + 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 102, 102, + 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 119, + 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, + 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, + 136, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, + 153, 153, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, + 170, 170, 170, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, + 187, 187, 187, 187, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, + 204, 204, 204, 204, 204, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221, 221, + 221, 221, 221, 221, 221, 221, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, + 238, 238, 238, 238, 238, 238, 238, 255, 255, 255, 255, 255, 255, 255, 255, 255 + }, + { + 0, 0, 0, 0, 0, 0, 0, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, + 27, 27, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, + 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 67, 67, 67, + 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, 94, 94, 94, 94, 94, 94, 94, 94, + 94, 94, 94, 94, 94, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, + 107, 107, 107, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, + 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 148, 148, 148, + 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 161, 161, 161, 161, 161, + 161, 161, 161, 161, 161, 161, 161, 161, 175, 175, 175, 175, 175, 175, 175, 175, + 175, 175, 175, 175, 175, 175, 188, 188, 188, 188, 188, 188, 188, 188, 188, 188, + 188, 188, 188, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, + 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 228, 228, + 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 242, 242, 242, 242, 242, + 242, 242, 242, 242, 242, 242, 242, 242, 242, 255, 255, 255, 255, 255, 255, 255 + }, + { + 0, 0, 0, 0, 0, 0, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, + 11, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 33, 33, 33, 33, + 33, 33, 33, 33, 33, 33, 33, 44, 44, 44, 44, 44, 44, 44, 44, 44, + 44, 44, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 66, 66, 66, + 66, 66, 66, 66, 66, 66, 66, 66, 77, 77, 77, 77, 77, 77, 77, 77, + 77, 77, 77, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 110, 110, 110, 110, 110, 110, 110, + 110, 110, 110, 110, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, + 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 134, 145, 145, 145, 145, + 145, 145, 145, 145, 145, 145, 145, 156, 156, 156, 156, 156, 156, 156, 156, 156, + 156, 156, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 178, 178, 178, + 178, 178, 178, 178, 178, 178, 178, 178, 189, 189, 189, 189, 189, 189, 189, 189, + 189, 189, 189, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 211, 211, + 211, 211, 211, 211, 211, 211, 211, 211, 211, 222, 222, 222, 222, 222, 222, 222, + 222, 222, 222, 222, 233, 233, 233, 233, 233, 233, 233, 233, 233, 233, 233, 244, + 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, 255, 255, 255, 255, 255, 255 + }, + { + 0, 0, 0, 0, 0, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, + 16, 16, 16, 16, 16, 24, 24, 24, 24, 24, 24, 24, 24, 33, 33, 33, + 33, 33, 33, 33, 33, 33, 41, 41, 41, 41, 41, 41, 41, 41, 49, 49, + 49, 49, 49, 49, 49, 49, 57, 57, 57, 57, 57, 57, 57, 57, 66, 66, + 66, 66, 66, 66, 66, 66, 66, 74, 74, 74, 74, 74, 74, 74, 74, 82, + 82, 82, 82, 82, 82, 82, 82, 90, 90, 90, 90, 90, 90, 90, 90, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 107, 107, 107, 107, 107, 107, 107, 107, + 115, 115, 115, 115, 115, 115, 115, 115, 123, 123, 123, 123, 123, 123, 123, 123, + 132, 132, 132, 132, 132, 132, 132, 132, 140, 140, 140, 140, 140, 140, 140, 140, + 148, 148, 148, 148, 148, 148, 148, 148, 156, 156, 156, 156, 156, 156, 156, 156, + 156, 165, 165, 165, 165, 165, 165, 165, 165, 173, 173, 173, 173, 173, 173, 173, + 173, 181, 181, 181, 181, 181, 181, 181, 181, 189, 189, 189, 189, 189, 189, 189, + 189, 189, 198, 198, 198, 198, 198, 198, 198, 198, 206, 206, 206, 206, 206, 206, + 206, 206, 214, 214, 214, 214, 214, 214, 214, 214, 222, 222, 222, 222, 222, 222, + 222, 222, 222, 231, 231, 231, 231, 231, 231, 231, 231, 239, 239, 239, 239, 239, + 239, 239, 239, 247, 247, 247, 247, 247, 247, 247, 247, 255, 255, 255, 255, 255 + }, + { + 0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 13, 13, 13, 13, 13, 13, + 13, 19, 19, 19, 19, 19, 19, 26, 26, 26, 26, 26, 26, 26, 32, 32, + 32, 32, 32, 32, 39, 39, 39, 39, 39, 39, 39, 45, 45, 45, 45, 45, + 45, 52, 52, 52, 52, 52, 52, 52, 58, 58, 58, 58, 58, 58, 65, 65, + 65, 65, 65, 65, 65, 71, 71, 71, 71, 71, 71, 78, 78, 78, 78, 78, + 78, 78, 84, 84, 84, 84, 84, 84, 91, 91, 91, 91, 91, 91, 91, 97, + 97, 97, 97, 97, 97, 104, 104, 104, 104, 104, 104, 104, 110, 110, 110, 110, + 110, 110, 117, 117, 117, 117, 117, 117, 117, 123, 123, 123, 123, 123, 123, 123, + 132, 132, 132, 132, 132, 132, 132, 138, 138, 138, 138, 138, 138, 138, 145, 145, + 145, 145, 145, 145, 151, 151, 151, 151, 151, 151, 151, 158, 158, 158, 158, 158, + 158, 164, 164, 164, 164, 164, 164, 164, 171, 171, 171, 171, 171, 171, 177, 177, + 177, 177, 177, 177, 177, 184, 184, 184, 184, 184, 184, 190, 190, 190, 190, 190, + 190, 190, 197, 197, 197, 197, 197, 197, 203, 203, 203, 203, 203, 203, 203, 210, + 210, 210, 210, 210, 210, 216, 216, 216, 216, 216, 216, 216, 223, 223, 223, 223, + 223, 223, 229, 229, 229, 229, 229, 229, 229, 236, 236, 236, 236, 236, 236, 242, + 242, 242, 242, 242, 242, 242, 249, 249, 249, 249, 249, 249, 255, 255, 255, 255 + }, + { + 0, 0, 0, 5, 5, 5, 5, 5, 5, 11, 11, 11, 11, 11, 16, 16, + 16, 16, 16, 21, 21, 21, 21, 21, 21, 27, 27, 27, 27, 27, 32, 32, + 32, 32, 32, 32, 38, 38, 38, 38, 38, 43, 43, 43, 43, 43, 48, 48, + 48, 48, 48, 48, 54, 54, 54, 54, 54, 59, 59, 59, 59, 59, 59, 65, + 65, 65, 65, 65, 70, 70, 70, 70, 70, 70, 76, 76, 76, 76, 76, 81, + 81, 81, 81, 81, 86, 86, 86, 86, 86, 86, 92, 92, 92, 92, 92, 97, + 97, 97, 97, 97, 97, 103, 103, 103, 103, 103, 108, 108, 108, 108, 108, 113, + 113, 113, 113, 113, 113, 119, 119, 119, 119, 119, 124, 124, 124, 124, 124, 124, + 131, 131, 131, 131, 131, 131, 136, 136, 136, 136, 136, 142, 142, 142, 142, 142, + 142, 147, 147, 147, 147, 147, 152, 152, 152, 152, 152, 158, 158, 158, 158, 158, + 158, 163, 163, 163, 163, 163, 169, 169, 169, 169, 169, 169, 174, 174, 174, 174, + 174, 179, 179, 179, 179, 179, 185, 185, 185, 185, 185, 185, 190, 190, 190, 190, + 190, 196, 196, 196, 196, 196, 196, 201, 201, 201, 201, 201, 207, 207, 207, 207, + 207, 207, 212, 212, 212, 212, 212, 217, 217, 217, 217, 217, 223, 223, 223, 223, + 223, 223, 228, 228, 228, 228, 228, 234, 234, 234, 234, 234, 234, 239, 239, 239, + 239, 239, 244, 244, 244, 244, 244, 250, 250, 250, 250, 250, 250, 255, 255, 255 + }, + { + 0, 0, 0, 4, 4, 4, 4, 8, 8, 8, 8, 12, 12, 12, 12, 16, + 16, 16, 16, 20, 20, 20, 20, 24, 24, 24, 24, 28, 28, 28, 28, 32, + 32, 32, 32, 36, 36, 36, 36, 40, 40, 40, 40, 44, 44, 44, 44, 48, + 48, 48, 48, 52, 52, 52, 52, 56, 56, 56, 56, 60, 60, 60, 60, 65, + 65, 65, 65, 65, 69, 69, 69, 69, 73, 73, 73, 73, 77, 77, 77, 77, + 81, 81, 81, 81, 85, 85, 85, 85, 89, 89, 89, 89, 93, 93, 93, 93, + 97, 97, 97, 97, 101, 101, 101, 101, 105, 105, 105, 105, 109, 109, 109, 109, + 113, 113, 113, 113, 117, 117, 117, 117, 121, 121, 121, 121, 125, 125, 125, 125, + 130, 130, 130, 130, 134, 134, 134, 134, 138, 138, 138, 138, 142, 142, 142, 142, + 146, 146, 146, 146, 150, 150, 150, 150, 154, 154, 154, 154, 158, 158, 158, 158, + 162, 162, 162, 162, 166, 166, 166, 166, 170, 170, 170, 170, 174, 174, 174, 174, + 178, 178, 178, 178, 182, 182, 182, 182, 186, 186, 186, 186, 190, 190, 190, 190, + 190, 195, 195, 195, 195, 199, 199, 199, 199, 203, 203, 203, 203, 207, 207, 207, + 207, 211, 211, 211, 211, 215, 215, 215, 215, 219, 219, 219, 219, 223, 223, 223, + 223, 227, 227, 227, 227, 231, 231, 231, 231, 235, 235, 235, 235, 239, 239, 239, + 239, 243, 243, 243, 243, 247, 247, 247, 247, 251, 251, 251, 251, 255, 255, 255 + }, + { + 0, 0, 3, 3, 3, 6, 6, 6, 9, 9, 9, 9, 13, 13, 13, 16, + 16, 16, 19, 19, 19, 22, 22, 22, 25, 25, 25, 25, 29, 29, 29, 32, + 32, 32, 35, 35, 35, 38, 38, 38, 38, 42, 42, 42, 45, 45, 45, 48, + 48, 48, 51, 51, 51, 54, 54, 54, 54, 58, 58, 58, 61, 61, 61, 64, + 64, 64, 67, 67, 67, 67, 71, 71, 71, 74, 74, 74, 77, 77, 77, 80, + 80, 80, 83, 83, 83, 83, 87, 87, 87, 90, 90, 90, 93, 93, 93, 96, + 96, 96, 96, 100, 100, 100, 103, 103, 103, 106, 106, 106, 109, 109, 109, 112, + 112, 112, 112, 116, 116, 116, 119, 119, 119, 122, 122, 122, 125, 125, 125, 125, + 130, 130, 130, 130, 133, 133, 133, 136, 136, 136, 139, 139, 139, 143, 143, 143, + 143, 146, 146, 146, 149, 149, 149, 152, 152, 152, 155, 155, 155, 159, 159, 159, + 159, 162, 162, 162, 165, 165, 165, 168, 168, 168, 172, 172, 172, 172, 175, 175, + 175, 178, 178, 178, 181, 181, 181, 184, 184, 184, 188, 188, 188, 188, 191, 191, + 191, 194, 194, 194, 197, 197, 197, 201, 201, 201, 201, 204, 204, 204, 207, 207, + 207, 210, 210, 210, 213, 213, 213, 217, 217, 217, 217, 220, 220, 220, 223, 223, + 223, 226, 226, 226, 230, 230, 230, 230, 233, 233, 233, 236, 236, 236, 239, 239, + 239, 242, 242, 242, 246, 246, 246, 246, 249, 249, 249, 252, 252, 252, 255, 255 + }, + { + 0, 0, 2, 2, 5, 5, 5, 8, 8, 8, 10, 10, 13, 13, 13, 16, + 16, 16, 18, 18, 21, 21, 21, 24, 24, 24, 26, 26, 29, 29, 29, 32, + 32, 32, 35, 35, 35, 37, 37, 40, 40, 40, 43, 43, 43, 45, 45, 48, + 48, 48, 51, 51, 51, 53, 53, 56, 56, 56, 59, 59, 59, 61, 61, 64, + 64, 64, 67, 67, 67, 70, 70, 70, 72, 72, 75, 75, 75, 78, 78, 78, + 80, 80, 83, 83, 83, 86, 86, 86, 88, 88, 91, 91, 91, 94, 94, 94, + 96, 96, 99, 99, 99, 102, 102, 102, 104, 104, 107, 107, 107, 110, 110, 110, + 112, 112, 115, 115, 115, 118, 118, 118, 120, 120, 123, 123, 123, 126, 126, 126, + 129, 129, 129, 132, 132, 132, 135, 135, 137, 137, 137, 140, 140, 140, 143, 143, + 145, 145, 145, 148, 148, 148, 151, 151, 153, 153, 153, 156, 156, 156, 159, 159, + 161, 161, 161, 164, 164, 164, 167, 167, 169, 169, 169, 172, 172, 172, 175, 175, + 177, 177, 177, 180, 180, 180, 183, 183, 185, 185, 185, 188, 188, 188, 191, 191, + 191, 194, 194, 196, 196, 196, 199, 199, 199, 202, 202, 204, 204, 204, 207, 207, + 207, 210, 210, 212, 212, 212, 215, 215, 215, 218, 218, 220, 220, 220, 223, 223, + 223, 226, 226, 226, 229, 229, 231, 231, 231, 234, 234, 234, 237, 237, 239, 239, + 239, 242, 242, 242, 245, 245, 247, 247, 247, 250, 250, 250, 253, 253, 255, 255 + }, + { + 0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, + 16, 16, 18, 18, 20, 20, 22, 22, 24, 24, 26, 26, 28, 28, 30, 30, + 32, 32, 34, 34, 36, 36, 38, 38, 40, 40, 42, 42, 44, 44, 46, 46, + 48, 48, 50, 50, 52, 52, 54, 54, 56, 56, 58, 58, 60, 60, 62, 62, + 64, 64, 66, 66, 68, 68, 70, 70, 72, 72, 74, 74, 76, 76, 78, 78, + 80, 80, 82, 82, 84, 84, 86, 86, 88, 88, 90, 90, 92, 92, 94, 94, + 96, 96, 98, 98, 100, 100, 102, 102, 104, 104, 106, 106, 108, 108, 110, 110, + 112, 112, 114, 114, 116, 116, 118, 118, 120, 120, 122, 122, 124, 124, 126, 126, + 129, 129, 131, 131, 133, 133, 135, 135, 137, 137, 139, 139, 141, 141, 143, 143, + 145, 145, 147, 147, 149, 149, 151, 151, 153, 153, 155, 155, 157, 157, 159, 159, + 161, 161, 163, 163, 165, 165, 167, 167, 169, 169, 171, 171, 173, 173, 175, 175, + 177, 177, 179, 179, 181, 181, 183, 183, 185, 185, 187, 187, 189, 189, 191, 191, + 193, 193, 195, 195, 197, 197, 199, 199, 201, 201, 203, 203, 205, 205, 207, 207, + 209, 209, 211, 211, 213, 213, 215, 215, 217, 217, 219, 219, 221, 221, 223, 223, + 225, 225, 227, 227, 229, 229, 231, 231, 233, 233, 235, 235, 237, 237, 239, 239, + 241, 241, 243, 243, 245, 245, 247, 247, 249, 249, 251, 251, 253, 253, 255, 255 + }, + { + 0, 1, 1, 3, 4, 4, 6, 6, 8, 9, 9, 11, 12, 12, 14, 14, + 16, 17, 17, 19, 20, 20, 22, 22, 24, 25, 25, 27, 28, 28, 30, 30, + 32, 33, 33, 35, 36, 36, 38, 38, 40, 41, 41, 43, 44, 44, 46, 46, + 48, 49, 49, 51, 52, 52, 54, 54, 56, 57, 57, 59, 60, 60, 62, 62, + 64, 65, 65, 67, 68, 68, 70, 70, 72, 73, 73, 75, 76, 76, 78, 78, + 80, 81, 81, 83, 84, 84, 86, 86, 88, 89, 89, 91, 92, 92, 94, 94, + 96, 97, 97, 99, 100, 100, 102, 102, 104, 105, 105, 107, 108, 108, 110, 110, + 112, 113, 113, 115, 116, 116, 118, 118, 120, 121, 121, 123, 124, 124, 126, 126, + 129, 129, 131, 131, 132, 134, 134, 135, 137, 137, 139, 139, 140, 142, 142, 143, + 145, 145, 147, 147, 148, 150, 150, 151, 153, 153, 155, 155, 156, 158, 158, 159, + 161, 161, 163, 163, 164, 166, 166, 167, 169, 169, 171, 171, 172, 174, 174, 175, + 177, 177, 179, 179, 180, 182, 182, 183, 185, 185, 187, 187, 188, 190, 190, 191, + 193, 193, 195, 195, 196, 198, 198, 199, 201, 201, 203, 203, 204, 206, 206, 207, + 209, 209, 211, 211, 212, 214, 214, 215, 217, 217, 219, 219, 220, 222, 222, 223, + 225, 225, 227, 227, 228, 230, 230, 231, 233, 233, 235, 235, 236, 238, 238, 239, + 241, 241, 243, 243, 244, 246, 246, 247, 249, 249, 251, 251, 252, 254, 254, 255 + }, + { + 0, 1, 2, 2, 4, 5, 6, 6, 8, 9, 10, 10, 12, 13, 14, 14, + 16, 17, 18, 18, 20, 21, 22, 22, 24, 25, 26, 26, 28, 29, 30, 30, + 32, 33, 34, 34, 36, 37, 38, 38, 40, 41, 42, 42, 44, 45, 46, 46, + 48, 49, 50, 50, 52, 53, 54, 54, 56, 57, 58, 58, 60, 61, 62, 62, + 64, 65, 66, 66, 68, 69, 70, 70, 72, 73, 74, 74, 76, 77, 78, 78, + 80, 81, 82, 82, 84, 85, 86, 86, 88, 89, 90, 90, 92, 93, 94, 94, + 96, 97, 98, 98, 100, 101, 102, 102, 104, 105, 106, 106, 108, 109, 110, 110, + 112, 113, 114, 114, 116, 117, 118, 118, 120, 121, 122, 122, 124, 125, 126, 126, + 129, 129, 130, 131, 133, 133, 134, 135, 137, 137, 138, 139, 141, 141, 142, 143, + 145, 145, 146, 147, 149, 149, 150, 151, 153, 153, 154, 155, 157, 157, 158, 159, + 161, 161, 162, 163, 165, 165, 166, 167, 169, 169, 170, 171, 173, 173, 174, 175, + 177, 177, 178, 179, 181, 181, 182, 183, 185, 185, 186, 187, 189, 189, 190, 191, + 193, 193, 194, 195, 197, 197, 198, 199, 201, 201, 202, 203, 205, 205, 206, 207, + 209, 209, 210, 211, 213, 213, 214, 215, 217, 217, 218, 219, 221, 221, 222, 223, + 225, 225, 226, 227, 229, 229, 230, 231, 233, 233, 234, 235, 237, 237, 238, 239, + 241, 241, 242, 243, 245, 245, 246, 247, 249, 249, 250, 251, 253, 253, 254, 255 + }, + { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, + 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, + 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, + 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, + 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, + 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, + 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, + 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, + 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255 + } +}; + // Starts from QUANT_6 // Scrambled -const uint8_t color_quant_tables[17][256] { +const uint8_t color_uquant_to_scrambled_pquant_tables[17][256] { { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 }, { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, - 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 10, 10, 10, 10, 10, 10, 10, + 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, + 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, + 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15 }, { - 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, - 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 1, 1, 1, 1, 1 + 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 10, 10, 10, 10, 10, 10, 10, 10, + 10, 10, 10, 10, 10, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 1, 1, 1, 1, 1 }, { - 0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 10, 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, - 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, 11, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 1, 1, 1, 1, 1, 1 + 0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 10, 10, 10, 10, 10, 10, 10, 10, 10, + 10, 10, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, 11, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 1, 1, 1, 1, 1, 1 }, { - 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, - 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, - 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, - 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 12, - 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, - 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, - 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, - 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, - 21, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, - 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, - 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, - 29, 29, 29, 30, 30, 30, 30, 30, 30, 30, 30, 31, 31, 31, 31, 31 + 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, + 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, + 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, + 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 12, + 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, + 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, + 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, + 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, + 21, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, + 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, + 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, + 29, 29, 29, 30, 30, 30, 30, 30, 30, 30, 30, 31, 31, 31, 31, 31 }, { - 0, 0, 0, 0, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, - 16, 24, 24, 24, 24, 24, 24, 32, 32, 32, 32, 32, 32, 32, 2, 2, - 2, 2, 2, 2, 10, 10, 10, 10, 10, 10, 10, 18, 18, 18, 18, 18, - 18, 26, 26, 26, 26, 26, 26, 26, 34, 34, 34, 34, 34, 34, 4, 4, - 4, 4, 4, 4, 4, 12, 12, 12, 12, 12, 12, 20, 20, 20, 20, 20, - 20, 20, 28, 28, 28, 28, 28, 28, 36, 36, 36, 36, 36, 36, 36, 6, - 6, 6, 6, 6, 6, 14, 14, 14, 14, 14, 14, 14, 22, 22, 22, 22, - 22, 22, 30, 30, 30, 30, 30, 30, 30, 38, 38, 38, 38, 38, 38, 38, - 39, 39, 39, 39, 39, 39, 39, 31, 31, 31, 31, 31, 31, 31, 23, 23, - 23, 23, 23, 23, 15, 15, 15, 15, 15, 15, 15, 7, 7, 7, 7, 7, - 7, 37, 37, 37, 37, 37, 37, 37, 29, 29, 29, 29, 29, 29, 21, 21, - 21, 21, 21, 21, 21, 13, 13, 13, 13, 13, 13, 5, 5, 5, 5, 5, - 5, 5, 35, 35, 35, 35, 35, 35, 27, 27, 27, 27, 27, 27, 27, 19, - 19, 19, 19, 19, 19, 11, 11, 11, 11, 11, 11, 11, 3, 3, 3, 3, - 3, 3, 33, 33, 33, 33, 33, 33, 33, 25, 25, 25, 25, 25, 25, 17, - 17, 17, 17, 17, 17, 17, 9, 9, 9, 9, 9, 9, 1, 1, 1, 1 + 0, 0, 0, 0, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, + 16, 24, 24, 24, 24, 24, 24, 32, 32, 32, 32, 32, 32, 32, 2, 2, + 2, 2, 2, 2, 10, 10, 10, 10, 10, 10, 10, 18, 18, 18, 18, 18, + 18, 26, 26, 26, 26, 26, 26, 26, 34, 34, 34, 34, 34, 34, 4, 4, + 4, 4, 4, 4, 4, 12, 12, 12, 12, 12, 12, 20, 20, 20, 20, 20, + 20, 20, 28, 28, 28, 28, 28, 28, 36, 36, 36, 36, 36, 36, 36, 6, + 6, 6, 6, 6, 6, 14, 14, 14, 14, 14, 14, 14, 22, 22, 22, 22, + 22, 22, 30, 30, 30, 30, 30, 30, 30, 38, 38, 38, 38, 38, 38, 38, + 39, 39, 39, 39, 39, 39, 39, 31, 31, 31, 31, 31, 31, 31, 23, 23, + 23, 23, 23, 23, 15, 15, 15, 15, 15, 15, 15, 7, 7, 7, 7, 7, + 7, 37, 37, 37, 37, 37, 37, 37, 29, 29, 29, 29, 29, 29, 21, 21, + 21, 21, 21, 21, 21, 13, 13, 13, 13, 13, 13, 5, 5, 5, 5, 5, + 5, 5, 35, 35, 35, 35, 35, 35, 27, 27, 27, 27, 27, 27, 27, 19, + 19, 19, 19, 19, 19, 11, 11, 11, 11, 11, 11, 11, 3, 3, 3, 3, + 3, 3, 33, 33, 33, 33, 33, 33, 33, 25, 25, 25, 25, 25, 25, 17, + 17, 17, 17, 17, 17, 17, 9, 9, 9, 9, 9, 9, 1, 1, 1, 1 }, { - 0, 0, 0, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 2, 2, - 2, 2, 2, 18, 18, 18, 18, 18, 18, 34, 34, 34, 34, 34, 4, 4, - 4, 4, 4, 4, 20, 20, 20, 20, 20, 36, 36, 36, 36, 36, 6, 6, - 6, 6, 6, 6, 22, 22, 22, 22, 22, 38, 38, 38, 38, 38, 38, 8, - 8, 8, 8, 8, 24, 24, 24, 24, 24, 24, 40, 40, 40, 40, 40, 10, - 10, 10, 10, 10, 26, 26, 26, 26, 26, 26, 42, 42, 42, 42, 42, 12, - 12, 12, 12, 12, 12, 28, 28, 28, 28, 28, 44, 44, 44, 44, 44, 14, - 14, 14, 14, 14, 14, 30, 30, 30, 30, 30, 46, 46, 46, 46, 46, 46, - 47, 47, 47, 47, 47, 47, 31, 31, 31, 31, 31, 15, 15, 15, 15, 15, - 15, 45, 45, 45, 45, 45, 29, 29, 29, 29, 29, 13, 13, 13, 13, 13, - 13, 43, 43, 43, 43, 43, 27, 27, 27, 27, 27, 27, 11, 11, 11, 11, - 11, 41, 41, 41, 41, 41, 25, 25, 25, 25, 25, 25, 9, 9, 9, 9, - 9, 39, 39, 39, 39, 39, 39, 23, 23, 23, 23, 23, 7, 7, 7, 7, - 7, 7, 37, 37, 37, 37, 37, 21, 21, 21, 21, 21, 5, 5, 5, 5, - 5, 5, 35, 35, 35, 35, 35, 19, 19, 19, 19, 19, 19, 3, 3, 3, - 3, 3, 33, 33, 33, 33, 33, 17, 17, 17, 17, 17, 17, 1, 1, 1 + 0, 0, 0, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 2, 2, + 2, 2, 2, 18, 18, 18, 18, 18, 18, 34, 34, 34, 34, 34, 4, 4, + 4, 4, 4, 4, 20, 20, 20, 20, 20, 36, 36, 36, 36, 36, 6, 6, + 6, 6, 6, 6, 22, 22, 22, 22, 22, 38, 38, 38, 38, 38, 38, 8, + 8, 8, 8, 8, 24, 24, 24, 24, 24, 24, 40, 40, 40, 40, 40, 10, + 10, 10, 10, 10, 26, 26, 26, 26, 26, 26, 42, 42, 42, 42, 42, 12, + 12, 12, 12, 12, 12, 28, 28, 28, 28, 28, 44, 44, 44, 44, 44, 14, + 14, 14, 14, 14, 14, 30, 30, 30, 30, 30, 46, 46, 46, 46, 46, 46, + 47, 47, 47, 47, 47, 47, 31, 31, 31, 31, 31, 15, 15, 15, 15, 15, + 15, 45, 45, 45, 45, 45, 29, 29, 29, 29, 29, 13, 13, 13, 13, 13, + 13, 43, 43, 43, 43, 43, 27, 27, 27, 27, 27, 27, 11, 11, 11, 11, + 11, 41, 41, 41, 41, 41, 25, 25, 25, 25, 25, 25, 9, 9, 9, 9, + 9, 39, 39, 39, 39, 39, 39, 23, 23, 23, 23, 23, 7, 7, 7, 7, + 7, 7, 37, 37, 37, 37, 37, 21, 21, 21, 21, 21, 5, 5, 5, 5, + 5, 5, 35, 35, 35, 35, 35, 19, 19, 19, 19, 19, 19, 3, 3, 3, + 3, 3, 33, 33, 33, 33, 33, 17, 17, 17, 17, 17, 17, 1, 1, 1 }, { - 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, - 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, - 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, - 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, - 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, - 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 23, 23, 23, 23, - 24, 24, 24, 24, 25, 25, 25, 25, 26, 26, 26, 26, 27, 27, 27, 27, - 28, 28, 28, 28, 29, 29, 29, 29, 30, 30, 30, 30, 31, 31, 31, 31, - 32, 32, 32, 32, 33, 33, 33, 33, 34, 34, 34, 34, 35, 35, 35, 35, - 36, 36, 36, 36, 37, 37, 37, 37, 38, 38, 38, 38, 39, 39, 39, 39, - 40, 40, 40, 40, 41, 41, 41, 41, 42, 42, 42, 42, 43, 43, 43, 43, - 44, 44, 44, 44, 45, 45, 45, 45, 46, 46, 46, 46, 47, 47, 47, 47, - 47, 48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 51, 51, 51, - 51, 52, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 54, 55, 55, 55, - 55, 56, 56, 56, 56, 57, 57, 57, 57, 58, 58, 58, 58, 59, 59, 59, - 59, 60, 60, 60, 60, 61, 61, 61, 61, 62, 62, 62, 62, 63, 63, 63 + 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, + 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, + 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, + 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, + 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, + 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 23, 23, 23, 23, + 24, 24, 24, 24, 25, 25, 25, 25, 26, 26, 26, 26, 27, 27, 27, 27, + 28, 28, 28, 28, 29, 29, 29, 29, 30, 30, 30, 30, 31, 31, 31, 31, + 32, 32, 32, 32, 33, 33, 33, 33, 34, 34, 34, 34, 35, 35, 35, 35, + 36, 36, 36, 36, 37, 37, 37, 37, 38, 38, 38, 38, 39, 39, 39, 39, + 40, 40, 40, 40, 41, 41, 41, 41, 42, 42, 42, 42, 43, 43, 43, 43, + 44, 44, 44, 44, 45, 45, 45, 45, 46, 46, 46, 46, 47, 47, 47, 47, + 47, 48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 51, 51, 51, + 51, 52, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 54, 55, 55, 55, + 55, 56, 56, 56, 56, 57, 57, 57, 57, 58, 58, 58, 58, 59, 59, 59, + 59, 60, 60, 60, 60, 61, 61, 61, 61, 62, 62, 62, 62, 63, 63, 63 }, { - 0, 0, 16, 16, 16, 32, 32, 32, 48, 48, 48, 48, 64, 64, 64, 2, - 2, 2, 18, 18, 18, 34, 34, 34, 50, 50, 50, 50, 66, 66, 66, 4, - 4, 4, 20, 20, 20, 36, 36, 36, 36, 52, 52, 52, 68, 68, 68, 6, - 6, 6, 22, 22, 22, 38, 38, 38, 38, 54, 54, 54, 70, 70, 70, 8, - 8, 8, 24, 24, 24, 24, 40, 40, 40, 56, 56, 56, 72, 72, 72, 10, - 10, 10, 26, 26, 26, 26, 42, 42, 42, 58, 58, 58, 74, 74, 74, 12, - 12, 12, 12, 28, 28, 28, 44, 44, 44, 60, 60, 60, 76, 76, 76, 14, - 14, 14, 14, 30, 30, 30, 46, 46, 46, 62, 62, 62, 78, 78, 78, 78, - 79, 79, 79, 79, 63, 63, 63, 47, 47, 47, 31, 31, 31, 15, 15, 15, - 15, 77, 77, 77, 61, 61, 61, 45, 45, 45, 29, 29, 29, 13, 13, 13, - 13, 75, 75, 75, 59, 59, 59, 43, 43, 43, 27, 27, 27, 27, 11, 11, - 11, 73, 73, 73, 57, 57, 57, 41, 41, 41, 25, 25, 25, 25, 9, 9, - 9, 71, 71, 71, 55, 55, 55, 39, 39, 39, 39, 23, 23, 23, 7, 7, - 7, 69, 69, 69, 53, 53, 53, 37, 37, 37, 37, 21, 21, 21, 5, 5, - 5, 67, 67, 67, 51, 51, 51, 51, 35, 35, 35, 19, 19, 19, 3, 3, - 3, 65, 65, 65, 49, 49, 49, 49, 33, 33, 33, 17, 17, 17, 1, 1 + 0, 0, 16, 16, 16, 32, 32, 32, 48, 48, 48, 48, 64, 64, 64, 2, + 2, 2, 18, 18, 18, 34, 34, 34, 50, 50, 50, 50, 66, 66, 66, 4, + 4, 4, 20, 20, 20, 36, 36, 36, 36, 52, 52, 52, 68, 68, 68, 6, + 6, 6, 22, 22, 22, 38, 38, 38, 38, 54, 54, 54, 70, 70, 70, 8, + 8, 8, 24, 24, 24, 24, 40, 40, 40, 56, 56, 56, 72, 72, 72, 10, + 10, 10, 26, 26, 26, 26, 42, 42, 42, 58, 58, 58, 74, 74, 74, 12, + 12, 12, 12, 28, 28, 28, 44, 44, 44, 60, 60, 60, 76, 76, 76, 14, + 14, 14, 14, 30, 30, 30, 46, 46, 46, 62, 62, 62, 78, 78, 78, 78, + 79, 79, 79, 79, 63, 63, 63, 47, 47, 47, 31, 31, 31, 15, 15, 15, + 15, 77, 77, 77, 61, 61, 61, 45, 45, 45, 29, 29, 29, 13, 13, 13, + 13, 75, 75, 75, 59, 59, 59, 43, 43, 43, 27, 27, 27, 27, 11, 11, + 11, 73, 73, 73, 57, 57, 57, 41, 41, 41, 25, 25, 25, 25, 9, 9, + 9, 71, 71, 71, 55, 55, 55, 39, 39, 39, 39, 23, 23, 23, 7, 7, + 7, 69, 69, 69, 53, 53, 53, 37, 37, 37, 37, 21, 21, 21, 5, 5, + 5, 67, 67, 67, 51, 51, 51, 51, 35, 35, 35, 19, 19, 19, 3, 3, + 3, 65, 65, 65, 49, 49, 49, 49, 33, 33, 33, 17, 17, 17, 1, 1 }, { - 0, 0, 32, 32, 64, 64, 64, 2, 2, 2, 34, 34, 66, 66, 66, 4, - 4, 4, 36, 36, 68, 68, 68, 6, 6, 6, 38, 38, 70, 70, 70, 8, - 8, 8, 40, 40, 40, 72, 72, 10, 10, 10, 42, 42, 42, 74, 74, 12, - 12, 12, 44, 44, 44, 76, 76, 14, 14, 14, 46, 46, 46, 78, 78, 16, - 16, 16, 48, 48, 48, 80, 80, 80, 18, 18, 50, 50, 50, 82, 82, 82, - 20, 20, 52, 52, 52, 84, 84, 84, 22, 22, 54, 54, 54, 86, 86, 86, - 24, 24, 56, 56, 56, 88, 88, 88, 26, 26, 58, 58, 58, 90, 90, 90, - 28, 28, 60, 60, 60, 92, 92, 92, 30, 30, 62, 62, 62, 94, 94, 94, - 95, 95, 95, 63, 63, 63, 31, 31, 93, 93, 93, 61, 61, 61, 29, 29, - 91, 91, 91, 59, 59, 59, 27, 27, 89, 89, 89, 57, 57, 57, 25, 25, - 87, 87, 87, 55, 55, 55, 23, 23, 85, 85, 85, 53, 53, 53, 21, 21, - 83, 83, 83, 51, 51, 51, 19, 19, 81, 81, 81, 49, 49, 49, 17, 17, - 17, 79, 79, 47, 47, 47, 15, 15, 15, 77, 77, 45, 45, 45, 13, 13, - 13, 75, 75, 43, 43, 43, 11, 11, 11, 73, 73, 41, 41, 41, 9, 9, - 9, 71, 71, 71, 39, 39, 7, 7, 7, 69, 69, 69, 37, 37, 5, 5, - 5, 67, 67, 67, 35, 35, 3, 3, 3, 65, 65, 65, 33, 33, 1, 1 + 0, 0, 32, 32, 64, 64, 64, 2, 2, 2, 34, 34, 66, 66, 66, 4, + 4, 4, 36, 36, 68, 68, 68, 6, 6, 6, 38, 38, 70, 70, 70, 8, + 8, 8, 40, 40, 40, 72, 72, 10, 10, 10, 42, 42, 42, 74, 74, 12, + 12, 12, 44, 44, 44, 76, 76, 14, 14, 14, 46, 46, 46, 78, 78, 16, + 16, 16, 48, 48, 48, 80, 80, 80, 18, 18, 50, 50, 50, 82, 82, 82, + 20, 20, 52, 52, 52, 84, 84, 84, 22, 22, 54, 54, 54, 86, 86, 86, + 24, 24, 56, 56, 56, 88, 88, 88, 26, 26, 58, 58, 58, 90, 90, 90, + 28, 28, 60, 60, 60, 92, 92, 92, 30, 30, 62, 62, 62, 94, 94, 94, + 95, 95, 95, 63, 63, 63, 31, 31, 93, 93, 93, 61, 61, 61, 29, 29, + 91, 91, 91, 59, 59, 59, 27, 27, 89, 89, 89, 57, 57, 57, 25, 25, + 87, 87, 87, 55, 55, 55, 23, 23, 85, 85, 85, 53, 53, 53, 21, 21, + 83, 83, 83, 51, 51, 51, 19, 19, 81, 81, 81, 49, 49, 49, 17, 17, + 17, 79, 79, 47, 47, 47, 15, 15, 15, 77, 77, 45, 45, 45, 13, 13, + 13, 75, 75, 43, 43, 43, 11, 11, 11, 73, 73, 41, 41, 41, 9, 9, + 9, 71, 71, 71, 39, 39, 7, 7, 7, 69, 69, 69, 37, 37, 5, 5, + 5, 67, 67, 67, 35, 35, 3, 3, 3, 65, 65, 65, 33, 33, 1, 1 }, { - 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, - 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, - 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, - 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31, 31, - 32, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37, 38, 38, 39, 39, - 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 45, 45, 46, 46, 47, 47, - 48, 48, 49, 49, 50, 50, 51, 51, 52, 52, 53, 53, 54, 54, 55, 55, - 56, 56, 57, 57, 58, 58, 59, 59, 60, 60, 61, 61, 62, 62, 63, 63, - 64, 64, 65, 65, 66, 66, 67, 67, 68, 68, 69, 69, 70, 70, 71, 71, - 72, 72, 73, 73, 74, 74, 75, 75, 76, 76, 77, 77, 78, 78, 79, 79, - 80, 80, 81, 81, 82, 82, 83, 83, 84, 84, 85, 85, 86, 86, 87, 87, - 88, 88, 89, 89, 90, 90, 91, 91, 92, 92, 93, 93, 94, 94, 95, 95, - 96, 96, 97, 97, 98, 98, 99, 99, 100, 100, 101, 101, 102, 102, 103, 103, + 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, + 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, + 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, + 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31, 31, + 32, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37, 38, 38, 39, 39, + 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 45, 45, 46, 46, 47, 47, + 48, 48, 49, 49, 50, 50, 51, 51, 52, 52, 53, 53, 54, 54, 55, 55, + 56, 56, 57, 57, 58, 58, 59, 59, 60, 60, 61, 61, 62, 62, 63, 63, + 64, 64, 65, 65, 66, 66, 67, 67, 68, 68, 69, 69, 70, 70, 71, 71, + 72, 72, 73, 73, 74, 74, 75, 75, 76, 76, 77, 77, 78, 78, 79, 79, + 80, 80, 81, 81, 82, 82, 83, 83, 84, 84, 85, 85, 86, 86, 87, 87, + 88, 88, 89, 89, 90, 90, 91, 91, 92, 92, 93, 93, 94, 94, 95, 95, + 96, 96, 97, 97, 98, 98, 99, 99, 100, 100, 101, 101, 102, 102, 103, 103, 104, 104, 105, 105, 106, 106, 107, 107, 108, 108, 109, 109, 110, 110, 111, 111, 112, 112, 113, 113, 114, 114, 115, 115, 116, 116, 117, 117, 118, 118, 119, 119, 120, 120, 121, 121, 122, 122, 123, 123, 124, 124, 125, 125, 126, 126, 127, 127 }, { - 0, 32, 32, 64, 96, 96, 128, 128, 2, 34, 34, 66, 98, 98, 130, 130, - 4, 36, 36, 68, 100, 100, 132, 132, 6, 38, 38, 70, 102, 102, 134, 134, - 8, 40, 40, 72, 104, 104, 136, 136, 10, 42, 42, 74, 106, 106, 138, 138, - 12, 44, 44, 76, 108, 108, 140, 140, 14, 46, 46, 78, 110, 110, 142, 142, - 16, 48, 48, 80, 112, 112, 144, 144, 18, 50, 50, 82, 114, 114, 146, 146, - 20, 52, 52, 84, 116, 116, 148, 148, 22, 54, 54, 86, 118, 118, 150, 150, - 24, 56, 56, 88, 120, 120, 152, 152, 26, 58, 58, 90, 122, 122, 154, 154, - 28, 60, 60, 92, 124, 124, 156, 156, 30, 62, 62, 94, 126, 126, 158, 158, - 159, 159, 127, 127, 95, 63, 63, 31, 157, 157, 125, 125, 93, 61, 61, 29, - 155, 155, 123, 123, 91, 59, 59, 27, 153, 153, 121, 121, 89, 57, 57, 25, - 151, 151, 119, 119, 87, 55, 55, 23, 149, 149, 117, 117, 85, 53, 53, 21, - 147, 147, 115, 115, 83, 51, 51, 19, 145, 145, 113, 113, 81, 49, 49, 17, - 143, 143, 111, 111, 79, 47, 47, 15, 141, 141, 109, 109, 77, 45, 45, 13, - 139, 139, 107, 107, 75, 43, 43, 11, 137, 137, 105, 105, 73, 41, 41, 9, - 135, 135, 103, 103, 71, 39, 39, 7, 133, 133, 101, 101, 69, 37, 37, 5, - 131, 131, 99, 99, 67, 35, 35, 3, 129, 129, 97, 97, 65, 33, 33, 1 + 0, 32, 32, 64, 96, 96, 128, 128, 2, 34, 34, 66, 98, 98, 130, 130, + 4, 36, 36, 68, 100, 100, 132, 132, 6, 38, 38, 70, 102, 102, 134, 134, + 8, 40, 40, 72, 104, 104, 136, 136, 10, 42, 42, 74, 106, 106, 138, 138, + 12, 44, 44, 76, 108, 108, 140, 140, 14, 46, 46, 78, 110, 110, 142, 142, + 16, 48, 48, 80, 112, 112, 144, 144, 18, 50, 50, 82, 114, 114, 146, 146, + 20, 52, 52, 84, 116, 116, 148, 148, 22, 54, 54, 86, 118, 118, 150, 150, + 24, 56, 56, 88, 120, 120, 152, 152, 26, 58, 58, 90, 122, 122, 154, 154, + 28, 60, 60, 92, 124, 124, 156, 156, 30, 62, 62, 94, 126, 126, 158, 158, + 159, 159, 127, 127, 95, 63, 63, 31, 157, 157, 125, 125, 93, 61, 61, 29, + 155, 155, 123, 123, 91, 59, 59, 27, 153, 153, 121, 121, 89, 57, 57, 25, + 151, 151, 119, 119, 87, 55, 55, 23, 149, 149, 117, 117, 85, 53, 53, 21, + 147, 147, 115, 115, 83, 51, 51, 19, 145, 145, 113, 113, 81, 49, 49, 17, + 143, 143, 111, 111, 79, 47, 47, 15, 141, 141, 109, 109, 77, 45, 45, 13, + 139, 139, 107, 107, 75, 43, 43, 11, 137, 137, 105, 105, 73, 41, 41, 9, + 135, 135, 103, 103, 71, 39, 39, 7, 133, 133, 101, 101, 69, 37, 37, 5, + 131, 131, 99, 99, 67, 35, 35, 3, 129, 129, 97, 97, 65, 33, 33, 1 }, { - 0, 64, 128, 128, 2, 66, 130, 130, 4, 68, 132, 132, 6, 70, 134, 134, - 8, 72, 136, 136, 10, 74, 138, 138, 12, 76, 140, 140, 14, 78, 142, 142, - 16, 80, 144, 144, 18, 82, 146, 146, 20, 84, 148, 148, 22, 86, 150, 150, - 24, 88, 152, 152, 26, 90, 154, 154, 28, 92, 156, 156, 30, 94, 158, 158, - 32, 96, 160, 160, 34, 98, 162, 162, 36, 100, 164, 164, 38, 102, 166, 166, - 40, 104, 168, 168, 42, 106, 170, 170, 44, 108, 172, 172, 46, 110, 174, 174, - 48, 112, 176, 176, 50, 114, 178, 178, 52, 116, 180, 180, 54, 118, 182, 182, - 56, 120, 184, 184, 58, 122, 186, 186, 60, 124, 188, 188, 62, 126, 190, 190, - 191, 191, 127, 63, 189, 189, 125, 61, 187, 187, 123, 59, 185, 185, 121, 57, - 183, 183, 119, 55, 181, 181, 117, 53, 179, 179, 115, 51, 177, 177, 113, 49, - 175, 175, 111, 47, 173, 173, 109, 45, 171, 171, 107, 43, 169, 169, 105, 41, - 167, 167, 103, 39, 165, 165, 101, 37, 163, 163, 99, 35, 161, 161, 97, 33, - 159, 159, 95, 31, 157, 157, 93, 29, 155, 155, 91, 27, 153, 153, 89, 25, - 151, 151, 87, 23, 149, 149, 85, 21, 147, 147, 83, 19, 145, 145, 81, 17, - 143, 143, 79, 15, 141, 141, 77, 13, 139, 139, 75, 11, 137, 137, 73, 9, - 135, 135, 71, 7, 133, 133, 69, 5, 131, 131, 67, 3, 129, 129, 65, 1 + 0, 64, 128, 128, 2, 66, 130, 130, 4, 68, 132, 132, 6, 70, 134, 134, + 8, 72, 136, 136, 10, 74, 138, 138, 12, 76, 140, 140, 14, 78, 142, 142, + 16, 80, 144, 144, 18, 82, 146, 146, 20, 84, 148, 148, 22, 86, 150, 150, + 24, 88, 152, 152, 26, 90, 154, 154, 28, 92, 156, 156, 30, 94, 158, 158, + 32, 96, 160, 160, 34, 98, 162, 162, 36, 100, 164, 164, 38, 102, 166, 166, + 40, 104, 168, 168, 42, 106, 170, 170, 44, 108, 172, 172, 46, 110, 174, 174, + 48, 112, 176, 176, 50, 114, 178, 178, 52, 116, 180, 180, 54, 118, 182, 182, + 56, 120, 184, 184, 58, 122, 186, 186, 60, 124, 188, 188, 62, 126, 190, 190, + 191, 191, 127, 63, 189, 189, 125, 61, 187, 187, 123, 59, 185, 185, 121, 57, + 183, 183, 119, 55, 181, 181, 117, 53, 179, 179, 115, 51, 177, 177, 113, 49, + 175, 175, 111, 47, 173, 173, 109, 45, 171, 171, 107, 43, 169, 169, 105, 41, + 167, 167, 103, 39, 165, 165, 101, 37, 163, 163, 99, 35, 161, 161, 97, 33, + 159, 159, 95, 31, 157, 157, 93, 29, 155, 155, 91, 27, 153, 153, 89, 25, + 151, 151, 87, 23, 149, 149, 85, 21, 147, 147, 83, 19, 145, 145, 81, 17, + 143, 143, 79, 15, 141, 141, 77, 13, 139, 139, 75, 11, 137, 137, 73, 9, + 135, 135, 71, 7, 133, 133, 69, 5, 131, 131, 67, 3, 129, 129, 65, 1 }, { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, @@ -338,119 +649,153 @@ const uint8_t color_quant_tables[17][256] { // Starts from QUANT_6 // Scrambled -const uint8_t color_unquant_tables[17][256] { - { - 0, 255, 51, 204, 102, 153 - }, - { - 0, 36, 73, 109, 146, 182, 219, 255 - }, - { - 0, 255, 28, 227, 56, 199, 84, 171, 113, 142 - }, - { - 0, 255, 69, 186, 23, 232, 92, 163, 46, 209, 116, 139 - }, - { - 0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255 - }, - { - 0, 255, 67, 188, 13, 242, 80, 175, 27, 228, 94, 161, 40, 215, 107, 148, - 54, 201, 121, 134 - }, - { - 0, 255, 33, 222, 66, 189, 99, 156, 11, 244, 44, 211, 77, 178, 110, 145, - 22, 233, 55, 200, 88, 167, 121, 134 - }, - { - 0, 8, 16, 24, 33, 41, 49, 57, 66, 74, 82, 90, 99, 107, 115, 123, - 132, 140, 148, 156, 165, 173, 181, 189, 198, 206, 214, 222, 231, 239, 247, 255 - }, - { - 0, 255, 32, 223, 65, 190, 97, 158, 6, 249, 39, 216, 71, 184, 104, 151, - 13, 242, 45, 210, 78, 177, 110, 145, 19, 236, 52, 203, 84, 171, 117, 138, - 26, 229, 58, 197, 91, 164, 123, 132 - }, - { - 0, 255, 16, 239, 32, 223, 48, 207, 65, 190, 81, 174, 97, 158, 113, 142, - 5, 250, 21, 234, 38, 217, 54, 201, 70, 185, 86, 169, 103, 152, 119, 136, - 11, 244, 27, 228, 43, 212, 59, 196, 76, 179, 92, 163, 108, 147, 124, 131 - }, - { - 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, - 65, 69, 73, 77, 81, 85, 89, 93, 97, 101, 105, 109, 113, 117, 121, 125, - 130, 134, 138, 142, 146, 150, 154, 158, 162, 166, 170, 174, 178, 182, 186, 190, - 195, 199, 203, 207, 211, 215, 219, 223, 227, 231, 235, 239, 243, 247, 251, 255 - }, - { - 0, 255, 16, 239, 32, 223, 48, 207, 64, 191, 80, 175, 96, 159, 112, 143, - 3, 252, 19, 236, 35, 220, 51, 204, 67, 188, 83, 172, 100, 155, 116, 139, - 6, 249, 22, 233, 38, 217, 54, 201, 71, 184, 87, 168, 103, 152, 119, 136, - 9, 246, 25, 230, 42, 213, 58, 197, 74, 181, 90, 165, 106, 149, 122, 133, - 13, 242, 29, 226, 45, 210, 61, 194, 77, 178, 93, 162, 109, 146, 125, 130 - }, - { - 0, 255, 8, 247, 16, 239, 24, 231, 32, 223, 40, 215, 48, 207, 56, 199, - 64, 191, 72, 183, 80, 175, 88, 167, 96, 159, 104, 151, 112, 143, 120, 135, - 2, 253, 10, 245, 18, 237, 26, 229, 35, 220, 43, 212, 51, 204, 59, 196, - 67, 188, 75, 180, 83, 172, 91, 164, 99, 156, 107, 148, 115, 140, 123, 132, - 5, 250, 13, 242, 21, 234, 29, 226, 37, 218, 45, 210, 53, 202, 61, 194, - 70, 185, 78, 177, 86, 169, 94, 161, 102, 153, 110, 145, 118, 137, 126, 129 - }, - { - 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, - 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, - 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, - 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, - 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 157, 159, - 161, 163, 165, 167, 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 189, 191, - 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 221, 223, - 225, 227, 229, 231, 233, 235, 237, 239, 241, 243, 245, 247, 249, 251, 253, 255 - }, - { - 0, 255, 8, 247, 16, 239, 24, 231, 32, 223, 40, 215, 48, 207, 56, 199, - 64, 191, 72, 183, 80, 175, 88, 167, 96, 159, 104, 151, 112, 143, 120, 135, - 1, 254, 9, 246, 17, 238, 25, 230, 33, 222, 41, 214, 49, 206, 57, 198, - 65, 190, 73, 182, 81, 174, 89, 166, 97, 158, 105, 150, 113, 142, 121, 134, - 3, 252, 11, 244, 19, 236, 27, 228, 35, 220, 43, 212, 51, 204, 59, 196, - 67, 188, 75, 180, 83, 172, 91, 164, 99, 156, 107, 148, 115, 140, 123, 132, - 4, 251, 12, 243, 20, 235, 28, 227, 36, 219, 44, 211, 52, 203, 60, 195, - 68, 187, 76, 179, 84, 171, 92, 163, 100, 155, 108, 147, 116, 139, 124, 131, - 6, 249, 14, 241, 22, 233, 30, 225, 38, 217, 46, 209, 54, 201, 62, 193, - 70, 185, 78, 177, 86, 169, 94, 161, 102, 153, 110, 145, 118, 137, 126, 129 - }, - { - 0, 255, 4, 251, 8, 247, 12, 243, 16, 239, 20, 235, 24, 231, 28, 227, - 32, 223, 36, 219, 40, 215, 44, 211, 48, 207, 52, 203, 56, 199, 60, 195, - 64, 191, 68, 187, 72, 183, 76, 179, 80, 175, 84, 171, 88, 167, 92, 163, - 96, 159, 100, 155, 104, 151, 108, 147, 112, 143, 116, 139, 120, 135, 124, 131, - 1, 254, 5, 250, 9, 246, 13, 242, 17, 238, 21, 234, 25, 230, 29, 226, - 33, 222, 37, 218, 41, 214, 45, 210, 49, 206, 53, 202, 57, 198, 61, 194, - 65, 190, 69, 186, 73, 182, 77, 178, 81, 174, 85, 170, 89, 166, 93, 162, - 97, 158, 101, 154, 105, 150, 109, 146, 113, 142, 117, 138, 121, 134, 125, 130, - 2, 253, 6, 249, 10, 245, 14, 241, 18, 237, 22, 233, 26, 229, 30, 225, - 34, 221, 38, 217, 42, 213, 46, 209, 50, 205, 54, 201, 58, 197, 62, 193, - 66, 189, 70, 185, 74, 181, 78, 177, 82, 173, 86, 169, 90, 165, 94, 161, - 98, 157, 102, 153, 106, 149, 110, 145, 114, 141, 118, 137, 122, 133, 126, 129 - }, - { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, - 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, - 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, - 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, - 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, - 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, - 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, - 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, - 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, - 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255 - } +static const uint8_t color_scrambled_pquant_to_uquant_q6[6] { + 0, 255, 51, 204, 102, 153 +}; + +static const uint8_t color_scrambled_pquant_to_uquant_q8[8] { + 0, 36, 73, 109, 146, 182, 219, 255 +}; + +static const uint8_t color_scrambled_pquant_to_uquant_q10[10] { + 0, 255, 28, 227, 56, 199, 84, 171, 113, 142 +}; + +static const uint8_t color_scrambled_pquant_to_uquant_q12[12] { + 0, 255, 69, 186, 23, 232, 92, 163, 46, 209, 116, 139 +}; + +static const uint8_t color_scrambled_pquant_to_uquant_q16[16] { + 0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255 +}; + +static const uint8_t color_scrambled_pquant_to_uquant_q20[20] { + 0, 255, 67, 188, 13, 242, 80, 175, 27, 228, 94, 161, 40, 215, 107, 148, + 54, 201, 121, 134 +}; + +static const uint8_t color_scrambled_pquant_to_uquant_q24[24] { + 0, 255, 33, 222, 66, 189, 99, 156, 11, 244, 44, 211, 77, 178, 110, 145, + 22, 233, 55, 200, 88, 167, 121, 134 +}; + +static const uint8_t color_scrambled_pquant_to_uquant_q32[32] { + 0, 8, 16, 24, 33, 41, 49, 57, 66, 74, 82, 90, 99, 107, 115, 123, + 132, 140, 148, 156, 165, 173, 181, 189, 198, 206, 214, 222, 231, 239, 247, 255 +}; + +static const uint8_t color_scrambled_pquant_to_uquant_q40[40] { + 0, 255, 32, 223, 65, 190, 97, 158, 6, 249, 39, 216, 71, 184, 104, 151, + 13, 242, 45, 210, 78, 177, 110, 145, 19, 236, 52, 203, 84, 171, 117, 138, + 26, 229, 58, 197, 91, 164, 123, 132 +}; + +static const uint8_t color_scrambled_pquant_to_uquant_q48[48] { + 0, 255, 16, 239, 32, 223, 48, 207, 65, 190, 81, 174, 97, 158, 113, 142, + 5, 250, 21, 234, 38, 217, 54, 201, 70, 185, 86, 169, 103, 152, 119, 136, + 11, 244, 27, 228, 43, 212, 59, 196, 76, 179, 92, 163, 108, 147, 124, 131 +}; + +static const uint8_t color_scrambled_pquant_to_uquant_q64[64] { + 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, + 65, 69, 73, 77, 81, 85, 89, 93, 97, 101, 105, 109, 113, 117, 121, 125, + 130, 134, 138, 142, 146, 150, 154, 158, 162, 166, 170, 174, 178, 182, 186, 190, + 195, 199, 203, 207, 211, 215, 219, 223, 227, 231, 235, 239, 243, 247, 251, 255, +}; + +static const uint8_t color_scrambled_pquant_to_uquant_q80[80] { + 0, 255, 16, 239, 32, 223, 48, 207, 64, 191, 80, 175, 96, 159, 112, 143, + 3, 252, 19, 236, 35, 220, 51, 204, 67, 188, 83, 172, 100, 155, 116, 139, + 6, 249, 22, 233, 38, 217, 54, 201, 71, 184, 87, 168, 103, 152, 119, 136, + 9, 246, 25, 230, 42, 213, 58, 197, 74, 181, 90, 165, 106, 149, 122, 133, + 13, 242, 29, 226, 45, 210, 61, 194, 77, 178, 93, 162, 109, 146, 125, 130 +}; + +static const uint8_t color_scrambled_pquant_to_uquant_q96[96] { + 0, 255, 8, 247, 16, 239, 24, 231, 32, 223, 40, 215, 48, 207, 56, 199, + 64, 191, 72, 183, 80, 175, 88, 167, 96, 159, 104, 151, 112, 143, 120, 135, + 2, 253, 10, 245, 18, 237, 26, 229, 35, 220, 43, 212, 51, 204, 59, 196, + 67, 188, 75, 180, 83, 172, 91, 164, 99, 156, 107, 148, 115, 140, 123, 132, + 5, 250, 13, 242, 21, 234, 29, 226, 37, 218, 45, 210, 53, 202, 61, 194, + 70, 185, 78, 177, 86, 169, 94, 161, 102, 153, 110, 145, 118, 137, 126, 129 +}; + +static const uint8_t color_scrambled_pquant_to_uquant_q128[128] { + 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, + 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, + 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, + 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, + 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 157, 159, + 161, 163, 165, 167, 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 189, 191, + 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 221, 223, + 225, 227, 229, 231, 233, 235, 237, 239, 241, 243, 245, 247, 249, 251, 253, 255 +}; + +static const uint8_t color_scrambled_pquant_to_uquant_q160[160] { + 0, 255, 8, 247, 16, 239, 24, 231, 32, 223, 40, 215, 48, 207, 56, 199, + 64, 191, 72, 183, 80, 175, 88, 167, 96, 159, 104, 151, 112, 143, 120, 135, + 1, 254, 9, 246, 17, 238, 25, 230, 33, 222, 41, 214, 49, 206, 57, 198, + 65, 190, 73, 182, 81, 174, 89, 166, 97, 158, 105, 150, 113, 142, 121, 134, + 3, 252, 11, 244, 19, 236, 27, 228, 35, 220, 43, 212, 51, 204, 59, 196, + 67, 188, 75, 180, 83, 172, 91, 164, 99, 156, 107, 148, 115, 140, 123, 132, + 4, 251, 12, 243, 20, 235, 28, 227, 36, 219, 44, 211, 52, 203, 60, 195, + 68, 187, 76, 179, 84, 171, 92, 163, 100, 155, 108, 147, 116, 139, 124, 131, + 6, 249, 14, 241, 22, 233, 30, 225, 38, 217, 46, 209, 54, 201, 62, 193, + 70, 185, 78, 177, 86, 169, 94, 161, 102, 153, 110, 145, 118, 137, 126, 129 +}; + +static const uint8_t color_scrambled_pquant_to_uquant_q192[192] { + 0, 255, 4, 251, 8, 247, 12, 243, 16, 239, 20, 235, 24, 231, 28, 227, + 32, 223, 36, 219, 40, 215, 44, 211, 48, 207, 52, 203, 56, 199, 60, 195, + 64, 191, 68, 187, 72, 183, 76, 179, 80, 175, 84, 171, 88, 167, 92, 163, + 96, 159, 100, 155, 104, 151, 108, 147, 112, 143, 116, 139, 120, 135, 124, 131, + 1, 254, 5, 250, 9, 246, 13, 242, 17, 238, 21, 234, 25, 230, 29, 226, + 33, 222, 37, 218, 41, 214, 45, 210, 49, 206, 53, 202, 57, 198, 61, 194, + 65, 190, 69, 186, 73, 182, 77, 178, 81, 174, 85, 170, 89, 166, 93, 162, + 97, 158, 101, 154, 105, 150, 109, 146, 113, 142, 117, 138, 121, 134, 125, 130, + 2, 253, 6, 249, 10, 245, 14, 241, 18, 237, 22, 233, 26, 229, 30, 225, + 34, 221, 38, 217, 42, 213, 46, 209, 50, 205, 54, 201, 58, 197, 62, 193, + 66, 189, 70, 185, 74, 181, 78, 177, 82, 173, 86, 169, 90, 165, 94, 161, + 98, 157, 102, 153, 106, 149, 110, 145, 114, 141, 118, 137, 122, 133, 126, 129 +}; + +static const uint8_t color_scrambled_pquant_to_uquant_q256[256] { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, + 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, + 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, + 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, + 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, + 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, + 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, + 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, + 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255 +}; + +const uint8_t* color_scrambled_pquant_to_uquant_tables[17] { + color_scrambled_pquant_to_uquant_q6, + color_scrambled_pquant_to_uquant_q8, + color_scrambled_pquant_to_uquant_q10, + color_scrambled_pquant_to_uquant_q12, + color_scrambled_pquant_to_uquant_q16, + color_scrambled_pquant_to_uquant_q20, + color_scrambled_pquant_to_uquant_q24, + color_scrambled_pquant_to_uquant_q32, + color_scrambled_pquant_to_uquant_q40, + color_scrambled_pquant_to_uquant_q48, + color_scrambled_pquant_to_uquant_q64, + color_scrambled_pquant_to_uquant_q80, + color_scrambled_pquant_to_uquant_q96, + color_scrambled_pquant_to_uquant_q128, + color_scrambled_pquant_to_uquant_q160, + color_scrambled_pquant_to_uquant_q192, + color_scrambled_pquant_to_uquant_q256 }; // The quant_mode_table[integer_count/2][bits] gives us the quantization level for a given integer diff --git a/3rdparty/astc-encoder/source/astcenc_symbolic_physical.cpp b/3rdparty/astc-encoder/source/astcenc_symbolic_physical.cpp index 230ae39..a19b907 100644 --- a/3rdparty/astc-encoder/source/astcenc_symbolic_physical.cpp +++ b/3rdparty/astc-encoder/source/astcenc_symbolic_physical.cpp @@ -265,13 +265,15 @@ void symbolic_to_physical( // Encode the color components uint8_t values_to_encode[32]; int valuecount_to_encode = 0; + + const uint8_t* pack_table = color_uquant_to_scrambled_pquant_tables[scb.quant_mode - QUANT_6]; for (unsigned int i = 0; i < scb.partition_count; i++) { int vals = 2 * (scb.color_formats[i] >> 2) + 2; assert(vals <= 8); for (int j = 0; j < vals; j++) { - values_to_encode[j + valuecount_to_encode] = scb.color_values[i][j]; + values_to_encode[j + valuecount_to_encode] = pack_table[scb.color_values[i][j]]; } valuecount_to_encode += vals; } @@ -503,17 +505,19 @@ void physical_to_symbolic( // Unpack the integer color values and assign to endpoints scb.quant_mode = static_cast(color_quant_level); + uint8_t values_to_decode[32]; decode_ise(static_cast(color_quant_level), color_integer_count, pcb.data, values_to_decode, (partition_count == 1 ? 17 : 19 + PARTITION_INDEX_BITS)); int valuecount_to_decode = 0; + const uint8_t* unpack_table = color_scrambled_pquant_to_uquant_tables[scb.quant_mode - QUANT_6]; for (int i = 0; i < partition_count; i++) { int vals = 2 * (color_formats[i] >> 2) + 2; for (int j = 0; j < vals; j++) { - scb.color_values[i][j] = values_to_decode[j + valuecount_to_decode]; + scb.color_values[i][j] = unpack_table[values_to_decode[j + valuecount_to_decode]]; } valuecount_to_decode += vals; }