From 7d8afe92b761aa33ddfa7ccde2dee71944332ca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Mon, 11 Apr 2016 20:22:10 -0700 Subject: [PATCH] texturec: Added option for image quality assesment. --- 3rdparty/.editorconfig | 4 +++ tools/texturec/texturec.cpp | 51 +++++++++++++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/3rdparty/.editorconfig b/3rdparty/.editorconfig index 901bf58d0..214695015 100644 --- a/3rdparty/.editorconfig +++ b/3rdparty/.editorconfig @@ -8,6 +8,10 @@ indent_size = 4 indent_style = space indent_size = 2 +[iqa/*] +indent_style = tab +indent_size = 4 + [libsquish/*] indent_style = tab indent_size = 4 diff --git a/tools/texturec/texturec.cpp b/tools/texturec/texturec.cpp index 21d256ffb..ba23a5283 100644 --- a/tools/texturec/texturec.cpp +++ b/tools/texturec/texturec.cpp @@ -19,6 +19,10 @@ #include #include +extern "C" { +#include +} + #define STB_IMAGE_IMPLEMENTATION #include @@ -348,6 +352,7 @@ void help(const char* _error = NULL) " -m, --mips Generate mip-maps.\n" " -n, --normalmap Input texture is normal map.\n" " --sdf Compute SDF texture.\n" + " --iqa Image Quality Assesment\n" "\n" "For additional information, see https://github.com/bkaradzic/bgfx\n" @@ -409,8 +414,9 @@ int main(int _argc, const char* _argv[]) } } - const bool mips = cmdLine.hasArg('m', "mips"); - const bool normalMap = cmdLine.hasArg('n', "normalmap"); + const bool mips = cmdLine.hasArg('m', "mips"); + const bool normalMap = cmdLine.hasArg('n', "normalmap"); + const bool iqa = cmdLine.hasArg('\0', "iqa"); uint32_t size = (uint32_t)bx::getSize(&reader); const bgfx::Memory* mem = bgfx::alloc(size); @@ -567,6 +573,13 @@ int main(int _argc, const char* _argv[]) , mip.m_format ); + void* ref = NULL; + if (iqa) + { + ref = BX_ALLOC(&allocator, size); + memcpy(ref, rgba, size); + } + imageEncodeFromRgba8(output->data, rgba, dstMip.m_width, dstMip.m_height, format); for (uint8_t lod = 1; lod < numMips; ++lod) @@ -576,6 +589,40 @@ int main(int _argc, const char* _argv[]) uint8_t* data = const_cast(dstMip.m_data); imageEncodeFromRgba8(data, rgba, dstMip.m_width, dstMip.m_height, format); } + + if (NULL != ref) + { + imageDecodeToRgba8(rgba + , output->data + , mip.m_width + , mip.m_height + , mip.m_width*mip.m_bpp/8 + , format + ); + + static const iqa_ssim_args args = + { + 0.39f, // alpha + 0.731f, // beta + 1.12f, // gamma + 187, // L + 0.025987f, // K1 + 0.0173f, // K2 + 1 // factor + }; + + float result = iqa_ssim( (uint8_t*)ref + , rgba + , mip.m_width + , mip.m_height + , mip.m_width*mip.m_bpp/8 + , 0 + , &args + ); + printf("%f\n", result); + + BX_FREE(&allocator, ref); + } } BX_FREE(&allocator, temp);