From 50833b01ac966835195287bd1ebd46c630bd55be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Tue, 23 Jul 2019 20:42:41 -0700 Subject: [PATCH] Cleanup. --- include/bimg/encode.h | 6 ++--- src/image_encode.cpp | 16 ++++++----- tools/texturec/texturec.cpp | 53 ++++++++++++++++++++----------------- 3 files changed, 42 insertions(+), 33 deletions(-) diff --git a/include/bimg/encode.h b/include/bimg/encode.h index 39876e6..1c7abff 100644 --- a/include/bimg/encode.h +++ b/include/bimg/encode.h @@ -18,9 +18,9 @@ namespace bimg Highest, Fastest, - NormalMap_Default, // Treat the source as a normal map - NormalMap_Highest, - NormalMap_Fastest, + NormalMapDefault, // Treat the source as a normal map + NormalMapHighest, + NormalMapFastest, Count }; diff --git a/src/image_encode.cpp b/src/image_encode.cpp index cd5eadb..faf1a45 100644 --- a/src/image_encode.cpp +++ b/src/image_encode.cpp @@ -150,13 +150,17 @@ namespace bimg { const bimg::ImageBlockInfo& astcBlockInfo = bimg::getBlockInfo(_format); - ASTC_COMPRESS_MODE compress_mode = s_astcQuality[_quality]; - ASTC_DECODE_MODE decode_mode = ASTC_DECODE_LDR_LINEAR; + ASTC_COMPRESS_MODE compress_mode = s_astcQuality[_quality]; + ASTC_DECODE_MODE decode_mode = ASTC_DECODE_LDR_LINEAR; - if (Quality::NormalMap_Default <= _quality) - astc_compress(_width, _height, src, ASTC_ENC_NORMAL_RA, srcPitch, astcBlockInfo.blockWidth, astcBlockInfo.blockHeight, compress_mode, decode_mode, dst); - else - astc_compress(_width, _height, src, ASTC_RGBA, srcPitch, astcBlockInfo.blockWidth, astcBlockInfo.blockHeight, compress_mode, decode_mode, dst); + if (Quality::NormalMapDefault <= _quality) + { + astc_compress(_width, _height, src, ASTC_ENC_NORMAL_RA, srcPitch, astcBlockInfo.blockWidth, astcBlockInfo.blockHeight, compress_mode, decode_mode, dst); + } + else + { + astc_compress(_width, _height, src, ASTC_RGBA, srcPitch, astcBlockInfo.blockWidth, astcBlockInfo.blockHeight, compress_mode, decode_mode, dst); + } } break; diff --git a/tools/texturec/texturec.cpp b/tools/texturec/texturec.cpp index 64fd849..1fd0b12 100644 --- a/tools/texturec/texturec.cpp +++ b/tools/texturec/texturec.cpp @@ -3,7 +3,6 @@ * License: https://github.com/bkaradzic/bimg#license-bsd-2-clause */ -#include #include #include #include @@ -157,12 +156,12 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData const bimg::ImageBlockInfo& inputBlockInfo = bimg::getBlockInfo(inputFormat); const bimg::ImageBlockInfo& outputBlockInfo = bimg::getBlockInfo(outputFormat); const uint32_t blockWidth = outputBlockInfo.blockWidth; - const uint32_t blockHeight = outputBlockInfo.blockHeight; - const uint32_t minBlockX = outputBlockInfo.minBlockX; - const uint32_t minBlockY = outputBlockInfo.minBlockY; - uint32_t outputWidth = bx::max(blockWidth * minBlockX, ( (input->m_width + blockWidth - 1) / blockWidth )*blockWidth); - uint32_t outputHeight = bx::max(blockHeight * minBlockY, ( (input->m_height + blockHeight - 1) / blockHeight)*blockHeight); - uint32_t outputDepth = input->m_depth; + const uint32_t blockHeight = outputBlockInfo.blockHeight; + const uint32_t minBlockX = outputBlockInfo.minBlockX; + const uint32_t minBlockY = outputBlockInfo.minBlockY; + uint32_t outputWidth = bx::max(blockWidth * minBlockX, ( (input->m_width + blockWidth - 1) / blockWidth )*blockWidth); + uint32_t outputHeight = bx::max(blockHeight * minBlockY, ( (input->m_height + blockHeight - 1) / blockHeight)*blockHeight); + uint32_t outputDepth = input->m_depth; if (_options.mips && _options.mipSkip != 0) @@ -450,7 +449,7 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData , rgba ); - bimg::Quality::Enum nmapQuality = bimg::Quality::Enum(_options.quality + bimg::Quality::NormalMap_Default); + bimg::Quality::Enum nmapQuality = bimg::Quality::Enum(_options.quality + bimg::Quality::NormalMapDefault); bimg::imageEncodeFromRgba32f(_allocator , dstData , rgbaDst @@ -861,7 +860,7 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData , uint16_t(mip.m_height) ); - printf("%f\n", result); + bx::printf("%f\n", result); BX_FREE(_allocator, ref); } @@ -888,7 +887,7 @@ void help(const char* _error = NULL, bool _showHelp = true) { if (NULL != _error) { - fprintf(stderr, "Error:\n%s\n\n", _error); + bx::printf("Error:\n%s\n\n", _error); if (!_showHelp) { @@ -896,8 +895,8 @@ void help(const char* _error = NULL, bool _showHelp = true) } } - fprintf(stderr - , "texturec, bgfx texture compiler tool, version %d.%d.%d.\n" + bx::printf( + "texturec, bgfx texture compiler tool, version %d.%d.%d.\n" "Copyright 2011-2019 Branimir Karadzic. All rights reserved.\n" "License: https://github.com/bkaradzic/bimg#license-bsd-2-clause\n\n" , BIMG_TEXTUREC_VERSION_MAJOR @@ -905,8 +904,8 @@ void help(const char* _error = NULL, bool _showHelp = true) , BIMG_API_VERSION ); - fprintf(stderr - , "Usage: texturec -f -o [-t ]\n" + bx::printf( + "Usage: texturec -f -o [-t ]\n" "\n" "Supported file formats:\n" @@ -944,7 +943,7 @@ void help(const char* _error = NULL, bool _showHelp = true) " aspect ratio will be preserved.\n" " --radiance Radiance cubemap filter. (Lighting model: Phong, PhongBrdf, Blinn, BlinnBrdf, GGX)\n" " --as Save as.\n" - " --formats List all supported formats.\n" + " --formats List all supported formats.\n" " --validate *DEBUG* Validate that output image produced matches after loading.\n" "\n" @@ -1014,20 +1013,26 @@ int main(int _argc, const char* _argv[]) if (cmdLine.hasArg("formats")) { - printf("Uncompressed formats:\n"); + bx::printf("Uncompressed formats:\n"); - for (int format = bimg::TextureFormat::Unknown + 1; format < bimg::TextureFormat::UnknownDepth; format++) - printf(" %s\n", bimg::getName((bimg::TextureFormat::Enum) format)); + for (int format = bimg::TextureFormat::Unknown + 1; format < bimg::TextureFormat::UnknownDepth; format++) + { + bx::printf(" %s\n", bimg::getName((bimg::TextureFormat::Enum) format)); + } - for (int format = bimg::TextureFormat::UnknownDepth + 1; format < bimg::TextureFormat::Count; format++) - printf(" %s\n", bimg::getName((bimg::TextureFormat::Enum) format)); + for (int format = bimg::TextureFormat::UnknownDepth + 1; format < bimg::TextureFormat::Count; format++) + { + bx::printf(" %s\n", bimg::getName((bimg::TextureFormat::Enum) format)); + } - printf("Compressed formats:\n"); + bx::printf("Compressed formats:\n"); - for (int format = 0; format < bimg::TextureFormat::Unknown; format++) - printf(" %s\n", bimg::getName((bimg::TextureFormat::Enum) format)); + for (int format = 0; format < bimg::TextureFormat::Unknown; format++) + { + bx::printf(" %s\n", bimg::getName((bimg::TextureFormat::Enum) format)); + } - return bx::kExitSuccess; + return bx::kExitSuccess; } const char* inputFileName = cmdLine.findOption('f');