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) {
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);

View File

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

View File

@ -5,16 +5,35 @@
#include <stdlib.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()
: 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;
}