From fc4cf7758b067ac93a79b3d360e2de6193a0c578 Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Thu, 30 Aug 2012 17:46:34 -0400 Subject: [PATCH] Add ability to change quality of BPTC encoder. --- CLTool/src/clunix.cpp | 3 ++- Core/include/TexComp.h | 1 + Core/src/TexComp.cpp | 21 ++++++++++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CLTool/src/clunix.cpp b/CLTool/src/clunix.cpp index 0ec8d87..9ddb255 100644 --- a/CLTool/src/clunix.cpp +++ b/CLTool/src/clunix.cpp @@ -41,7 +41,7 @@ int main(int argc, char **argv) { if(strcmp(argv[fileArg], "-q") == 0) { fileArg++; - if(fileArg == argc || (quality = atoi(argv[fileArg])) < 1) { + if(fileArg == argc || (quality = atoi(argv[fileArg])) < 0) { PrintUsage(); exit(1); } @@ -62,6 +62,7 @@ int main(int argc, char **argv) { SCompressionSettings settings; settings.bUseSIMD = bUseSIMD; settings.iNumThreads = numThreads; + settings.iQuality = quality; CompressedImage *ci = CompressImage(file, settings); diff --git a/Core/include/TexComp.h b/Core/include/TexComp.h index e789bf0..e10fac1 100644 --- a/Core/include/TexComp.h +++ b/Core/include/TexComp.h @@ -9,6 +9,7 @@ struct SCompressionSettings { ECompressionFormat format; bool bUseSIMD; int iNumThreads; + int iQuality; }; extern CompressedImage * CompressImage( diff --git a/Core/src/TexComp.cpp b/Core/src/TexComp.cpp index a395957..7792d5a 100644 --- a/Core/src/TexComp.cpp +++ b/Core/src/TexComp.cpp @@ -5,16 +5,35 @@ #include #include +template +static T min(const T &a, const T &b) { + return (a < b)? a : b; +} + +template +static T max(const T &a, const T &b) { + return (a > b)? a : b; +} + +template +static void clamp(T &x, const T &minX, const T &maxX) { + x = max(min(maxX, x), minX); +} + SCompressionSettings:: SCompressionSettings() : format(eCompressionFormat_BPTC) , bUseSIMD(false) , iNumThreads(1) -{} + , iQuality(50) +{ + clamp(iQuality, 0, 256); +} static CompressionFunc ChooseFuncFromSettings(const SCompressionSettings &s) { switch(s.format) { case eCompressionFormat_BPTC: { + BC7C::SetQualityLevel(s.iQuality); if(s.bUseSIMD) { return BC7C::CompressImageBC7SIMD; }