From 03cca3778e611af3b99f6371346ed027bef370f1 Mon Sep 17 00:00:00 2001 From: JCash Date: Tue, 30 Mar 2021 18:44:07 +0200 Subject: [PATCH 1/2] Replaced std::min/std::max with basisu::min/basisu::max Removed use of NOMINMAX --- basisu_tool.cpp | 110 ++++++++++---------- encoder/basisu_astc_decomp.cpp | 2 +- encoder/basisu_comp.cpp | 6 +- encoder/basisu_enc.cpp | 13 ++- encoder/basisu_enc.h | 8 +- encoder/basisu_etc.cpp | 16 +-- encoder/basisu_gpu_texture.cpp | 2 +- encoder/basisu_kernels_declares.h | 2 +- encoder/basisu_pvrtc1_4.cpp | 2 +- encoder/basisu_uastc_enc.cpp | 38 +++---- transcoder/basisu.h | 7 +- transcoder/basisu_containers.h | 16 +-- transcoder/basisu_transcoder.cpp | 128 ++++++++++++------------ transcoder/basisu_transcoder_internal.h | 4 +- 14 files changed, 177 insertions(+), 177 deletions(-) diff --git a/basisu_tool.cpp b/basisu_tool.cpp index f9b6ea3..c233746 100644 --- a/basisu_tool.cpp +++ b/basisu_tool.cpp @@ -258,7 +258,7 @@ public: m_compare_ssim(false), m_bench(false) { - m_comp_params.m_compression_level = std::max(0, BASISU_DEFAULT_COMPRESSION_LEVEL - 1); + m_comp_params.m_compression_level = basisu::max(0, BASISU_DEFAULT_COMPRESSION_LEVEL - 1); } bool parse(int arg_c, const char **arg_v) @@ -961,13 +961,13 @@ static bool compress_mode(command_line_params &opts) for (size_t slice_index = 0; slice_index < c.get_stats().size(); slice_index++) { - rgb_avg_psnr_min = std::min(rgb_avg_psnr_min, c.get_stats()[slice_index].m_basis_rgb_avg_psnr); + rgb_avg_psnr_min = basisu::min(rgb_avg_psnr_min, c.get_stats()[slice_index].m_basis_rgb_avg_psnr); rgb_avg_psnr_avg += c.get_stats()[slice_index].m_basis_rgb_avg_psnr; - a_avg_psnr_min = std::min(a_avg_psnr_min, c.get_stats()[slice_index].m_basis_a_avg_psnr); + a_avg_psnr_min = basisu::min(a_avg_psnr_min, c.get_stats()[slice_index].m_basis_a_avg_psnr); a_avg_psnr_avg += c.get_stats()[slice_index].m_basis_a_avg_psnr; - luma_709_psnr_min = std::min(luma_709_psnr_min, c.get_stats()[slice_index].m_basis_luma_709_psnr); + luma_709_psnr_min = basisu::min(luma_709_psnr_min, c.get_stats()[slice_index].m_basis_luma_709_psnr); luma_709_psnr_avg += c.get_stats()[slice_index].m_basis_luma_709_psnr; } @@ -1582,8 +1582,8 @@ static bool unpack_and_validate_mode(command_line_params &opts) { for (uint32_t level_index = 0; level_index < fileinfo.m_image_mipmap_levels[image_index]; level_index++) { - max_mipmap_levels = std::max(max_mipmap_levels, fileinfo.m_image_mipmap_levels[image_index]); - + max_mipmap_levels = basisu::max(max_mipmap_levels, fileinfo.m_image_mipmap_levels[image_index]); + const basist::transcoder_texture_format transcoder_tex_fmt = basist::transcoder_texture_format::cTFRGBA4444; basist::basisu_image_level_info level_info; @@ -2015,7 +2015,7 @@ static bool bench_mode(command_line_params& opts) for (uint32_t bx = 0; bx < num_blocks_x; bx += N) { - const uint32_t num_blocks_to_process = std::min(num_blocks_x - bx, N); + const uint32_t num_blocks_to_process = basisu::min(num_blocks_x - bx, N); color_rgba pixels[16 * N]; @@ -2636,186 +2636,186 @@ static bool bench_mode(command_line_params& opts) // UASTC em.calc(img, uastc_img, 0, 3); em.print("UASTC RGB "); - total_uastc_psnr += std::min(99.0f, em.m_psnr); + total_uastc_psnr += basisu::min(99.0f, em.m_psnr); em.calc(img, uastc_img, 3, 1); em.print("UASTC A "); if (img_has_alpha) - total_uastc_a_psnr += std::min(99.0f, em.m_psnr); + total_uastc_a_psnr += basisu::min(99.0f, em.m_psnr); em.calc(img, uastc_img, 0, 4); em.print("UASTC RGBA "); - total_uastc_rgba_psnr += std::min(99.0f, em.m_psnr); + total_uastc_rgba_psnr += basisu::min(99.0f, em.m_psnr); // RDO UASTC em.calc(img, rdo_uastc_img, 0, 3); em.print("RDOUASTC RGB "); - total_rdo_uastc_psnr += std::min(99.0f, em.m_psnr); + total_rdo_uastc_psnr += basisu::min(99.0f, em.m_psnr); em.calc(img, rdo_uastc_img, 3, 1); em.print("RDOUASTC A "); if (img_has_alpha) - total_rdo_uastc_a_psnr += std::min(99.0f, em.m_psnr); + total_rdo_uastc_a_psnr += basisu::min(99.0f, em.m_psnr); em.calc(img, rdo_uastc_img, 0, 4); em.print("RDOUASTC RGBA "); - total_rdo_uastc_rgba_psnr += std::min(99.0f, em.m_psnr); + total_rdo_uastc_rgba_psnr += basisu::min(99.0f, em.m_psnr); // UASTC2 em.calc(img, uastc2_img, 0, 3); em.print("UASTC2 RGB "); - total_uastc2_psnr += std::min(99.0f, em.m_psnr); + total_uastc2_psnr += basisu::min(99.0f, em.m_psnr); em.calc(img, uastc2_img, 3, 1); em.print("UASTC2 A "); if (img_has_alpha) - total_uastc2_a_psnr += std::min(99.0f, em.m_psnr); + total_uastc2_a_psnr += basisu::min(99.0f, em.m_psnr); em.calc(img, uastc2_img, 0, 4); em.print("UASTC2 RGBA "); - total_uastc2_rgba_psnr += std::min(99.0f, em.m_psnr); + total_uastc2_rgba_psnr += basisu::min(99.0f, em.m_psnr); // BC7 em.calc(img, bc7_img, 0, 3); em.print("BC7 RGB "); - total_bc7_psnr += std::min(99.0f, em.m_psnr); + total_bc7_psnr += basisu::min(99.0f, em.m_psnr); em.calc(img, bc7_img, 3, 1); em.print("BC7 A "); if (img_has_alpha) - total_bc7_a_psnr += std::min(99.0f, em.m_psnr); + total_bc7_a_psnr += basisu::min(99.0f, em.m_psnr); em.calc(img, bc7_img, 0, 4); em.print("BC7 RGBA "); - total_bc7_rgba_psnr += std::min(99.0f, em.m_psnr); + total_bc7_rgba_psnr += basisu::min(99.0f, em.m_psnr); // RDO BC7 em.calc(img, rdo_bc7_img, 0, 3); em.print("RDOBC7 RGB "); - total_rdo_bc7_psnr += std::min(99.0f, em.m_psnr); + total_rdo_bc7_psnr += basisu::min(99.0f, em.m_psnr); em.calc(img, rdo_bc7_img, 3, 1); em.print("RDOBC7 A "); if (img_has_alpha) - total_rdo_bc7_a_psnr += std::min(99.0f, em.m_psnr); + total_rdo_bc7_a_psnr += basisu::min(99.0f, em.m_psnr); em.calc(img, rdo_bc7_img, 0, 4); em.print("RDOBC7 RGBA "); - total_rdo_bc7_rgba_psnr += std::min(99.0f, em.m_psnr); + total_rdo_bc7_rgba_psnr += basisu::min(99.0f, em.m_psnr); #if 0 // OBC7 em.calc(img, opt_bc7_img, 0, 3); em.print("OBC7 RGB "); - total_obc7_psnr += std::min(99.0f, em.m_psnr); + total_obc7_psnr += basisu::min(99.0f, em.m_psnr); em.calc(img, opt_bc7_img, 3, 1); em.print("OBC7 A "); if (img_has_alpha) - total_obc7_a_psnr += std::min(99.0f, em.m_psnr); + total_obc7_a_psnr += basisu::min(99.0f, em.m_psnr); em.calc(img, opt_bc7_img, 0, 4); em.print("OBC7 RGBA "); - total_obc7_rgba_psnr += std::min(99.0f, em.m_psnr); + total_obc7_rgba_psnr += basisu::min(99.0f, em.m_psnr); // OASTC em.calc(img, opt_astc_img, 0, 3); em.print("OASTC RGB "); - total_oastc_psnr += std::min(99.0f, em.m_psnr); + total_oastc_psnr += basisu::min(99.0f, em.m_psnr); em.calc(img, opt_astc_img, 3, 1); em.print("OASTC A "); if (img_has_alpha) - total_oastc_a_psnr += std::min(99.0f, em.m_psnr); + total_oastc_a_psnr += basisu::min(99.0f, em.m_psnr); em.calc(img, opt_astc_img, 0, 4); em.print("OASTC RGBA "); - total_oastc_rgba_psnr += std::min(99.0f, em.m_psnr); + total_oastc_rgba_psnr += basisu::min(99.0f, em.m_psnr); #endif // bc7enc em.calc(img, bc7enc_img, 0, 3); em.print("BC7ENC RGB "); - total_bc7enc_psnr += std::min(99.0f, em.m_psnr); + total_bc7enc_psnr += basisu::min(99.0f, em.m_psnr); em.calc(img, bc7enc_img, 3, 1); em.print("BC7ENC A "); if (img_has_alpha) - total_bc7enc_a_psnr += std::min(99.0f, em.m_psnr); + total_bc7enc_a_psnr += basisu::min(99.0f, em.m_psnr); em.calc(img, bc7enc_img, 0, 4); em.print("BC7ENC RGBA "); - total_bc7enc_rgba_psnr += std::min(99.0f, em.m_psnr); + total_bc7enc_rgba_psnr += basisu::min(99.0f, em.m_psnr); #if 1 // OBC1 em.calc(img, opt_bc1_img, 0, 3); em.print("OBC1 RGB "); - total_obc1_psnr += std::min(99.0f, em.m_psnr); - total_obc1_psnr_sq += std::min(99.0f, em.m_psnr) * std::min(99.0f, em.m_psnr); + total_obc1_psnr += basisu::min(99.0f, em.m_psnr); + total_obc1_psnr_sq += basisu::min(99.0f, em.m_psnr) * basisu::min(99.0f, em.m_psnr); #endif em.calc(img, opt_bc1_2_img, 0, 3); em.print("OBC1 2 RGB "); - total_obc1_2_psnr += std::min(99.0f, em.m_psnr); - total_obc1_2_psnr_sq += std::min(99.0f, em.m_psnr) * std::min(99.0f, em.m_psnr); + total_obc1_2_psnr += basisu::min(99.0f, em.m_psnr); + total_obc1_2_psnr_sq += basisu::min(99.0f, em.m_psnr) * basisu::min(99.0f, em.m_psnr); em.calc(img, bc1_img, 0, 3); em.print("BC1 RGB "); - total_bc1_psnr += std::min(99.0f, em.m_psnr); - total_bc1_psnr_sq += std::min(99.0f, em.m_psnr) * std::min(99.0f, em.m_psnr); + total_bc1_psnr += basisu::min(99.0f, em.m_psnr); + total_bc1_psnr_sq += basisu::min(99.0f, em.m_psnr) * basisu::min(99.0f, em.m_psnr); // ETC1 em.calc(img, etc1_img, 0, 3); em.print("ETC1 RGB "); - total_etc1_psnr += std::min(99.0f, em.m_psnr); + total_etc1_psnr += basisu::min(99.0f, em.m_psnr); em.calc(img, etc1_img, 0, 0); em.print("ETC1 Y "); - total_etc1_y_psnr += std::min(99.0f, em.m_psnr); + total_etc1_y_psnr += basisu::min(99.0f, em.m_psnr); // ETC1 em.calc(img, etc1_g_img, 1, 1); em.print("ETC1 G "); - total_etc1_g_psnr += std::min(99.0f, em.m_psnr); + total_etc1_g_psnr += basisu::min(99.0f, em.m_psnr); // ETC2 em.calc(img, etc2_img, 0, 3); em.print("ETC2 RGB "); - total_etc2_psnr += std::min(99.0f, em.m_psnr); + total_etc2_psnr += basisu::min(99.0f, em.m_psnr); em.calc(img, etc2_img, 3, 1); em.print("ETC2 A "); if (img_has_alpha) - total_etc2_a_psnr += std::min(99.0f, em.m_psnr); + total_etc2_a_psnr += basisu::min(99.0f, em.m_psnr); em.calc(img, etc2_img, 0, 4); em.print("ETC2 RGBA "); - total_etc2_rgba_psnr += std::min(99.0f, em.m_psnr); + total_etc2_rgba_psnr += basisu::min(99.0f, em.m_psnr); // BC3 em.calc(img, bc3_img, 0, 3); em.print("BC3 RGB "); - total_bc3_psnr += std::min(99.0f, em.m_psnr); + total_bc3_psnr += basisu::min(99.0f, em.m_psnr); em.calc(img, bc3_img, 3, 1); em.print("BC3 A "); if (img_has_alpha) - total_bc3_a_psnr += std::min(99.0f, em.m_psnr); + total_bc3_a_psnr += basisu::min(99.0f, em.m_psnr); em.calc(img, bc3_img, 0, 4); em.print("BC3 RGBA "); - total_bc3_rgba_psnr += std::min(99.0f, em.m_psnr); + total_bc3_rgba_psnr += basisu::min(99.0f, em.m_psnr); // EAC R11 em.calc(img, eac_r11_img, 0, 1); em.print("EAC R11 "); - total_eac_r11_psnr += std::min(99.0f, em.m_psnr); + total_eac_r11_psnr += basisu::min(99.0f, em.m_psnr); // EAC RG11 em.calc(img, eac_rg11_img, 0, 2); em.print("EAC RG11 "); - total_eac_rg11_psnr += std::min(99.0f, em.m_psnr); + total_eac_rg11_psnr += basisu::min(99.0f, em.m_psnr); const uint32_t width = num_blocks_x * 4; const uint32_t height = num_blocks_y * 4; @@ -2863,15 +2863,15 @@ static bool bench_mode(command_line_params& opts) em.calc(img, pi_unpacked, 0, 3); em.print("PVRTC1 After RGB "); - total_pvrtc1_rgb_psnr += std::min(99.0f, em.m_psnr); + total_pvrtc1_rgb_psnr += basisu::min(99.0f, em.m_psnr); em.calc(img, pi_unpacked, 3, 1); em.print("PVRTC1 After A "); - total_pvrtc1_a_psnr += std::min(99.0f, em.m_psnr); + total_pvrtc1_a_psnr += basisu::min(99.0f, em.m_psnr); em.calc(img, pi_unpacked, 0, 4); em.print("PVRTC1 After RGBA "); - total_pvrtc1_rgba_psnr += std::min(99.0f, em.m_psnr); + total_pvrtc1_rgba_psnr += basisu::min(99.0f, em.m_psnr); total_pvrtc1_images++; } @@ -2925,11 +2925,11 @@ static bool bench_mode(command_line_params& opts) //printf("Avg Opt ASTC RGB PSNR: %f, A PSNR: %f, RGBA PSNR: %f\n", total_oastc_psnr / total_images, total_oastc_a_psnr / total_a_images, total_oastc_rgba_psnr / total_images); printf("Avg BC7ENC RGB PSNR: %f, A PSNR: %f, RGBA PSNR: %f\n", total_bc7enc_psnr / total_images, total_bc7enc_a_psnr / total_a_images, total_bc7enc_rgba_psnr / total_images); - printf("Avg Opt BC1 PSNR: %f, std dev: %f\n", total_obc1_psnr / total_images, sqrtf(std::max(0.0f, (total_obc1_psnr_sq / total_images) - (total_obc1_psnr / total_images) * (total_obc1_psnr / total_images)))); - - printf("Avg Opt BC1 2 PSNR: %f, std dev: %f\n", total_obc1_2_psnr / total_images, sqrtf(std::max(0.0f, (total_obc1_2_psnr_sq / total_images) - (total_obc1_2_psnr / total_images) * (total_obc1_2_psnr / total_images)))); + printf("Avg Opt BC1 PSNR: %f, std dev: %f\n", total_obc1_psnr / total_images, sqrtf(basisu::max(0.0f, (total_obc1_psnr_sq / total_images) - (total_obc1_psnr / total_images) * (total_obc1_psnr / total_images)))); - printf("Avg BC1 PSNR: %f, std dev: %f\n", total_bc1_psnr / total_images, sqrtf(std::max(0.0f, (total_bc1_psnr_sq / total_images) - (total_bc1_psnr / total_images) * (total_bc1_psnr / total_images)))); + printf("Avg Opt BC1 2 PSNR: %f, std dev: %f\n", total_obc1_2_psnr / total_images, sqrtf(basisu::max(0.0f, (total_obc1_2_psnr_sq / total_images) - (total_obc1_2_psnr / total_images) * (total_obc1_2_psnr / total_images)))); + + printf("Avg BC1 PSNR: %f, std dev: %f\n", total_bc1_psnr / total_images, sqrtf(basisu::max(0.0f, (total_bc1_psnr_sq / total_images) - (total_bc1_psnr / total_images) * (total_bc1_psnr / total_images)))); printf("Avg ETC1 RGB PSNR: %f\n", total_etc1_psnr / total_images); printf("Avg ETC1 Y PSNR: %f\n", total_etc1_y_psnr / total_images); diff --git a/encoder/basisu_astc_decomp.cpp b/encoder/basisu_astc_decomp.cpp index 22e52b4..aa941b9 100644 --- a/encoder/basisu_astc_decomp.cpp +++ b/encoder/basisu_astc_decomp.cpp @@ -157,7 +157,7 @@ namespace basisu_astc UVec4 asUint() const { - return UVec4(std::max(0, m_c[0]), std::max(0, m_c[1]), std::max(0, m_c[2]), std::max(0, m_c[3])); + return UVec4(basisu::max(0, m_c[0]), basisu::max(0, m_c[1]), basisu::max(0, m_c[2]), basisu::max(0, m_c[3])); } int32_t operator[] (uint32_t idx) const { assert(idx < 4); return m_c[idx]; } diff --git a/encoder/basisu_comp.cpp b/encoder/basisu_comp.cpp index b4ee077..0df4521 100644 --- a/encoder/basisu_comp.cpp +++ b/encoder/basisu_comp.cpp @@ -267,7 +267,7 @@ namespace basisu bool status = uastc_rdo(tex.get_total_blocks(), (basist::uastc_block*)tex.get_ptr(), (const color_rgba *)m_source_blocks[slice_desc.m_first_block_index].m_pixels, rdo_params, m_params.m_pack_uastc_flags, m_params.m_rdo_uastc_multithreading ? m_params.m_pJob_pool : nullptr, - (m_params.m_rdo_uastc_multithreading && m_params.m_pJob_pool) ? std::min(4, (uint32_t)m_params.m_pJob_pool->get_total_threads()) : 0); + (m_params.m_rdo_uastc_multithreading && m_params.m_pJob_pool) ? basisu::min(4, (uint32_t)m_params.m_pJob_pool->get_total_threads()) : 0); if (!status) { return cECFailedUASTCRDOPostProcess; @@ -489,8 +489,8 @@ namespace basisu if (m_params.m_resample_factor > 0.0f) { - int new_width = std::min(std::max(1, (int)ceilf(file_image.get_width() * m_params.m_resample_factor)), BASISU_MAX_SUPPORTED_TEXTURE_DIMENSION); - int new_height = std::min(std::max(1, (int)ceilf(file_image.get_height() * m_params.m_resample_factor)), BASISU_MAX_SUPPORTED_TEXTURE_DIMENSION); + int new_width = basisu::min(basisu::max(1, (int)ceilf(file_image.get_width() * m_params.m_resample_factor)), BASISU_MAX_SUPPORTED_TEXTURE_DIMENSION); + int new_height = basisu::min(basisu::max(1, (int)ceilf(file_image.get_height() * m_params.m_resample_factor)), BASISU_MAX_SUPPORTED_TEXTURE_DIMENSION); debug_printf("Resampling to %ix%i\n", new_width, new_height); diff --git a/encoder/basisu_enc.cpp b/encoder/basisu_enc.cpp index d046888..e795653 100644 --- a/encoder/basisu_enc.cpp +++ b/encoder/basisu_enc.cpp @@ -26,7 +26,6 @@ #if defined(_WIN32) // For QueryPerformanceCounter/QueryPerformanceFrequency #define WIN32_LEAN_AND_MEAN -#define NOMINMAX #include #endif @@ -1308,10 +1307,10 @@ namespace basisu void image_metrics::calc(const image &a, const image &b, uint32_t first_chan, uint32_t total_chans, bool avg_comp_error, bool use_601_luma) { assert((first_chan < 4U) && (first_chan + total_chans <= 4U)); - - const uint32_t width = std::min(a.get_width(), b.get_width()); - const uint32_t height = std::min(a.get_height(), b.get_height()); - + + const uint32_t width = basisu::min(a.get_width(), b.get_width()); + const uint32_t height = basisu::min(a.get_height(), b.get_height()); + double hist[256]; clear_obj(hist); @@ -1342,7 +1341,7 @@ namespace basisu { if (hist[i]) { - m_max = std::max(m_max, (float)i); + m_max = basisu::max(m_max, (float)i); double v = i * hist[i]; sum += v; sum2 += i * v; @@ -1824,7 +1823,7 @@ namespace basisu } } - const uint32_t n = std::min(pixels_remaining, run_remaining); + const uint32_t n = basisu::min(pixels_remaining, run_remaining); pixels_remaining -= n; run_remaining -= n; diff --git a/encoder/basisu_enc.h b/encoder/basisu_enc.h index aadc861..142425b 100644 --- a/encoder/basisu_enc.h +++ b/encoder/basisu_enc.h @@ -194,8 +194,8 @@ namespace basisu m_new_s = m_old_s + (x - m_old_m) * (x - m_new_m); m_old_m = m_new_m; m_old_s = m_new_s; - m_min = std::min(x, m_min); - m_max = std::max(x, m_max); + m_min = basisu::min(x, m_min); + m_max = basisu::max(x, m_max); } } uint32_t get_num() const @@ -741,8 +741,8 @@ namespace basisu return basist::color32(r, g, b, a); } - static color_rgba comp_min(const color_rgba& a, const color_rgba& b) { return color_rgba(std::min(a[0], b[0]), std::min(a[1], b[1]), std::min(a[2], b[2]), std::min(a[3], b[3])); } - static color_rgba comp_max(const color_rgba& a, const color_rgba& b) { return color_rgba(std::max(a[0], b[0]), std::max(a[1], b[1]), std::max(a[2], b[2]), std::max(a[3], b[3])); } + static color_rgba comp_min(const color_rgba& a, const color_rgba& b) { return color_rgba(basisu::min(a[0], b[0]), basisu::min(a[1], b[1]), basisu::min(a[2], b[2]), basisu::min(a[3], b[3])); } + static color_rgba comp_max(const color_rgba& a, const color_rgba& b) { return color_rgba(basisu::max(a[0], b[0]), basisu::max(a[1], b[1]), basisu::max(a[2], b[2]), basisu::max(a[3], b[3])); } }; typedef basisu::vector color_rgba_vec; diff --git a/encoder/basisu_etc.cpp b/encoder/basisu_etc.cpp index 34cca98..b488731 100644 --- a/encoder/basisu_etc.cpp +++ b/encoder/basisu_etc.cpp @@ -1006,13 +1006,13 @@ namespace basisu { const color_rgba& c = m_pParams->m_pSrc_pixels[i]; - min_r = std::min(min_r, c.r); - min_g = std::min(min_g, c.g); - min_b = std::min(min_b, c.b); + min_r = basisu::min(min_r, c.r); + min_g = basisu::min(min_g, c.g); + min_b = basisu::min(min_b, c.b); - max_r = std::max(max_r, c.r); - max_g = std::max(max_g, c.g); - max_b = std::max(max_b, c.b); + max_r = basisu::max(max_r, c.r); + max_g = basisu::max(max_g, c.g); + max_b = basisu::max(max_b, c.b); const vec3F fc(c.r, c.g, c.b); @@ -1023,8 +1023,8 @@ namespace basisu } avg_color /= static_cast(n); m_avg_color = avg_color; - m_max_comp_spread = std::max(std::max(max_r - min_r, max_g - min_g), max_b - min_b); - + m_max_comp_spread = basisu::max(basisu::max(max_r - min_r, max_g - min_g), max_b - min_b); + m_br = clamp(static_cast(m_avg_color[0] * m_limit / 255.0f + .5f), 0, m_limit); m_bg = clamp(static_cast(m_avg_color[1] * m_limit / 255.0f + .5f), 0, m_limit); m_bb = clamp(static_cast(m_avg_color[2] * m_limit / 255.0f + .5f), 0, m_limit); diff --git a/encoder/basisu_gpu_texture.cpp b/encoder/basisu_gpu_texture.cpp index 5ed2c0e..83c444b 100644 --- a/encoder/basisu_gpu_texture.cpp +++ b/encoder/basisu_gpu_texture.cpp @@ -399,7 +399,7 @@ namespace basisu if (mode) { - c[1].set(std::max(0, c[0].r - (c[3].r >> 2)), std::max(0, c[0].g - (c[3].g >> 2)), std::max(0, c[0].b - (c[3].b >> 2)), 255); + c[1].set(basisu::max(0, c[0].r - (c[3].r >> 2)), basisu::max(0, c[0].g - (c[3].g >> 2)), basisu::max(0, c[0].b - (c[3].b >> 2)), 255); c[2] = c[0]; c[0].set(0, 0, 0, 255); } diff --git a/encoder/basisu_kernels_declares.h b/encoder/basisu_kernels_declares.h index 2872604..e24bdd7 100644 --- a/encoder/basisu_kernels_declares.h +++ b/encoder/basisu_kernels_declares.h @@ -22,4 +22,4 @@ void CPPSPMD_NAME(find_selectors_linear_rgb_4_N)(int64_t* pDistance, uint8_t* pS void CPPSPMD_NAME(find_lowest_error_perceptual_rgb_4_N)(int64_t* pDistance, const basisu::color_rgba* pBlock_colors, const basisu::color_rgba* pSrc_pixels, uint32_t n, int64_t early_out_error); void CPPSPMD_NAME(find_lowest_error_linear_rgb_4_N)(int64_t* pDistance, const basisu::color_rgba* pBlock_colors, const basisu::color_rgba* pSrc_pixels, uint32_t n, int64_t early_out_error); -#endif \ No newline at end of file +#endif diff --git a/encoder/basisu_pvrtc1_4.cpp b/encoder/basisu_pvrtc1_4.cpp index 83c2052..f3e4ce4 100644 --- a/encoder/basisu_pvrtc1_4.cpp +++ b/encoder/basisu_pvrtc1_4.cpp @@ -529,7 +529,7 @@ namespace basisu uint64_t e03_err_1 = remap_pixels_influenced_by_endpoint(bx, by, orig_img, perceptual, false); - if (initial_error < std::min(e03_err_0, e03_err_1)) + if (initial_error < basisu::min(e03_err_0, e03_err_1)) { for (int y = -1; y <= 1; y++) { diff --git a/encoder/basisu_uastc_enc.cpp b/encoder/basisu_uastc_enc.cpp index 5dc7ea8..a412cf5 100644 --- a/encoder/basisu_uastc_enc.cpp +++ b/encoder/basisu_uastc_enc.cpp @@ -1630,7 +1630,7 @@ namespace basisu else if (estimate_partition_list_size > 0) { assert(estimate_partition_list_size <= MAX_PARTS); - estimate_partition_list_size = std::min(estimate_partition_list_size, MAX_PARTS); + estimate_partition_list_size = basisu::min(estimate_partition_list_size, MAX_PARTS); estimate_partition2_list(4, 4, g_bc7_weights2, (const color_rgba(*)[4])pBlock, parts, estimate_partition_list_size, weights); @@ -2817,13 +2817,13 @@ namespace basisu avg_color[1] += p.g; avg_color[2] += p.b; - min_r[subset] = std::min(min_r[subset], p.r); - min_g[subset] = std::min(min_g[subset], p.g); - min_b[subset] = std::min(min_b[subset], p.b); - - max_r[subset] = std::max(max_r[subset], p.r); - max_g[subset] = std::max(max_g[subset], p.g); - max_b[subset] = std::max(max_b[subset], p.b); + min_r[subset] = basisu::min(min_r[subset], p.r); + min_g[subset] = basisu::min(min_g[subset], p.g); + min_b[subset] = basisu::min(min_b[subset], p.b); + + max_r[subset] = basisu::max(max_r[subset], p.r); + max_g[subset] = basisu::max(max_g[subset], p.g); + max_b[subset] = basisu::max(max_b[subset], p.b); } // j unbiased_block_colors[subset][0] = (uint8_t)((avg_color[0] * mul + 1020) / (8 * 255)); @@ -3769,7 +3769,7 @@ namespace basisu dist_cost += g_tdefl_small_dist_extra[dist & 511]; else { - dist_cost += g_tdefl_large_dist_extra[std::min(dist, 32767) >> 8]; + dist_cost += g_tdefl_large_dist_extra[basisu::min(dist, 32767) >> 8]; while (dist >= 32768) { dist_cost++; @@ -3839,7 +3839,7 @@ namespace basisu { debug_printf("uastc_rdo_blocks: Processing blocks %u to %u\n", first_index, last_index); - const int total_blocks_to_check = std::max(1U, params.m_lz_dict_size / sizeof(basist::uastc_block)); + const int total_blocks_to_check = basisu::max(1U, params.m_lz_dict_size / sizeof(basist::uastc_block)); const bool perceptual = false; std::unordered_map selector_history; @@ -3867,8 +3867,8 @@ namespace basisu a_stats.update(pPixels[i].a); } - const float max_std_dev = std::max(std::max(std::max(r_stats.get_std_dev(), g_stats.get_std_dev()), b_stats.get_std_dev()), a_stats.get_std_dev()); - + const float max_std_dev = basisu::max(basisu::max(basisu::max(r_stats.get_std_dev(), g_stats.get_std_dev()), b_stats.get_std_dev()), a_stats.get_std_dev()); + float yl = clamp(max_std_dev / params.m_max_smooth_block_std_dev, 0.0f, 1.0f); yl = yl * yl; const float smooth_block_error_scale = lerp(params.m_smooth_block_max_error_scale, 1.0f, yl); @@ -3910,8 +3910,8 @@ namespace basisu assert(total_sel_bits > 0); uint32_t cur_bit_offset = first_sel_bit; - uint64_t cur_sel_bits = read_bits((const uint8_t*)&blk, cur_bit_offset, std::min(64U, total_sel_bits)); - + uint64_t cur_sel_bits = read_bits((const uint8_t*)&blk, cur_bit_offset, basisu::min(64U, total_sel_bits)); + if (cur_rms_err >= params.m_skip_block_rms_thresh) { auto cur_search_res = selector_history.insert(std::make_pair(selector_bitsequence(first_sel_bit, cur_sel_bits), block_index)); @@ -3940,7 +3940,7 @@ namespace basisu cur_bits = compute_match_cost_estimate(block_dist_in_bytes); } - int first_block_to_check = std::max(first_index, block_index - total_blocks_to_check); + int first_block_to_check = basisu::max(first_index, block_index - total_blocks_to_check); int last_block_to_check = block_index - 1; basist::uastc_block best_block(blk); @@ -3955,7 +3955,7 @@ namespace basisu const basist::uastc_block& prev_blk = pBlocks[prev_block_index]; uint32_t bit_offset = first_sel_bit; - uint64_t sel_bits = read_bits((const uint8_t*)&prev_blk, bit_offset, std::min(64U, total_sel_bits)); + uint64_t sel_bits = read_bits((const uint8_t*)&prev_blk, bit_offset, basisu::min(64U, total_sel_bits)); int match_block_index = prev_block_index; auto res = selector_history.find(selector_bitsequence(first_sel_bit, sel_bits)); @@ -3971,13 +3971,13 @@ namespace basisu basist::uastc_block trial_blk(blk); - set_block_bits((uint8_t*)&trial_blk, sel_bits, std::min(64U, total_sel_bits), first_sel_bit); + set_block_bits((uint8_t*)&trial_blk, sel_bits, basisu::min(64U, total_sel_bits), first_sel_bit); if (total_sel_bits > 64) { sel_bits = read_bits((const uint8_t*)&prev_blk, bit_offset, total_sel_bits - 64U); - set_block_bits((uint8_t*)&trial_blk, sel_bits, total_sel_bits - 64U, first_sel_bit + std::min(64U, total_sel_bits)); + set_block_bits((uint8_t*)&trial_blk, sel_bits, total_sel_bits - 64U, first_sel_bit + basisu::min(64U, total_sel_bits)); } unpacked_uastc_block unpacked_trial_blk; @@ -4102,7 +4102,7 @@ namespace basisu { uint32_t bit_offset = first_sel_bit; - uint64_t sel_bits = read_bits((const uint8_t*)&best_block, bit_offset, std::min(64U, total_sel_bits)); + uint64_t sel_bits = read_bits((const uint8_t*)&best_block, bit_offset, basisu::min(64U, total_sel_bits)); auto res = selector_history.insert(std::make_pair(selector_bitsequence(first_sel_bit, sel_bits), block_index)); if (!res.second) diff --git a/transcoder/basisu.h b/transcoder/basisu.h index 9d8dfa6..5e82e4c 100644 --- a/transcoder/basisu.h +++ b/transcoder/basisu.h @@ -41,10 +41,6 @@ #endif #endif // defined(_DEBUG) || defined(DEBUG) - #ifndef NOMINMAX - #define NOMINMAX - #endif - #endif // BASISU_NO_ITERATOR_DEBUG_LEVEL #endif // _MSC_VER @@ -122,6 +118,9 @@ namespace basisu template inline void clear_obj(T& obj) { memset(&obj, 0, sizeof(obj)); } + template const T& min(const T& a, const T& b) { return (b < a) ? b : a; } + template const T& max(const T& a, const T& b) { return (a < b) ? b : a; } + template inline T0 lerp(T0 a, T0 b, T1 c) { return a + (b - a) * c; } template inline S maximum(S a, S b) { return (a > b) ? a : b; } diff --git a/transcoder/basisu_containers.h b/transcoder/basisu_containers.h index 9a31766..14a02e8 100644 --- a/transcoder/basisu_containers.h +++ b/transcoder/basisu_containers.h @@ -26,6 +26,8 @@ namespace basisu { inline bool is_power_of_2(uint32_t x) { return x && ((x & (x - 1U)) == 0U); } inline bool is_power_of_2(uint64_t x) { return x && ((x & (x - 1U)) == 0U); } + template const T& minimum(const T& a, const T& b) { return (b < a) ? b : a; } + template const T& maximum(const T& a, const T& b) { return (a < b) ? b : a; } inline uint32_t floor_log2i(uint32_t v) { @@ -408,7 +410,7 @@ namespace basisu // Must work around the lack of a "decrease_capacity()" method. // This case is rare enough in practice that it's probably not worth implementing an optimized in-place resize. vector tmp; - tmp.increase_capacity(std::max(m_size, new_capacity), false); + tmp.increase_capacity(helpers::maximum(m_size, new_capacity), false); tmp = *this; swap(tmp); } @@ -735,7 +737,7 @@ namespace basisu inline bool operator< (const vector& rhs) const { - const uint32_t min_size = std::min(m_size, rhs.m_size); + const uint32_t min_size = helpers::minimum(m_size, rhs.m_size); const T* pSrc = m_p; const T* pSrc_end = m_p + min_size; @@ -1188,16 +1190,16 @@ namespace basisu inline void reserve(uint32_t new_capacity) { - uint64_t new_hash_size = std::max(1U, new_capacity); + uint64_t new_hash_size = helpers::maximum(1U, new_capacity); new_hash_size = new_hash_size * 2ULL; if (!helpers::is_power_of_2(new_hash_size)) new_hash_size = helpers::next_pow2(new_hash_size); - new_hash_size = std::max(cMinHashSize, new_hash_size); + new_hash_size = helpers::maximum(cMinHashSize, new_hash_size); - new_hash_size = std::min(0x80000000UL, new_hash_size); + new_hash_size = helpers::minimum(0x80000000UL, new_hash_size); if (new_hash_size > m_values.size()) rehash((uint32_t)new_hash_size); @@ -1646,7 +1648,7 @@ namespace basisu if (n > 0x80000000UL) n = 0x80000000UL; - rehash(std::max(cMinHashSize, (uint32_t)n)); + rehash(helpers::maximum(cMinHashSize, (uint32_t)n)); } inline void rehash(uint32_t new_hash_size) @@ -1877,4 +1879,4 @@ namespace std a.swap(b); } -} // namespace std \ No newline at end of file +} // namespace std diff --git a/transcoder/basisu_transcoder.cpp b/transcoder/basisu_transcoder.cpp index a0e0b74..a7d3e76 100644 --- a/transcoder/basisu_transcoder.cpp +++ b/transcoder/basisu_transcoder.cpp @@ -5082,7 +5082,7 @@ namespace basist while (total_bits) { - const uint32_t bits_to_write = std::min(total_bits, 8 - (bit_pos & 7)); + const uint32_t bits_to_write = basisu::min(total_bits, 8 - (bit_pos & 7)); pBytes[bit_pos >> 3] |= static_cast(value << (bit_pos & 7)); @@ -11893,7 +11893,7 @@ namespace basist { uint8_t vals[5] = { 0, 0, 0, 0, 0 }; - const int limit = std::min(group_size, num_vals - group_index * group_size); + const int limit = basisu::min(group_size, num_vals - group_index * group_size); for (int i = 0; i < limit; i++) vals[i] = pSrc_vals[group_index * group_size + i]; @@ -12480,7 +12480,7 @@ namespace basist // Read the weight bits if ((BASISD_IS_BIG_ENDIAN) || (!BASISD_USE_UNALIGNED_WORD_READS)) - bits = read_bits64(blk.m_bytes, bit_ofs, std::min(64, 128 - (int)bit_ofs)); + bits = read_bits64(blk.m_bytes, bit_ofs, basisu::min(64, 128 - (int)bit_ofs)); else { #ifdef __EMSCRIPTEN__ @@ -12649,7 +12649,7 @@ namespace basist color32 endpoints[3][2]; const uint32_t total_subsets = g_uastc_mode_subsets[mode]; - const uint32_t total_comps = std::min(4U, g_uastc_mode_comps[mode]); + const uint32_t total_comps = basisu::min(4U, g_uastc_mode_comps[mode]); const uint32_t endpoint_range = g_uastc_mode_endpoint_ranges[mode]; const uint32_t total_planes = g_uastc_mode_planes[mode]; const uint32_t weight_bits = g_uastc_mode_weight_bits[mode]; @@ -13845,7 +13845,7 @@ namespace basist uint32_t sels[4] = { 0,0,0,0 }; const uint32_t N = 4; - for (uint32_t i = 0; i < std::min(N, (256 - c)); i++) + for (uint32_t i = 0; i < basisu::min(N, (256 - c)); i++) { uint32_t best_sel_e = UINT32_MAX; uint32_t best_sel = 0; @@ -13925,7 +13925,7 @@ namespace basist uint32_t sels[4] = { 0,0,0,0 }; const uint32_t N = 1; - for (uint32_t i = 0; i < std::min(N, (256 - c)); i++) + for (uint32_t i = 0; i < basisu::min(N, (256 - c)); i++) { uint32_t best_sel_e = UINT32_MAX; uint32_t best_sel = 0; @@ -14029,8 +14029,8 @@ namespace basist for (uint32_t x = 0; x < 4; x++) { const uint32_t v = block_y[y][x]; - low[0] = std::min(low[0], v); - high[0] = std::max(high[0], v); + low[0] = basisu::min(low[0], v); + high[0] = basisu::max(high[0], v); } } for (uint32_t y = 2; y < 4; y++) @@ -14038,8 +14038,8 @@ namespace basist for (uint32_t x = 0; x < 4; x++) { const uint32_t v = block_y[y][x]; - low[1] = std::min(low[1], v); - high[1] = std::max(high[1], v); + low[1] = basisu::min(low[1], v); + high[1] = basisu::max(high[1], v); } } } @@ -14050,8 +14050,8 @@ namespace basist for (uint32_t x = 0; x < 2; x++) { const uint32_t v = block_y[y][x]; - low[0] = std::min(low[0], v); - high[0] = std::max(high[0], v); + low[0] = basisu::min(low[0], v); + high[0] = basisu::max(high[0], v); } } for (uint32_t y = 0; y < 4; y++) @@ -14059,8 +14059,8 @@ namespace basist for (uint32_t x = 2; x < 4; x++) { const uint32_t v = block_y[y][x]; - low[1] = std::min(low[1], v); - high[1] = std::max(high[1], v); + low[1] = basisu::min(low[1], v); + high[1] = basisu::max(high[1], v); } } } @@ -14320,10 +14320,10 @@ namespace basist if ((inten_table_mask & (1 << inten)) == 0) continue; - const int t0 = std::max(low_limit, g_etc1_inten_tables[inten][0]); - const int t1 = std::max(low_limit, g_etc1_inten_tables[inten][1]); - const int t2 = std::min(high_limit, g_etc1_inten_tables[inten][2]); - const int t3 = std::min(high_limit, g_etc1_inten_tables[inten][3]); + const int t0 = basisu::max(low_limit, g_etc1_inten_tables[inten][0]); + const int t1 = basisu::max(low_limit, g_etc1_inten_tables[inten][1]); + const int t2 = basisu::min(high_limit, g_etc1_inten_tables[inten][2]); + const int t3 = basisu::min(high_limit, g_etc1_inten_tables[inten][3]); assert((t0 <= t1) && (t1 <= t2) && (t2 <= t3)); const int tv[4] = { t2, t3, t1, t0 }; @@ -14541,8 +14541,8 @@ namespace basist uint32_t min_a = 255, max_a = 0; for (uint32_t i = 0; i < 16; i++) { - min_a = std::min(min_a, pSrc_pixels[i].a); - max_a = std::max(max_a, pSrc_pixels[i].a); + min_a = basisu::min(min_a, pSrc_pixels[i].a); + max_a = basisu::max(max_a, pSrc_pixels[i].a); } if (min_a == max_a) @@ -14640,24 +14640,24 @@ namespace basist } { - uint32_t v0 = pPixels[4 * stride]; min0_v = std::min(min0_v, v0); max0_v = std::max(max0_v, v0); - uint32_t v1 = pPixels[5 * stride]; min1_v = std::min(min1_v, v1); max1_v = std::max(max1_v, v1); - uint32_t v2 = pPixels[6 * stride]; min2_v = std::min(min2_v, v2); max2_v = std::max(max2_v, v2); - uint32_t v3 = pPixels[7 * stride]; min3_v = std::min(min3_v, v3); max3_v = std::max(max3_v, v3); + uint32_t v0 = pPixels[4 * stride]; min0_v = basisu::min(min0_v, v0); max0_v = basisu::max(max0_v, v0); + uint32_t v1 = pPixels[5 * stride]; min1_v = basisu::min(min1_v, v1); max1_v = basisu::max(max1_v, v1); + uint32_t v2 = pPixels[6 * stride]; min2_v = basisu::min(min2_v, v2); max2_v = basisu::max(max2_v, v2); + uint32_t v3 = pPixels[7 * stride]; min3_v = basisu::min(min3_v, v3); max3_v = basisu::max(max3_v, v3); } { - uint32_t v0 = pPixels[8 * stride]; min0_v = std::min(min0_v, v0); max0_v = std::max(max0_v, v0); - uint32_t v1 = pPixels[9 * stride]; min1_v = std::min(min1_v, v1); max1_v = std::max(max1_v, v1); - uint32_t v2 = pPixels[10 * stride]; min2_v = std::min(min2_v, v2); max2_v = std::max(max2_v, v2); - uint32_t v3 = pPixels[11 * stride]; min3_v = std::min(min3_v, v3); max3_v = std::max(max3_v, v3); + uint32_t v0 = pPixels[8 * stride]; min0_v = basisu::min(min0_v, v0); max0_v = basisu::max(max0_v, v0); + uint32_t v1 = pPixels[9 * stride]; min1_v = basisu::min(min1_v, v1); max1_v = basisu::max(max1_v, v1); + uint32_t v2 = pPixels[10 * stride]; min2_v = basisu::min(min2_v, v2); max2_v = basisu::max(max2_v, v2); + uint32_t v3 = pPixels[11 * stride]; min3_v = basisu::min(min3_v, v3); max3_v = basisu::max(max3_v, v3); } { - uint32_t v0 = pPixels[12 * stride]; min0_v = std::min(min0_v, v0); max0_v = std::max(max0_v, v0); - uint32_t v1 = pPixels[13 * stride]; min1_v = std::min(min1_v, v1); max1_v = std::max(max1_v, v1); - uint32_t v2 = pPixels[14 * stride]; min2_v = std::min(min2_v, v2); max2_v = std::max(max2_v, v2); - uint32_t v3 = pPixels[15 * stride]; min3_v = std::min(min3_v, v3); max3_v = std::max(max3_v, v3); + uint32_t v0 = pPixels[12 * stride]; min0_v = basisu::min(min0_v, v0); max0_v = basisu::max(max0_v, v0); + uint32_t v1 = pPixels[13 * stride]; min1_v = basisu::min(min1_v, v1); max1_v = basisu::max(max1_v, v1); + uint32_t v2 = pPixels[14 * stride]; min2_v = basisu::min(min2_v, v2); max2_v = basisu::max(max2_v, v2); + uint32_t v3 = pPixels[15 * stride]; min3_v = basisu::min(min3_v, v3); max3_v = basisu::max(max3_v, v3); } const uint32_t min_v = basisu::minimum(min0_v, min1_v, min2_v, min3_v); @@ -14982,8 +14982,8 @@ namespace basist for (uint32_t i = 1; i < 16; i++) { const int r = pSrc_pixels[i].r, g = pSrc_pixels[i].g, b = pSrc_pixels[i].b; - max_r = std::max(max_r, r); max_g = std::max(max_g, g); max_b = std::max(max_b, b); - min_r = std::min(min_r, r); min_g = std::min(min_g, g); min_b = std::min(min_b, b); + max_r = basisu::max(max_r, r); max_g = basisu::max(max_g, g); max_b = basisu::max(max_b, b); + min_r = basisu::min(min_r, r); min_g = basisu::min(min_g, g); min_b = basisu::min(min_b, b); total_r += r; total_g += g; total_b += b; } @@ -15214,8 +15214,8 @@ namespace basist { const int r = pSrc_pixels[i].r, g = pSrc_pixels[i].g, b = pSrc_pixels[i].b; grayscale_flag &= ((r == g) && (r == b)); - max_r = std::max(max_r, r); max_g = std::max(max_g, g); max_b = std::max(max_b, b); - min_r = std::min(min_r, r); min_g = std::min(min_g, g); min_b = std::min(min_b, b); + max_r = basisu::max(max_r, r); max_g = basisu::max(max_g, g); max_b = basisu::max(max_b, b); + min_r = basisu::min(min_r, r); min_g = basisu::min(min_g, g); min_b = basisu::min(min_b, b); total_r += r; total_g += g; total_b += b; } @@ -15252,25 +15252,25 @@ namespace basist uint32_t min_d0 = (dist[0][0] + dist[1][0] + dist[2][0]); uint32_t d4 = (dist[0][0] + dist[1][0] + dist[2][1]) | 4; - min_d0 = std::min(min_d0, d4); + min_d0 = basisu::min(min_d0, d4); uint32_t min_d1 = (dist[0][1] + dist[1][0] + dist[2][0]) | 1; uint32_t d5 = (dist[0][1] + dist[1][0] + dist[2][1]) | 5; - min_d1 = std::min(min_d1, d5); + min_d1 = basisu::min(min_d1, d5); uint32_t d2 = (dist[0][0] + dist[1][1] + dist[2][0]) | 2; - min_d0 = std::min(min_d0, d2); + min_d0 = basisu::min(min_d0, d2); uint32_t d3 = (dist[0][1] + dist[1][1] + dist[2][0]) | 3; - min_d1 = std::min(min_d1, d3); + min_d1 = basisu::min(min_d1, d3); uint32_t d6 = (dist[0][0] + dist[1][1] + dist[2][1]) | 6; - min_d0 = std::min(min_d0, d6); + min_d0 = basisu::min(min_d0, d6); uint32_t d7 = (dist[0][1] + dist[1][1] + dist[2][1]) | 7; - min_d1 = std::min(min_d1, d7); + min_d1 = basisu::min(min_d1, d7); - uint32_t min_d = std::min(min_d0, min_d1); + uint32_t min_d = basisu::min(min_d0, min_d1); uint32_t best_i = min_d & 7; int delta_r = (best_i & 1) ? (max_r - avg_r) : (avg_r - min_r); @@ -15855,10 +15855,10 @@ namespace basist const int v2 = clamp255(mul[2] * g_eac_modifier_table[T2][s] + base[2]); const int v3 = clamp255(mul[3] * g_eac_modifier_table[T3][s] + base[3]); - l0 = std::min(l0, (basisu::iabs(v0 - a) << 3) | s); - l1 = std::min(l1, (basisu::iabs(v1 - a) << 3) | s); - l2 = std::min(l2, (basisu::iabs(v2 - a) << 3) | s); - l3 = std::min(l3, (basisu::iabs(v3 - a) << 3) | s); + l0 = basisu::min(l0, (basisu::iabs(v0 - a) << 3) | s); + l1 = basisu::min(l1, (basisu::iabs(v1 - a) << 3) | s); + l2 = basisu::min(l2, (basisu::iabs(v2 - a) << 3) | s); + l3 = basisu::min(l3, (basisu::iabs(v3 - a) << 3) | s); } } else if (mul_or == 1) @@ -15872,10 +15872,10 @@ namespace basist const int v2 = g_eac_modifier_table[T2][s] + a2; const int v3 = g_eac_modifier_table[T3][s] + a3; - l0 = std::min(l0, (basisu::iabs(v0) << 3) | s); - l1 = std::min(l1, (basisu::iabs(v1) << 3) | s); - l2 = std::min(l2, (basisu::iabs(v2) << 3) | s); - l3 = std::min(l3, (basisu::iabs(v3) << 3) | s); + l0 = basisu::min(l0, (basisu::iabs(v0) << 3) | s); + l1 = basisu::min(l1, (basisu::iabs(v1) << 3) | s); + l2 = basisu::min(l2, (basisu::iabs(v2) << 3) | s); + l3 = basisu::min(l3, (basisu::iabs(v3) << 3) | s); } } else @@ -15889,10 +15889,10 @@ namespace basist const int v2 = mul[2] * g_eac_modifier_table[T2][s] + a2; const int v3 = mul[3] * g_eac_modifier_table[T3][s] + a3; - l0 = std::min(l0, (basisu::iabs(v0) << 3) | s); - l1 = std::min(l1, (basisu::iabs(v1) << 3) | s); - l2 = std::min(l2, (basisu::iabs(v2) << 3) | s); - l3 = std::min(l3, (basisu::iabs(v3) << 3) | s); + l0 = basisu::min(l0, (basisu::iabs(v0) << 3) | s); + l1 = basisu::min(l1, (basisu::iabs(v1) << 3) | s); + l2 = basisu::min(l2, (basisu::iabs(v2) << 3) | s); + l3 = basisu::min(l3, (basisu::iabs(v3) << 3) | s); } } @@ -16011,13 +16011,13 @@ namespace basist else { uint32_t l = basisu::iabs(clamp255(m * pTable[0] + b) - a) << 3; - l = std::min(l, (basisu::iabs(clamp255(m * pTable[1] + b) - a) << 3) | 1); - l = std::min(l, (basisu::iabs(clamp255(m * pTable[2] + b) - a) << 3) | 2); - l = std::min(l, (basisu::iabs(clamp255(m * pTable[3] + b) - a) << 3) | 3); - l = std::min(l, (basisu::iabs(clamp255(m * pTable[4] + b) - a) << 3) | 4); - l = std::min(l, (basisu::iabs(clamp255(m * pTable[5] + b) - a) << 3) | 5); - l = std::min(l, (basisu::iabs(clamp255(m * pTable[6] + b) - a) << 3) | 6); - l = std::min(l, (basisu::iabs(clamp255(m * pTable[7] + b) - a) << 3) | 7); + l = basisu::min(l, (basisu::iabs(clamp255(m * pTable[1] + b) - a) << 3) | 1); + l = basisu::min(l, (basisu::iabs(clamp255(m * pTable[2] + b) - a) << 3) | 2); + l = basisu::min(l, (basisu::iabs(clamp255(m * pTable[3] + b) - a) << 3) | 3); + l = basisu::min(l, (basisu::iabs(clamp255(m * pTable[4] + b) - a) << 3) | 4); + l = basisu::min(l, (basisu::iabs(clamp255(m * pTable[5] + b) - a) << 3) | 5); + l = basisu::min(l, (basisu::iabs(clamp255(m * pTable[6] + b) - a) << 3) | 6); + l = basisu::min(l, (basisu::iabs(clamp255(m * pTable[7] + b) - a) << 3) | 7); sels[table][i] = l & 7; total_err[table] += basisu::square(l >> 3); @@ -16464,8 +16464,8 @@ namespace basist uint32_t low_a = 255, high_a = 0; for (uint32_t i = 0; i < 16; i++) { - low_a = std::min(low_a, block_pixels[i].a); - high_a = std::max(high_a, block_pixels[i].a); + low_a = basisu::min(low_a, block_pixels[i].a); + high_a = basisu::max(high_a, block_pixels[i].a); } low_color.set(low_a, low_a, low_a, 255); high_color.set(high_a, high_a, high_a, 255); diff --git a/transcoder/basisu_transcoder_internal.h b/transcoder/basisu_transcoder_internal.h index 9fdcbc3..672e678 100644 --- a/transcoder/basisu_transcoder_internal.h +++ b/transcoder/basisu_transcoder_internal.h @@ -686,8 +686,8 @@ namespace basist bool operator== (const color32&rhs) const { return m == rhs.m; } - static color32 comp_min(const color32& a, const color32& b) { return color32(cNoClamp, std::min(a[0], b[0]), std::min(a[1], b[1]), std::min(a[2], b[2]), std::min(a[3], b[3])); } - static color32 comp_max(const color32& a, const color32& b) { return color32(cNoClamp, std::max(a[0], b[0]), std::max(a[1], b[1]), std::max(a[2], b[2]), std::max(a[3], b[3])); } + static color32 comp_min(const color32& a, const color32& b) { return color32(cNoClamp, basisu::min(a[0], b[0]), basisu::min(a[1], b[1]), basisu::min(a[2], b[2]), basisu::min(a[3], b[3])); } + static color32 comp_max(const color32& a, const color32& b) { return color32(cNoClamp, basisu::max(a[0], b[0]), basisu::max(a[1], b[1]), basisu::max(a[2], b[2]), basisu::max(a[3], b[3])); } }; struct endpoint From 2c0c038ffe78a1a1cada551fd955446272178206 Mon Sep 17 00:00:00 2001 From: JCash Date: Tue, 30 Mar 2021 19:17:50 +0200 Subject: [PATCH 2/2] Renamed to minimum/maximum --- basisu_tool.cpp | 106 ++++++++++---------- encoder/basisu_astc_decomp.cpp | 2 +- encoder/basisu_comp.cpp | 6 +- encoder/basisu_enc.cpp | 8 +- encoder/basisu_enc.h | 8 +- encoder/basisu_etc.cpp | 14 +-- encoder/basisu_gpu_texture.cpp | 2 +- encoder/basisu_pvrtc1_4.cpp | 2 +- encoder/basisu_uastc_enc.cpp | 32 +++--- transcoder/basisu.h | 4 +- transcoder/basisu_transcoder.cpp | 128 ++++++++++++------------ transcoder/basisu_transcoder_internal.h | 4 +- 12 files changed, 157 insertions(+), 159 deletions(-) diff --git a/basisu_tool.cpp b/basisu_tool.cpp index c233746..2623a5d 100644 --- a/basisu_tool.cpp +++ b/basisu_tool.cpp @@ -258,7 +258,7 @@ public: m_compare_ssim(false), m_bench(false) { - m_comp_params.m_compression_level = basisu::max(0, BASISU_DEFAULT_COMPRESSION_LEVEL - 1); + m_comp_params.m_compression_level = basisu::maximum(0, BASISU_DEFAULT_COMPRESSION_LEVEL - 1); } bool parse(int arg_c, const char **arg_v) @@ -961,13 +961,13 @@ static bool compress_mode(command_line_params &opts) for (size_t slice_index = 0; slice_index < c.get_stats().size(); slice_index++) { - rgb_avg_psnr_min = basisu::min(rgb_avg_psnr_min, c.get_stats()[slice_index].m_basis_rgb_avg_psnr); + rgb_avg_psnr_min = basisu::minimum(rgb_avg_psnr_min, c.get_stats()[slice_index].m_basis_rgb_avg_psnr); rgb_avg_psnr_avg += c.get_stats()[slice_index].m_basis_rgb_avg_psnr; - a_avg_psnr_min = basisu::min(a_avg_psnr_min, c.get_stats()[slice_index].m_basis_a_avg_psnr); + a_avg_psnr_min = basisu::minimum(a_avg_psnr_min, c.get_stats()[slice_index].m_basis_a_avg_psnr); a_avg_psnr_avg += c.get_stats()[slice_index].m_basis_a_avg_psnr; - luma_709_psnr_min = basisu::min(luma_709_psnr_min, c.get_stats()[slice_index].m_basis_luma_709_psnr); + luma_709_psnr_min = basisu::minimum(luma_709_psnr_min, c.get_stats()[slice_index].m_basis_luma_709_psnr); luma_709_psnr_avg += c.get_stats()[slice_index].m_basis_luma_709_psnr; } @@ -1582,7 +1582,7 @@ static bool unpack_and_validate_mode(command_line_params &opts) { for (uint32_t level_index = 0; level_index < fileinfo.m_image_mipmap_levels[image_index]; level_index++) { - max_mipmap_levels = basisu::max(max_mipmap_levels, fileinfo.m_image_mipmap_levels[image_index]); + max_mipmap_levels = basisu::maximum(max_mipmap_levels, fileinfo.m_image_mipmap_levels[image_index]); const basist::transcoder_texture_format transcoder_tex_fmt = basist::transcoder_texture_format::cTFRGBA4444; @@ -2015,7 +2015,7 @@ static bool bench_mode(command_line_params& opts) for (uint32_t bx = 0; bx < num_blocks_x; bx += N) { - const uint32_t num_blocks_to_process = basisu::min(num_blocks_x - bx, N); + const uint32_t num_blocks_to_process = basisu::minimum(num_blocks_x - bx, N); color_rgba pixels[16 * N]; @@ -2636,186 +2636,186 @@ static bool bench_mode(command_line_params& opts) // UASTC em.calc(img, uastc_img, 0, 3); em.print("UASTC RGB "); - total_uastc_psnr += basisu::min(99.0f, em.m_psnr); + total_uastc_psnr += basisu::minimum(99.0f, em.m_psnr); em.calc(img, uastc_img, 3, 1); em.print("UASTC A "); if (img_has_alpha) - total_uastc_a_psnr += basisu::min(99.0f, em.m_psnr); + total_uastc_a_psnr += basisu::minimum(99.0f, em.m_psnr); em.calc(img, uastc_img, 0, 4); em.print("UASTC RGBA "); - total_uastc_rgba_psnr += basisu::min(99.0f, em.m_psnr); + total_uastc_rgba_psnr += basisu::minimum(99.0f, em.m_psnr); // RDO UASTC em.calc(img, rdo_uastc_img, 0, 3); em.print("RDOUASTC RGB "); - total_rdo_uastc_psnr += basisu::min(99.0f, em.m_psnr); + total_rdo_uastc_psnr += basisu::minimum(99.0f, em.m_psnr); em.calc(img, rdo_uastc_img, 3, 1); em.print("RDOUASTC A "); if (img_has_alpha) - total_rdo_uastc_a_psnr += basisu::min(99.0f, em.m_psnr); + total_rdo_uastc_a_psnr += basisu::minimum(99.0f, em.m_psnr); em.calc(img, rdo_uastc_img, 0, 4); em.print("RDOUASTC RGBA "); - total_rdo_uastc_rgba_psnr += basisu::min(99.0f, em.m_psnr); + total_rdo_uastc_rgba_psnr += basisu::minimum(99.0f, em.m_psnr); // UASTC2 em.calc(img, uastc2_img, 0, 3); em.print("UASTC2 RGB "); - total_uastc2_psnr += basisu::min(99.0f, em.m_psnr); + total_uastc2_psnr += basisu::minimum(99.0f, em.m_psnr); em.calc(img, uastc2_img, 3, 1); em.print("UASTC2 A "); if (img_has_alpha) - total_uastc2_a_psnr += basisu::min(99.0f, em.m_psnr); + total_uastc2_a_psnr += basisu::minimum(99.0f, em.m_psnr); em.calc(img, uastc2_img, 0, 4); em.print("UASTC2 RGBA "); - total_uastc2_rgba_psnr += basisu::min(99.0f, em.m_psnr); + total_uastc2_rgba_psnr += basisu::minimum(99.0f, em.m_psnr); // BC7 em.calc(img, bc7_img, 0, 3); em.print("BC7 RGB "); - total_bc7_psnr += basisu::min(99.0f, em.m_psnr); + total_bc7_psnr += basisu::minimum(99.0f, em.m_psnr); em.calc(img, bc7_img, 3, 1); em.print("BC7 A "); if (img_has_alpha) - total_bc7_a_psnr += basisu::min(99.0f, em.m_psnr); + total_bc7_a_psnr += basisu::minimum(99.0f, em.m_psnr); em.calc(img, bc7_img, 0, 4); em.print("BC7 RGBA "); - total_bc7_rgba_psnr += basisu::min(99.0f, em.m_psnr); + total_bc7_rgba_psnr += basisu::minimum(99.0f, em.m_psnr); // RDO BC7 em.calc(img, rdo_bc7_img, 0, 3); em.print("RDOBC7 RGB "); - total_rdo_bc7_psnr += basisu::min(99.0f, em.m_psnr); + total_rdo_bc7_psnr += basisu::minimum(99.0f, em.m_psnr); em.calc(img, rdo_bc7_img, 3, 1); em.print("RDOBC7 A "); if (img_has_alpha) - total_rdo_bc7_a_psnr += basisu::min(99.0f, em.m_psnr); + total_rdo_bc7_a_psnr += basisu::minimum(99.0f, em.m_psnr); em.calc(img, rdo_bc7_img, 0, 4); em.print("RDOBC7 RGBA "); - total_rdo_bc7_rgba_psnr += basisu::min(99.0f, em.m_psnr); + total_rdo_bc7_rgba_psnr += basisu::minimum(99.0f, em.m_psnr); #if 0 // OBC7 em.calc(img, opt_bc7_img, 0, 3); em.print("OBC7 RGB "); - total_obc7_psnr += basisu::min(99.0f, em.m_psnr); + total_obc7_psnr += basisu::minimum(99.0f, em.m_psnr); em.calc(img, opt_bc7_img, 3, 1); em.print("OBC7 A "); if (img_has_alpha) - total_obc7_a_psnr += basisu::min(99.0f, em.m_psnr); + total_obc7_a_psnr += basisu::minimum(99.0f, em.m_psnr); em.calc(img, opt_bc7_img, 0, 4); em.print("OBC7 RGBA "); - total_obc7_rgba_psnr += basisu::min(99.0f, em.m_psnr); + total_obc7_rgba_psnr += basisu::minimum(99.0f, em.m_psnr); // OASTC em.calc(img, opt_astc_img, 0, 3); em.print("OASTC RGB "); - total_oastc_psnr += basisu::min(99.0f, em.m_psnr); + total_oastc_psnr += basisu::minimum(99.0f, em.m_psnr); em.calc(img, opt_astc_img, 3, 1); em.print("OASTC A "); if (img_has_alpha) - total_oastc_a_psnr += basisu::min(99.0f, em.m_psnr); + total_oastc_a_psnr += basisu::minimum(99.0f, em.m_psnr); em.calc(img, opt_astc_img, 0, 4); em.print("OASTC RGBA "); - total_oastc_rgba_psnr += basisu::min(99.0f, em.m_psnr); + total_oastc_rgba_psnr += basisu::minimum(99.0f, em.m_psnr); #endif // bc7enc em.calc(img, bc7enc_img, 0, 3); em.print("BC7ENC RGB "); - total_bc7enc_psnr += basisu::min(99.0f, em.m_psnr); + total_bc7enc_psnr += basisu::minimum(99.0f, em.m_psnr); em.calc(img, bc7enc_img, 3, 1); em.print("BC7ENC A "); if (img_has_alpha) - total_bc7enc_a_psnr += basisu::min(99.0f, em.m_psnr); + total_bc7enc_a_psnr += basisu::minimum(99.0f, em.m_psnr); em.calc(img, bc7enc_img, 0, 4); em.print("BC7ENC RGBA "); - total_bc7enc_rgba_psnr += basisu::min(99.0f, em.m_psnr); + total_bc7enc_rgba_psnr += basisu::minimum(99.0f, em.m_psnr); #if 1 // OBC1 em.calc(img, opt_bc1_img, 0, 3); em.print("OBC1 RGB "); - total_obc1_psnr += basisu::min(99.0f, em.m_psnr); - total_obc1_psnr_sq += basisu::min(99.0f, em.m_psnr) * basisu::min(99.0f, em.m_psnr); + total_obc1_psnr += basisu::minimum(99.0f, em.m_psnr); + total_obc1_psnr_sq += basisu::minimum(99.0f, em.m_psnr) * basisu::minimum(99.0f, em.m_psnr); #endif em.calc(img, opt_bc1_2_img, 0, 3); em.print("OBC1 2 RGB "); - total_obc1_2_psnr += basisu::min(99.0f, em.m_psnr); - total_obc1_2_psnr_sq += basisu::min(99.0f, em.m_psnr) * basisu::min(99.0f, em.m_psnr); + total_obc1_2_psnr += basisu::minimum(99.0f, em.m_psnr); + total_obc1_2_psnr_sq += basisu::minimum(99.0f, em.m_psnr) * basisu::minimum(99.0f, em.m_psnr); em.calc(img, bc1_img, 0, 3); em.print("BC1 RGB "); - total_bc1_psnr += basisu::min(99.0f, em.m_psnr); - total_bc1_psnr_sq += basisu::min(99.0f, em.m_psnr) * basisu::min(99.0f, em.m_psnr); + total_bc1_psnr += basisu::minimum(99.0f, em.m_psnr); + total_bc1_psnr_sq += basisu::minimum(99.0f, em.m_psnr) * basisu::minimum(99.0f, em.m_psnr); // ETC1 em.calc(img, etc1_img, 0, 3); em.print("ETC1 RGB "); - total_etc1_psnr += basisu::min(99.0f, em.m_psnr); + total_etc1_psnr += basisu::minimum(99.0f, em.m_psnr); em.calc(img, etc1_img, 0, 0); em.print("ETC1 Y "); - total_etc1_y_psnr += basisu::min(99.0f, em.m_psnr); + total_etc1_y_psnr += basisu::minimum(99.0f, em.m_psnr); // ETC1 em.calc(img, etc1_g_img, 1, 1); em.print("ETC1 G "); - total_etc1_g_psnr += basisu::min(99.0f, em.m_psnr); + total_etc1_g_psnr += basisu::minimum(99.0f, em.m_psnr); // ETC2 em.calc(img, etc2_img, 0, 3); em.print("ETC2 RGB "); - total_etc2_psnr += basisu::min(99.0f, em.m_psnr); + total_etc2_psnr += basisu::minimum(99.0f, em.m_psnr); em.calc(img, etc2_img, 3, 1); em.print("ETC2 A "); if (img_has_alpha) - total_etc2_a_psnr += basisu::min(99.0f, em.m_psnr); + total_etc2_a_psnr += basisu::minimum(99.0f, em.m_psnr); em.calc(img, etc2_img, 0, 4); em.print("ETC2 RGBA "); - total_etc2_rgba_psnr += basisu::min(99.0f, em.m_psnr); + total_etc2_rgba_psnr += basisu::minimum(99.0f, em.m_psnr); // BC3 em.calc(img, bc3_img, 0, 3); em.print("BC3 RGB "); - total_bc3_psnr += basisu::min(99.0f, em.m_psnr); + total_bc3_psnr += basisu::minimum(99.0f, em.m_psnr); em.calc(img, bc3_img, 3, 1); em.print("BC3 A "); if (img_has_alpha) - total_bc3_a_psnr += basisu::min(99.0f, em.m_psnr); + total_bc3_a_psnr += basisu::minimum(99.0f, em.m_psnr); em.calc(img, bc3_img, 0, 4); em.print("BC3 RGBA "); - total_bc3_rgba_psnr += basisu::min(99.0f, em.m_psnr); + total_bc3_rgba_psnr += basisu::minimum(99.0f, em.m_psnr); // EAC R11 em.calc(img, eac_r11_img, 0, 1); em.print("EAC R11 "); - total_eac_r11_psnr += basisu::min(99.0f, em.m_psnr); + total_eac_r11_psnr += basisu::minimum(99.0f, em.m_psnr); // EAC RG11 em.calc(img, eac_rg11_img, 0, 2); em.print("EAC RG11 "); - total_eac_rg11_psnr += basisu::min(99.0f, em.m_psnr); + total_eac_rg11_psnr += basisu::minimum(99.0f, em.m_psnr); const uint32_t width = num_blocks_x * 4; const uint32_t height = num_blocks_y * 4; @@ -2863,15 +2863,15 @@ static bool bench_mode(command_line_params& opts) em.calc(img, pi_unpacked, 0, 3); em.print("PVRTC1 After RGB "); - total_pvrtc1_rgb_psnr += basisu::min(99.0f, em.m_psnr); + total_pvrtc1_rgb_psnr += basisu::minimum(99.0f, em.m_psnr); em.calc(img, pi_unpacked, 3, 1); em.print("PVRTC1 After A "); - total_pvrtc1_a_psnr += basisu::min(99.0f, em.m_psnr); + total_pvrtc1_a_psnr += basisu::minimum(99.0f, em.m_psnr); em.calc(img, pi_unpacked, 0, 4); em.print("PVRTC1 After RGBA "); - total_pvrtc1_rgba_psnr += basisu::min(99.0f, em.m_psnr); + total_pvrtc1_rgba_psnr += basisu::minimum(99.0f, em.m_psnr); total_pvrtc1_images++; } @@ -2925,11 +2925,11 @@ static bool bench_mode(command_line_params& opts) //printf("Avg Opt ASTC RGB PSNR: %f, A PSNR: %f, RGBA PSNR: %f\n", total_oastc_psnr / total_images, total_oastc_a_psnr / total_a_images, total_oastc_rgba_psnr / total_images); printf("Avg BC7ENC RGB PSNR: %f, A PSNR: %f, RGBA PSNR: %f\n", total_bc7enc_psnr / total_images, total_bc7enc_a_psnr / total_a_images, total_bc7enc_rgba_psnr / total_images); - printf("Avg Opt BC1 PSNR: %f, std dev: %f\n", total_obc1_psnr / total_images, sqrtf(basisu::max(0.0f, (total_obc1_psnr_sq / total_images) - (total_obc1_psnr / total_images) * (total_obc1_psnr / total_images)))); + printf("Avg Opt BC1 PSNR: %f, std dev: %f\n", total_obc1_psnr / total_images, sqrtf(basisu::maximum(0.0f, (total_obc1_psnr_sq / total_images) - (total_obc1_psnr / total_images) * (total_obc1_psnr / total_images)))); - printf("Avg Opt BC1 2 PSNR: %f, std dev: %f\n", total_obc1_2_psnr / total_images, sqrtf(basisu::max(0.0f, (total_obc1_2_psnr_sq / total_images) - (total_obc1_2_psnr / total_images) * (total_obc1_2_psnr / total_images)))); + printf("Avg Opt BC1 2 PSNR: %f, std dev: %f\n", total_obc1_2_psnr / total_images, sqrtf(basisu::maximum(0.0f, (total_obc1_2_psnr_sq / total_images) - (total_obc1_2_psnr / total_images) * (total_obc1_2_psnr / total_images)))); - printf("Avg BC1 PSNR: %f, std dev: %f\n", total_bc1_psnr / total_images, sqrtf(basisu::max(0.0f, (total_bc1_psnr_sq / total_images) - (total_bc1_psnr / total_images) * (total_bc1_psnr / total_images)))); + printf("Avg BC1 PSNR: %f, std dev: %f\n", total_bc1_psnr / total_images, sqrtf(basisu::maximum(0.0f, (total_bc1_psnr_sq / total_images) - (total_bc1_psnr / total_images) * (total_bc1_psnr / total_images)))); printf("Avg ETC1 RGB PSNR: %f\n", total_etc1_psnr / total_images); printf("Avg ETC1 Y PSNR: %f\n", total_etc1_y_psnr / total_images); diff --git a/encoder/basisu_astc_decomp.cpp b/encoder/basisu_astc_decomp.cpp index aa941b9..53bccfc 100644 --- a/encoder/basisu_astc_decomp.cpp +++ b/encoder/basisu_astc_decomp.cpp @@ -157,7 +157,7 @@ namespace basisu_astc UVec4 asUint() const { - return UVec4(basisu::max(0, m_c[0]), basisu::max(0, m_c[1]), basisu::max(0, m_c[2]), basisu::max(0, m_c[3])); + return UVec4(basisu::maximum(0, m_c[0]), basisu::maximum(0, m_c[1]), basisu::maximum(0, m_c[2]), basisu::maximum(0, m_c[3])); } int32_t operator[] (uint32_t idx) const { assert(idx < 4); return m_c[idx]; } diff --git a/encoder/basisu_comp.cpp b/encoder/basisu_comp.cpp index 0df4521..9ca1ef5 100644 --- a/encoder/basisu_comp.cpp +++ b/encoder/basisu_comp.cpp @@ -267,7 +267,7 @@ namespace basisu bool status = uastc_rdo(tex.get_total_blocks(), (basist::uastc_block*)tex.get_ptr(), (const color_rgba *)m_source_blocks[slice_desc.m_first_block_index].m_pixels, rdo_params, m_params.m_pack_uastc_flags, m_params.m_rdo_uastc_multithreading ? m_params.m_pJob_pool : nullptr, - (m_params.m_rdo_uastc_multithreading && m_params.m_pJob_pool) ? basisu::min(4, (uint32_t)m_params.m_pJob_pool->get_total_threads()) : 0); + (m_params.m_rdo_uastc_multithreading && m_params.m_pJob_pool) ? basisu::minimum(4, (uint32_t)m_params.m_pJob_pool->get_total_threads()) : 0); if (!status) { return cECFailedUASTCRDOPostProcess; @@ -489,8 +489,8 @@ namespace basisu if (m_params.m_resample_factor > 0.0f) { - int new_width = basisu::min(basisu::max(1, (int)ceilf(file_image.get_width() * m_params.m_resample_factor)), BASISU_MAX_SUPPORTED_TEXTURE_DIMENSION); - int new_height = basisu::min(basisu::max(1, (int)ceilf(file_image.get_height() * m_params.m_resample_factor)), BASISU_MAX_SUPPORTED_TEXTURE_DIMENSION); + int new_width = basisu::minimum(basisu::maximum(1, (int)ceilf(file_image.get_width() * m_params.m_resample_factor)), BASISU_MAX_SUPPORTED_TEXTURE_DIMENSION); + int new_height = basisu::minimum(basisu::maximum(1, (int)ceilf(file_image.get_height() * m_params.m_resample_factor)), BASISU_MAX_SUPPORTED_TEXTURE_DIMENSION); debug_printf("Resampling to %ix%i\n", new_width, new_height); diff --git a/encoder/basisu_enc.cpp b/encoder/basisu_enc.cpp index e795653..491a13a 100644 --- a/encoder/basisu_enc.cpp +++ b/encoder/basisu_enc.cpp @@ -1308,8 +1308,8 @@ namespace basisu { assert((first_chan < 4U) && (first_chan + total_chans <= 4U)); - const uint32_t width = basisu::min(a.get_width(), b.get_width()); - const uint32_t height = basisu::min(a.get_height(), b.get_height()); + const uint32_t width = basisu::minimum(a.get_width(), b.get_width()); + const uint32_t height = basisu::minimum(a.get_height(), b.get_height()); double hist[256]; clear_obj(hist); @@ -1341,7 +1341,7 @@ namespace basisu { if (hist[i]) { - m_max = basisu::max(m_max, (float)i); + m_max = basisu::maximum(m_max, (float)i); double v = i * hist[i]; sum += v; sum2 += i * v; @@ -1823,7 +1823,7 @@ namespace basisu } } - const uint32_t n = basisu::min(pixels_remaining, run_remaining); + const uint32_t n = basisu::minimum(pixels_remaining, run_remaining); pixels_remaining -= n; run_remaining -= n; diff --git a/encoder/basisu_enc.h b/encoder/basisu_enc.h index 142425b..09f84b6 100644 --- a/encoder/basisu_enc.h +++ b/encoder/basisu_enc.h @@ -194,8 +194,8 @@ namespace basisu m_new_s = m_old_s + (x - m_old_m) * (x - m_new_m); m_old_m = m_new_m; m_old_s = m_new_s; - m_min = basisu::min(x, m_min); - m_max = basisu::max(x, m_max); + m_min = basisu::minimum(x, m_min); + m_max = basisu::maximum(x, m_max); } } uint32_t get_num() const @@ -741,8 +741,8 @@ namespace basisu return basist::color32(r, g, b, a); } - static color_rgba comp_min(const color_rgba& a, const color_rgba& b) { return color_rgba(basisu::min(a[0], b[0]), basisu::min(a[1], b[1]), basisu::min(a[2], b[2]), basisu::min(a[3], b[3])); } - static color_rgba comp_max(const color_rgba& a, const color_rgba& b) { return color_rgba(basisu::max(a[0], b[0]), basisu::max(a[1], b[1]), basisu::max(a[2], b[2]), basisu::max(a[3], b[3])); } + static color_rgba comp_min(const color_rgba& a, const color_rgba& b) { return color_rgba(basisu::minimum(a[0], b[0]), basisu::minimum(a[1], b[1]), basisu::minimum(a[2], b[2]), basisu::minimum(a[3], b[3])); } + static color_rgba comp_max(const color_rgba& a, const color_rgba& b) { return color_rgba(basisu::maximum(a[0], b[0]), basisu::maximum(a[1], b[1]), basisu::maximum(a[2], b[2]), basisu::maximum(a[3], b[3])); } }; typedef basisu::vector color_rgba_vec; diff --git a/encoder/basisu_etc.cpp b/encoder/basisu_etc.cpp index b488731..232e896 100644 --- a/encoder/basisu_etc.cpp +++ b/encoder/basisu_etc.cpp @@ -1006,13 +1006,13 @@ namespace basisu { const color_rgba& c = m_pParams->m_pSrc_pixels[i]; - min_r = basisu::min(min_r, c.r); - min_g = basisu::min(min_g, c.g); - min_b = basisu::min(min_b, c.b); + min_r = basisu::minimum(min_r, c.r); + min_g = basisu::minimum(min_g, c.g); + min_b = basisu::minimum(min_b, c.b); - max_r = basisu::max(max_r, c.r); - max_g = basisu::max(max_g, c.g); - max_b = basisu::max(max_b, c.b); + max_r = basisu::maximum(max_r, c.r); + max_g = basisu::maximum(max_g, c.g); + max_b = basisu::maximum(max_b, c.b); const vec3F fc(c.r, c.g, c.b); @@ -1023,7 +1023,7 @@ namespace basisu } avg_color /= static_cast(n); m_avg_color = avg_color; - m_max_comp_spread = basisu::max(basisu::max(max_r - min_r, max_g - min_g), max_b - min_b); + m_max_comp_spread = basisu::maximum(basisu::maximum(max_r - min_r, max_g - min_g), max_b - min_b); m_br = clamp(static_cast(m_avg_color[0] * m_limit / 255.0f + .5f), 0, m_limit); m_bg = clamp(static_cast(m_avg_color[1] * m_limit / 255.0f + .5f), 0, m_limit); diff --git a/encoder/basisu_gpu_texture.cpp b/encoder/basisu_gpu_texture.cpp index 83c444b..3f9fb67 100644 --- a/encoder/basisu_gpu_texture.cpp +++ b/encoder/basisu_gpu_texture.cpp @@ -399,7 +399,7 @@ namespace basisu if (mode) { - c[1].set(basisu::max(0, c[0].r - (c[3].r >> 2)), basisu::max(0, c[0].g - (c[3].g >> 2)), basisu::max(0, c[0].b - (c[3].b >> 2)), 255); + c[1].set(basisu::maximum(0, c[0].r - (c[3].r >> 2)), basisu::maximum(0, c[0].g - (c[3].g >> 2)), basisu::maximum(0, c[0].b - (c[3].b >> 2)), 255); c[2] = c[0]; c[0].set(0, 0, 0, 255); } diff --git a/encoder/basisu_pvrtc1_4.cpp b/encoder/basisu_pvrtc1_4.cpp index f3e4ce4..596fc19 100644 --- a/encoder/basisu_pvrtc1_4.cpp +++ b/encoder/basisu_pvrtc1_4.cpp @@ -529,7 +529,7 @@ namespace basisu uint64_t e03_err_1 = remap_pixels_influenced_by_endpoint(bx, by, orig_img, perceptual, false); - if (initial_error < basisu::min(e03_err_0, e03_err_1)) + if (initial_error < basisu::minimum(e03_err_0, e03_err_1)) { for (int y = -1; y <= 1; y++) { diff --git a/encoder/basisu_uastc_enc.cpp b/encoder/basisu_uastc_enc.cpp index a412cf5..ca2b325 100644 --- a/encoder/basisu_uastc_enc.cpp +++ b/encoder/basisu_uastc_enc.cpp @@ -1630,7 +1630,7 @@ namespace basisu else if (estimate_partition_list_size > 0) { assert(estimate_partition_list_size <= MAX_PARTS); - estimate_partition_list_size = basisu::min(estimate_partition_list_size, MAX_PARTS); + estimate_partition_list_size = basisu::minimum(estimate_partition_list_size, MAX_PARTS); estimate_partition2_list(4, 4, g_bc7_weights2, (const color_rgba(*)[4])pBlock, parts, estimate_partition_list_size, weights); @@ -2817,13 +2817,13 @@ namespace basisu avg_color[1] += p.g; avg_color[2] += p.b; - min_r[subset] = basisu::min(min_r[subset], p.r); - min_g[subset] = basisu::min(min_g[subset], p.g); - min_b[subset] = basisu::min(min_b[subset], p.b); + min_r[subset] = basisu::minimum(min_r[subset], p.r); + min_g[subset] = basisu::minimum(min_g[subset], p.g); + min_b[subset] = basisu::minimum(min_b[subset], p.b); - max_r[subset] = basisu::max(max_r[subset], p.r); - max_g[subset] = basisu::max(max_g[subset], p.g); - max_b[subset] = basisu::max(max_b[subset], p.b); + max_r[subset] = basisu::maximum(max_r[subset], p.r); + max_g[subset] = basisu::maximum(max_g[subset], p.g); + max_b[subset] = basisu::maximum(max_b[subset], p.b); } // j unbiased_block_colors[subset][0] = (uint8_t)((avg_color[0] * mul + 1020) / (8 * 255)); @@ -3769,7 +3769,7 @@ namespace basisu dist_cost += g_tdefl_small_dist_extra[dist & 511]; else { - dist_cost += g_tdefl_large_dist_extra[basisu::min(dist, 32767) >> 8]; + dist_cost += g_tdefl_large_dist_extra[basisu::minimum(dist, 32767) >> 8]; while (dist >= 32768) { dist_cost++; @@ -3839,7 +3839,7 @@ namespace basisu { debug_printf("uastc_rdo_blocks: Processing blocks %u to %u\n", first_index, last_index); - const int total_blocks_to_check = basisu::max(1U, params.m_lz_dict_size / sizeof(basist::uastc_block)); + const int total_blocks_to_check = basisu::maximum(1U, params.m_lz_dict_size / sizeof(basist::uastc_block)); const bool perceptual = false; std::unordered_map selector_history; @@ -3867,7 +3867,7 @@ namespace basisu a_stats.update(pPixels[i].a); } - const float max_std_dev = basisu::max(basisu::max(basisu::max(r_stats.get_std_dev(), g_stats.get_std_dev()), b_stats.get_std_dev()), a_stats.get_std_dev()); + const float max_std_dev = basisu::maximum(basisu::maximum(basisu::maximum(r_stats.get_std_dev(), g_stats.get_std_dev()), b_stats.get_std_dev()), a_stats.get_std_dev()); float yl = clamp(max_std_dev / params.m_max_smooth_block_std_dev, 0.0f, 1.0f); yl = yl * yl; @@ -3910,7 +3910,7 @@ namespace basisu assert(total_sel_bits > 0); uint32_t cur_bit_offset = first_sel_bit; - uint64_t cur_sel_bits = read_bits((const uint8_t*)&blk, cur_bit_offset, basisu::min(64U, total_sel_bits)); + uint64_t cur_sel_bits = read_bits((const uint8_t*)&blk, cur_bit_offset, basisu::minimum(64U, total_sel_bits)); if (cur_rms_err >= params.m_skip_block_rms_thresh) { @@ -3940,7 +3940,7 @@ namespace basisu cur_bits = compute_match_cost_estimate(block_dist_in_bytes); } - int first_block_to_check = basisu::max(first_index, block_index - total_blocks_to_check); + int first_block_to_check = basisu::maximum(first_index, block_index - total_blocks_to_check); int last_block_to_check = block_index - 1; basist::uastc_block best_block(blk); @@ -3955,7 +3955,7 @@ namespace basisu const basist::uastc_block& prev_blk = pBlocks[prev_block_index]; uint32_t bit_offset = first_sel_bit; - uint64_t sel_bits = read_bits((const uint8_t*)&prev_blk, bit_offset, basisu::min(64U, total_sel_bits)); + uint64_t sel_bits = read_bits((const uint8_t*)&prev_blk, bit_offset, basisu::minimum(64U, total_sel_bits)); int match_block_index = prev_block_index; auto res = selector_history.find(selector_bitsequence(first_sel_bit, sel_bits)); @@ -3971,13 +3971,13 @@ namespace basisu basist::uastc_block trial_blk(blk); - set_block_bits((uint8_t*)&trial_blk, sel_bits, basisu::min(64U, total_sel_bits), first_sel_bit); + set_block_bits((uint8_t*)&trial_blk, sel_bits, basisu::minimum(64U, total_sel_bits), first_sel_bit); if (total_sel_bits > 64) { sel_bits = read_bits((const uint8_t*)&prev_blk, bit_offset, total_sel_bits - 64U); - set_block_bits((uint8_t*)&trial_blk, sel_bits, total_sel_bits - 64U, first_sel_bit + basisu::min(64U, total_sel_bits)); + set_block_bits((uint8_t*)&trial_blk, sel_bits, total_sel_bits - 64U, first_sel_bit + basisu::minimum(64U, total_sel_bits)); } unpacked_uastc_block unpacked_trial_blk; @@ -4102,7 +4102,7 @@ namespace basisu { uint32_t bit_offset = first_sel_bit; - uint64_t sel_bits = read_bits((const uint8_t*)&best_block, bit_offset, basisu::min(64U, total_sel_bits)); + uint64_t sel_bits = read_bits((const uint8_t*)&best_block, bit_offset, basisu::minimum(64U, total_sel_bits)); auto res = selector_history.insert(std::make_pair(selector_bitsequence(first_sel_bit, sel_bits), block_index)); if (!res.second) diff --git a/transcoder/basisu.h b/transcoder/basisu.h index 5e82e4c..b7423cf 100644 --- a/transcoder/basisu.h +++ b/transcoder/basisu.h @@ -116,10 +116,8 @@ namespace basisu void enable_debug_printf(bool enabled); void debug_printf(const char *pFmt, ...); - template inline void clear_obj(T& obj) { memset(&obj, 0, sizeof(obj)); } - template const T& min(const T& a, const T& b) { return (b < a) ? b : a; } - template const T& max(const T& a, const T& b) { return (a < b) ? b : a; } + template inline void clear_obj(T& obj) { memset(&obj, 0, sizeof(obj)); } template inline T0 lerp(T0 a, T0 b, T1 c) { return a + (b - a) * c; } diff --git a/transcoder/basisu_transcoder.cpp b/transcoder/basisu_transcoder.cpp index a7d3e76..c99dda4 100644 --- a/transcoder/basisu_transcoder.cpp +++ b/transcoder/basisu_transcoder.cpp @@ -5082,7 +5082,7 @@ namespace basist while (total_bits) { - const uint32_t bits_to_write = basisu::min(total_bits, 8 - (bit_pos & 7)); + const uint32_t bits_to_write = basisu::minimum(total_bits, 8 - (bit_pos & 7)); pBytes[bit_pos >> 3] |= static_cast(value << (bit_pos & 7)); @@ -11893,7 +11893,7 @@ namespace basist { uint8_t vals[5] = { 0, 0, 0, 0, 0 }; - const int limit = basisu::min(group_size, num_vals - group_index * group_size); + const int limit = basisu::minimum(group_size, num_vals - group_index * group_size); for (int i = 0; i < limit; i++) vals[i] = pSrc_vals[group_index * group_size + i]; @@ -12480,7 +12480,7 @@ namespace basist // Read the weight bits if ((BASISD_IS_BIG_ENDIAN) || (!BASISD_USE_UNALIGNED_WORD_READS)) - bits = read_bits64(blk.m_bytes, bit_ofs, basisu::min(64, 128 - (int)bit_ofs)); + bits = read_bits64(blk.m_bytes, bit_ofs, basisu::minimum(64, 128 - (int)bit_ofs)); else { #ifdef __EMSCRIPTEN__ @@ -12649,7 +12649,7 @@ namespace basist color32 endpoints[3][2]; const uint32_t total_subsets = g_uastc_mode_subsets[mode]; - const uint32_t total_comps = basisu::min(4U, g_uastc_mode_comps[mode]); + const uint32_t total_comps = basisu::minimum(4U, g_uastc_mode_comps[mode]); const uint32_t endpoint_range = g_uastc_mode_endpoint_ranges[mode]; const uint32_t total_planes = g_uastc_mode_planes[mode]; const uint32_t weight_bits = g_uastc_mode_weight_bits[mode]; @@ -13845,7 +13845,7 @@ namespace basist uint32_t sels[4] = { 0,0,0,0 }; const uint32_t N = 4; - for (uint32_t i = 0; i < basisu::min(N, (256 - c)); i++) + for (uint32_t i = 0; i < basisu::minimum(N, (256 - c)); i++) { uint32_t best_sel_e = UINT32_MAX; uint32_t best_sel = 0; @@ -13925,7 +13925,7 @@ namespace basist uint32_t sels[4] = { 0,0,0,0 }; const uint32_t N = 1; - for (uint32_t i = 0; i < basisu::min(N, (256 - c)); i++) + for (uint32_t i = 0; i < basisu::minimum(N, (256 - c)); i++) { uint32_t best_sel_e = UINT32_MAX; uint32_t best_sel = 0; @@ -14029,8 +14029,8 @@ namespace basist for (uint32_t x = 0; x < 4; x++) { const uint32_t v = block_y[y][x]; - low[0] = basisu::min(low[0], v); - high[0] = basisu::max(high[0], v); + low[0] = basisu::minimum(low[0], v); + high[0] = basisu::maximum(high[0], v); } } for (uint32_t y = 2; y < 4; y++) @@ -14038,8 +14038,8 @@ namespace basist for (uint32_t x = 0; x < 4; x++) { const uint32_t v = block_y[y][x]; - low[1] = basisu::min(low[1], v); - high[1] = basisu::max(high[1], v); + low[1] = basisu::minimum(low[1], v); + high[1] = basisu::maximum(high[1], v); } } } @@ -14050,8 +14050,8 @@ namespace basist for (uint32_t x = 0; x < 2; x++) { const uint32_t v = block_y[y][x]; - low[0] = basisu::min(low[0], v); - high[0] = basisu::max(high[0], v); + low[0] = basisu::minimum(low[0], v); + high[0] = basisu::maximum(high[0], v); } } for (uint32_t y = 0; y < 4; y++) @@ -14059,8 +14059,8 @@ namespace basist for (uint32_t x = 2; x < 4; x++) { const uint32_t v = block_y[y][x]; - low[1] = basisu::min(low[1], v); - high[1] = basisu::max(high[1], v); + low[1] = basisu::minimum(low[1], v); + high[1] = basisu::maximum(high[1], v); } } } @@ -14320,10 +14320,10 @@ namespace basist if ((inten_table_mask & (1 << inten)) == 0) continue; - const int t0 = basisu::max(low_limit, g_etc1_inten_tables[inten][0]); - const int t1 = basisu::max(low_limit, g_etc1_inten_tables[inten][1]); - const int t2 = basisu::min(high_limit, g_etc1_inten_tables[inten][2]); - const int t3 = basisu::min(high_limit, g_etc1_inten_tables[inten][3]); + const int t0 = basisu::maximum(low_limit, g_etc1_inten_tables[inten][0]); + const int t1 = basisu::maximum(low_limit, g_etc1_inten_tables[inten][1]); + const int t2 = basisu::minimum(high_limit, g_etc1_inten_tables[inten][2]); + const int t3 = basisu::minimum(high_limit, g_etc1_inten_tables[inten][3]); assert((t0 <= t1) && (t1 <= t2) && (t2 <= t3)); const int tv[4] = { t2, t3, t1, t0 }; @@ -14541,8 +14541,8 @@ namespace basist uint32_t min_a = 255, max_a = 0; for (uint32_t i = 0; i < 16; i++) { - min_a = basisu::min(min_a, pSrc_pixels[i].a); - max_a = basisu::max(max_a, pSrc_pixels[i].a); + min_a = basisu::minimum(min_a, pSrc_pixels[i].a); + max_a = basisu::maximum(max_a, pSrc_pixels[i].a); } if (min_a == max_a) @@ -14640,24 +14640,24 @@ namespace basist } { - uint32_t v0 = pPixels[4 * stride]; min0_v = basisu::min(min0_v, v0); max0_v = basisu::max(max0_v, v0); - uint32_t v1 = pPixels[5 * stride]; min1_v = basisu::min(min1_v, v1); max1_v = basisu::max(max1_v, v1); - uint32_t v2 = pPixels[6 * stride]; min2_v = basisu::min(min2_v, v2); max2_v = basisu::max(max2_v, v2); - uint32_t v3 = pPixels[7 * stride]; min3_v = basisu::min(min3_v, v3); max3_v = basisu::max(max3_v, v3); + uint32_t v0 = pPixels[4 * stride]; min0_v = basisu::minimum(min0_v, v0); max0_v = basisu::maximum(max0_v, v0); + uint32_t v1 = pPixels[5 * stride]; min1_v = basisu::minimum(min1_v, v1); max1_v = basisu::maximum(max1_v, v1); + uint32_t v2 = pPixels[6 * stride]; min2_v = basisu::minimum(min2_v, v2); max2_v = basisu::maximum(max2_v, v2); + uint32_t v3 = pPixels[7 * stride]; min3_v = basisu::minimum(min3_v, v3); max3_v = basisu::maximum(max3_v, v3); } { - uint32_t v0 = pPixels[8 * stride]; min0_v = basisu::min(min0_v, v0); max0_v = basisu::max(max0_v, v0); - uint32_t v1 = pPixels[9 * stride]; min1_v = basisu::min(min1_v, v1); max1_v = basisu::max(max1_v, v1); - uint32_t v2 = pPixels[10 * stride]; min2_v = basisu::min(min2_v, v2); max2_v = basisu::max(max2_v, v2); - uint32_t v3 = pPixels[11 * stride]; min3_v = basisu::min(min3_v, v3); max3_v = basisu::max(max3_v, v3); + uint32_t v0 = pPixels[8 * stride]; min0_v = basisu::minimum(min0_v, v0); max0_v = basisu::maximum(max0_v, v0); + uint32_t v1 = pPixels[9 * stride]; min1_v = basisu::minimum(min1_v, v1); max1_v = basisu::maximum(max1_v, v1); + uint32_t v2 = pPixels[10 * stride]; min2_v = basisu::minimum(min2_v, v2); max2_v = basisu::maximum(max2_v, v2); + uint32_t v3 = pPixels[11 * stride]; min3_v = basisu::minimum(min3_v, v3); max3_v = basisu::maximum(max3_v, v3); } { - uint32_t v0 = pPixels[12 * stride]; min0_v = basisu::min(min0_v, v0); max0_v = basisu::max(max0_v, v0); - uint32_t v1 = pPixels[13 * stride]; min1_v = basisu::min(min1_v, v1); max1_v = basisu::max(max1_v, v1); - uint32_t v2 = pPixels[14 * stride]; min2_v = basisu::min(min2_v, v2); max2_v = basisu::max(max2_v, v2); - uint32_t v3 = pPixels[15 * stride]; min3_v = basisu::min(min3_v, v3); max3_v = basisu::max(max3_v, v3); + uint32_t v0 = pPixels[12 * stride]; min0_v = basisu::minimum(min0_v, v0); max0_v = basisu::maximum(max0_v, v0); + uint32_t v1 = pPixels[13 * stride]; min1_v = basisu::minimum(min1_v, v1); max1_v = basisu::maximum(max1_v, v1); + uint32_t v2 = pPixels[14 * stride]; min2_v = basisu::minimum(min2_v, v2); max2_v = basisu::maximum(max2_v, v2); + uint32_t v3 = pPixels[15 * stride]; min3_v = basisu::minimum(min3_v, v3); max3_v = basisu::maximum(max3_v, v3); } const uint32_t min_v = basisu::minimum(min0_v, min1_v, min2_v, min3_v); @@ -14982,8 +14982,8 @@ namespace basist for (uint32_t i = 1; i < 16; i++) { const int r = pSrc_pixels[i].r, g = pSrc_pixels[i].g, b = pSrc_pixels[i].b; - max_r = basisu::max(max_r, r); max_g = basisu::max(max_g, g); max_b = basisu::max(max_b, b); - min_r = basisu::min(min_r, r); min_g = basisu::min(min_g, g); min_b = basisu::min(min_b, b); + max_r = basisu::maximum(max_r, r); max_g = basisu::maximum(max_g, g); max_b = basisu::maximum(max_b, b); + min_r = basisu::minimum(min_r, r); min_g = basisu::minimum(min_g, g); min_b = basisu::minimum(min_b, b); total_r += r; total_g += g; total_b += b; } @@ -15214,8 +15214,8 @@ namespace basist { const int r = pSrc_pixels[i].r, g = pSrc_pixels[i].g, b = pSrc_pixels[i].b; grayscale_flag &= ((r == g) && (r == b)); - max_r = basisu::max(max_r, r); max_g = basisu::max(max_g, g); max_b = basisu::max(max_b, b); - min_r = basisu::min(min_r, r); min_g = basisu::min(min_g, g); min_b = basisu::min(min_b, b); + max_r = basisu::maximum(max_r, r); max_g = basisu::maximum(max_g, g); max_b = basisu::maximum(max_b, b); + min_r = basisu::minimum(min_r, r); min_g = basisu::minimum(min_g, g); min_b = basisu::minimum(min_b, b); total_r += r; total_g += g; total_b += b; } @@ -15252,25 +15252,25 @@ namespace basist uint32_t min_d0 = (dist[0][0] + dist[1][0] + dist[2][0]); uint32_t d4 = (dist[0][0] + dist[1][0] + dist[2][1]) | 4; - min_d0 = basisu::min(min_d0, d4); + min_d0 = basisu::minimum(min_d0, d4); uint32_t min_d1 = (dist[0][1] + dist[1][0] + dist[2][0]) | 1; uint32_t d5 = (dist[0][1] + dist[1][0] + dist[2][1]) | 5; - min_d1 = basisu::min(min_d1, d5); + min_d1 = basisu::minimum(min_d1, d5); uint32_t d2 = (dist[0][0] + dist[1][1] + dist[2][0]) | 2; - min_d0 = basisu::min(min_d0, d2); + min_d0 = basisu::minimum(min_d0, d2); uint32_t d3 = (dist[0][1] + dist[1][1] + dist[2][0]) | 3; - min_d1 = basisu::min(min_d1, d3); + min_d1 = basisu::minimum(min_d1, d3); uint32_t d6 = (dist[0][0] + dist[1][1] + dist[2][1]) | 6; - min_d0 = basisu::min(min_d0, d6); + min_d0 = basisu::minimum(min_d0, d6); uint32_t d7 = (dist[0][1] + dist[1][1] + dist[2][1]) | 7; - min_d1 = basisu::min(min_d1, d7); + min_d1 = basisu::minimum(min_d1, d7); - uint32_t min_d = basisu::min(min_d0, min_d1); + uint32_t min_d = basisu::minimum(min_d0, min_d1); uint32_t best_i = min_d & 7; int delta_r = (best_i & 1) ? (max_r - avg_r) : (avg_r - min_r); @@ -15855,10 +15855,10 @@ namespace basist const int v2 = clamp255(mul[2] * g_eac_modifier_table[T2][s] + base[2]); const int v3 = clamp255(mul[3] * g_eac_modifier_table[T3][s] + base[3]); - l0 = basisu::min(l0, (basisu::iabs(v0 - a) << 3) | s); - l1 = basisu::min(l1, (basisu::iabs(v1 - a) << 3) | s); - l2 = basisu::min(l2, (basisu::iabs(v2 - a) << 3) | s); - l3 = basisu::min(l3, (basisu::iabs(v3 - a) << 3) | s); + l0 = basisu::minimum(l0, (basisu::iabs(v0 - a) << 3) | s); + l1 = basisu::minimum(l1, (basisu::iabs(v1 - a) << 3) | s); + l2 = basisu::minimum(l2, (basisu::iabs(v2 - a) << 3) | s); + l3 = basisu::minimum(l3, (basisu::iabs(v3 - a) << 3) | s); } } else if (mul_or == 1) @@ -15872,10 +15872,10 @@ namespace basist const int v2 = g_eac_modifier_table[T2][s] + a2; const int v3 = g_eac_modifier_table[T3][s] + a3; - l0 = basisu::min(l0, (basisu::iabs(v0) << 3) | s); - l1 = basisu::min(l1, (basisu::iabs(v1) << 3) | s); - l2 = basisu::min(l2, (basisu::iabs(v2) << 3) | s); - l3 = basisu::min(l3, (basisu::iabs(v3) << 3) | s); + l0 = basisu::minimum(l0, (basisu::iabs(v0) << 3) | s); + l1 = basisu::minimum(l1, (basisu::iabs(v1) << 3) | s); + l2 = basisu::minimum(l2, (basisu::iabs(v2) << 3) | s); + l3 = basisu::minimum(l3, (basisu::iabs(v3) << 3) | s); } } else @@ -15889,10 +15889,10 @@ namespace basist const int v2 = mul[2] * g_eac_modifier_table[T2][s] + a2; const int v3 = mul[3] * g_eac_modifier_table[T3][s] + a3; - l0 = basisu::min(l0, (basisu::iabs(v0) << 3) | s); - l1 = basisu::min(l1, (basisu::iabs(v1) << 3) | s); - l2 = basisu::min(l2, (basisu::iabs(v2) << 3) | s); - l3 = basisu::min(l3, (basisu::iabs(v3) << 3) | s); + l0 = basisu::minimum(l0, (basisu::iabs(v0) << 3) | s); + l1 = basisu::minimum(l1, (basisu::iabs(v1) << 3) | s); + l2 = basisu::minimum(l2, (basisu::iabs(v2) << 3) | s); + l3 = basisu::minimum(l3, (basisu::iabs(v3) << 3) | s); } } @@ -16011,13 +16011,13 @@ namespace basist else { uint32_t l = basisu::iabs(clamp255(m * pTable[0] + b) - a) << 3; - l = basisu::min(l, (basisu::iabs(clamp255(m * pTable[1] + b) - a) << 3) | 1); - l = basisu::min(l, (basisu::iabs(clamp255(m * pTable[2] + b) - a) << 3) | 2); - l = basisu::min(l, (basisu::iabs(clamp255(m * pTable[3] + b) - a) << 3) | 3); - l = basisu::min(l, (basisu::iabs(clamp255(m * pTable[4] + b) - a) << 3) | 4); - l = basisu::min(l, (basisu::iabs(clamp255(m * pTable[5] + b) - a) << 3) | 5); - l = basisu::min(l, (basisu::iabs(clamp255(m * pTable[6] + b) - a) << 3) | 6); - l = basisu::min(l, (basisu::iabs(clamp255(m * pTable[7] + b) - a) << 3) | 7); + l = basisu::minimum(l, (basisu::iabs(clamp255(m * pTable[1] + b) - a) << 3) | 1); + l = basisu::minimum(l, (basisu::iabs(clamp255(m * pTable[2] + b) - a) << 3) | 2); + l = basisu::minimum(l, (basisu::iabs(clamp255(m * pTable[3] + b) - a) << 3) | 3); + l = basisu::minimum(l, (basisu::iabs(clamp255(m * pTable[4] + b) - a) << 3) | 4); + l = basisu::minimum(l, (basisu::iabs(clamp255(m * pTable[5] + b) - a) << 3) | 5); + l = basisu::minimum(l, (basisu::iabs(clamp255(m * pTable[6] + b) - a) << 3) | 6); + l = basisu::minimum(l, (basisu::iabs(clamp255(m * pTable[7] + b) - a) << 3) | 7); sels[table][i] = l & 7; total_err[table] += basisu::square(l >> 3); @@ -16464,8 +16464,8 @@ namespace basist uint32_t low_a = 255, high_a = 0; for (uint32_t i = 0; i < 16; i++) { - low_a = basisu::min(low_a, block_pixels[i].a); - high_a = basisu::max(high_a, block_pixels[i].a); + low_a = basisu::minimum(low_a, block_pixels[i].a); + high_a = basisu::maximum(high_a, block_pixels[i].a); } low_color.set(low_a, low_a, low_a, 255); high_color.set(high_a, high_a, high_a, 255); diff --git a/transcoder/basisu_transcoder_internal.h b/transcoder/basisu_transcoder_internal.h index 672e678..28e7eeb 100644 --- a/transcoder/basisu_transcoder_internal.h +++ b/transcoder/basisu_transcoder_internal.h @@ -686,8 +686,8 @@ namespace basist bool operator== (const color32&rhs) const { return m == rhs.m; } - static color32 comp_min(const color32& a, const color32& b) { return color32(cNoClamp, basisu::min(a[0], b[0]), basisu::min(a[1], b[1]), basisu::min(a[2], b[2]), basisu::min(a[3], b[3])); } - static color32 comp_max(const color32& a, const color32& b) { return color32(cNoClamp, basisu::max(a[0], b[0]), basisu::max(a[1], b[1]), basisu::max(a[2], b[2]), basisu::max(a[3], b[3])); } + static color32 comp_min(const color32& a, const color32& b) { return color32(cNoClamp, basisu::minimum(a[0], b[0]), basisu::minimum(a[1], b[1]), basisu::minimum(a[2], b[2]), basisu::minimum(a[3], b[3])); } + static color32 comp_max(const color32& a, const color32& b) { return color32(cNoClamp, basisu::maximum(a[0], b[0]), basisu::maximum(a[1], b[1]), basisu::maximum(a[2], b[2]), basisu::maximum(a[3], b[3])); } }; struct endpoint