2012-08-28 02:49:00 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2012-08-30 21:37:23 +00:00
|
|
|
#include <string.h>
|
2012-08-28 02:49:00 +00:00
|
|
|
|
|
|
|
#include "TexComp.h"
|
2012-09-21 16:39:09 +00:00
|
|
|
#include "ImageFile.h"
|
2012-08-28 02:49:00 +00:00
|
|
|
|
2012-08-30 21:37:23 +00:00
|
|
|
void PrintUsage() {
|
|
|
|
fprintf(stderr, "Usage: tc [-s|-t <num>] <imagefile>\n");
|
|
|
|
}
|
|
|
|
|
2012-08-28 02:49:00 +00:00
|
|
|
int main(int argc, char **argv) {
|
|
|
|
|
2012-08-30 21:37:23 +00:00
|
|
|
int fileArg = 1;
|
2012-09-13 20:32:07 +00:00
|
|
|
if(fileArg == argc) {
|
|
|
|
PrintUsage();
|
|
|
|
exit(1);
|
|
|
|
}
|
2012-08-30 21:37:23 +00:00
|
|
|
|
|
|
|
int quality = 50;
|
|
|
|
int numThreads = 1;
|
2012-09-15 14:29:36 +00:00
|
|
|
int numCompressions = 1;
|
2012-08-30 21:37:23 +00:00
|
|
|
bool bUseSIMD = false;
|
|
|
|
|
|
|
|
bool knowArg = false;
|
|
|
|
do {
|
|
|
|
knowArg = false;
|
2012-09-15 14:29:36 +00:00
|
|
|
|
|
|
|
if(strcmp(argv[fileArg], "-n") == 0) {
|
|
|
|
fileArg++;
|
|
|
|
|
|
|
|
if(fileArg == argc || (numCompressions = atoi(argv[fileArg])) < 0) {
|
|
|
|
PrintUsage();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
fileArg++;
|
|
|
|
knowArg = true;
|
|
|
|
}
|
2012-08-30 21:37:23 +00:00
|
|
|
|
|
|
|
if(strcmp(argv[fileArg], "-s") == 0) {
|
|
|
|
fileArg++;
|
|
|
|
bUseSIMD = true;
|
|
|
|
knowArg = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(strcmp(argv[fileArg], "-t") == 0) {
|
|
|
|
fileArg++;
|
|
|
|
|
|
|
|
if(fileArg == argc || (numThreads = atoi(argv[fileArg])) < 1) {
|
|
|
|
PrintUsage();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
fileArg++;
|
|
|
|
knowArg = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(strcmp(argv[fileArg], "-q") == 0) {
|
|
|
|
fileArg++;
|
|
|
|
|
2012-08-30 21:46:34 +00:00
|
|
|
if(fileArg == argc || (quality = atoi(argv[fileArg])) < 0) {
|
2012-08-30 21:37:23 +00:00
|
|
|
PrintUsage();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
fileArg++;
|
|
|
|
knowArg = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} while(knowArg);
|
|
|
|
|
|
|
|
if(fileArg == argc) {
|
|
|
|
PrintUsage();
|
2012-08-28 02:49:00 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2012-08-30 21:37:23 +00:00
|
|
|
ImageFile file (argv[fileArg]);
|
2012-08-28 02:49:00 +00:00
|
|
|
|
|
|
|
SCompressionSettings settings;
|
2012-08-30 21:37:23 +00:00
|
|
|
settings.bUseSIMD = bUseSIMD;
|
|
|
|
settings.iNumThreads = numThreads;
|
2012-08-30 21:46:34 +00:00
|
|
|
settings.iQuality = quality;
|
2012-09-15 14:29:36 +00:00
|
|
|
settings.iNumCompressions = numCompressions;
|
2012-08-30 21:37:23 +00:00
|
|
|
|
2012-09-21 16:39:09 +00:00
|
|
|
CompressedImage *ci = file.Compress(settings);
|
2012-09-19 02:33:18 +00:00
|
|
|
if(NULL == ci) {
|
|
|
|
fprintf(stderr, "Error compressing image!\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-09-18 23:00:20 +00:00
|
|
|
double PSNR = ComputePSNR(*ci, file);
|
|
|
|
if(PSNR > 0.0) {
|
|
|
|
fprintf(stdout, "PSNR: %.3f\n", PSNR);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "Error computing PSNR\n");
|
|
|
|
}
|
|
|
|
|
2012-08-28 02:49:00 +00:00
|
|
|
// Cleanup
|
2012-09-19 02:33:18 +00:00
|
|
|
delete ci;
|
2012-09-18 23:00:20 +00:00
|
|
|
|
2012-08-28 02:49:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|