Add ability to change quality of BPTC encoder.

This commit is contained in:
Pavel Krajcevski 2012-08-30 17:46:34 -04:00
parent add2f6fd96
commit fc4cf7758b
3 changed files with 23 additions and 2 deletions

View File

@ -41,7 +41,7 @@ int main(int argc, char **argv) {
if(strcmp(argv[fileArg], "-q") == 0) { if(strcmp(argv[fileArg], "-q") == 0) {
fileArg++; fileArg++;
if(fileArg == argc || (quality = atoi(argv[fileArg])) < 1) { if(fileArg == argc || (quality = atoi(argv[fileArg])) < 0) {
PrintUsage(); PrintUsage();
exit(1); exit(1);
} }
@ -62,6 +62,7 @@ int main(int argc, char **argv) {
SCompressionSettings settings; SCompressionSettings settings;
settings.bUseSIMD = bUseSIMD; settings.bUseSIMD = bUseSIMD;
settings.iNumThreads = numThreads; settings.iNumThreads = numThreads;
settings.iQuality = quality;
CompressedImage *ci = CompressImage(file, settings); CompressedImage *ci = CompressImage(file, settings);

View File

@ -9,6 +9,7 @@ struct SCompressionSettings {
ECompressionFormat format; ECompressionFormat format;
bool bUseSIMD; bool bUseSIMD;
int iNumThreads; int iNumThreads;
int iQuality;
}; };
extern CompressedImage * CompressImage( extern CompressedImage * CompressImage(

View File

@ -5,16 +5,35 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
template <typename T>
static T min(const T &a, const T &b) {
return (a < b)? a : b;
}
template <typename T>
static T max(const T &a, const T &b) {
return (a > b)? a : b;
}
template <typename T>
static void clamp(T &x, const T &minX, const T &maxX) {
x = max(min(maxX, x), minX);
}
SCompressionSettings:: SCompressionSettings() SCompressionSettings:: SCompressionSettings()
: format(eCompressionFormat_BPTC) : format(eCompressionFormat_BPTC)
, bUseSIMD(false) , bUseSIMD(false)
, iNumThreads(1) , iNumThreads(1)
{} , iQuality(50)
{
clamp(iQuality, 0, 256);
}
static CompressionFunc ChooseFuncFromSettings(const SCompressionSettings &s) { static CompressionFunc ChooseFuncFromSettings(const SCompressionSettings &s) {
switch(s.format) { switch(s.format) {
case eCompressionFormat_BPTC: case eCompressionFormat_BPTC:
{ {
BC7C::SetQualityLevel(s.iQuality);
if(s.bUseSIMD) { if(s.bUseSIMD) {
return BC7C::CompressImageBC7SIMD; return BC7C::CompressImageBC7SIMD;
} }