2012-11-15 16:51:55 +00:00
|
|
|
/* FasTC
|
2013-11-11 19:11:41 +00:00
|
|
|
* Copyright (c) 2013 University of North Carolina at Chapel Hill.
|
|
|
|
* All rights reserved.
|
2012-11-15 16:51:55 +00:00
|
|
|
*
|
2013-11-11 19:11:41 +00:00
|
|
|
* Permission to use, copy, modify, and distribute this software and its
|
|
|
|
* documentation for educational, research, and non-profit purposes, without
|
|
|
|
* fee, and without a written agreement is hereby granted, provided that the
|
|
|
|
* above copyright notice, this paragraph, and the following four paragraphs
|
|
|
|
* appear in all copies.
|
2012-11-15 16:51:55 +00:00
|
|
|
*
|
2013-11-11 19:11:41 +00:00
|
|
|
* Permission to incorporate this software into commercial products may be
|
|
|
|
* obtained by contacting the authors or the Office of Technology Development
|
|
|
|
* at the University of North Carolina at Chapel Hill <otd@unc.edu>.
|
2012-11-15 16:51:55 +00:00
|
|
|
*
|
2013-11-11 19:11:41 +00:00
|
|
|
* This software program and documentation are copyrighted by the University of
|
|
|
|
* North Carolina at Chapel Hill. The software program and documentation are
|
|
|
|
* supplied "as is," without any accompanying services from the University of
|
|
|
|
* North Carolina at Chapel Hill or the authors. The University of North
|
|
|
|
* Carolina at Chapel Hill and the authors do not warrant that the operation of
|
|
|
|
* the program will be uninterrupted or error-free. The end-user understands
|
|
|
|
* that the program was developed for research purposes and is advised not to
|
|
|
|
* rely exclusively on the program for any reason.
|
2012-11-15 16:51:55 +00:00
|
|
|
*
|
2013-11-11 19:11:41 +00:00
|
|
|
* IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
|
|
|
|
* AUTHORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
|
|
|
|
* OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA
|
|
|
|
* AT CHAPEL HILL OR THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
* DAMAGE.
|
2012-11-15 16:51:55 +00:00
|
|
|
*
|
2013-11-11 19:11:41 +00:00
|
|
|
* THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY
|
|
|
|
* DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
|
|
|
|
* STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON
|
|
|
|
* AN "AS IS" BASIS, AND THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND
|
|
|
|
* THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
2012-11-15 16:51:55 +00:00
|
|
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
*
|
|
|
|
* Please send all BUG REPORTS to <pavel@cs.unc.edu>.
|
|
|
|
*
|
|
|
|
* The authors may be contacted via:
|
|
|
|
*
|
|
|
|
* Pavel Krajcevski
|
|
|
|
* Dept of Computer Science
|
|
|
|
* 201 S Columbia St
|
|
|
|
* Frederick P. Brooks, Jr. Computer Science Bldg
|
|
|
|
* Chapel Hill, NC 27599-3175
|
|
|
|
* USA
|
|
|
|
*
|
|
|
|
* <http://gamma.cs.unc.edu/FasTC/>
|
|
|
|
*/
|
|
|
|
|
2013-11-11 19:11:41 +00:00
|
|
|
#define _CRT_SECURE_NO_WARNINGS
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
|
2014-10-24 13:10:29 +00:00
|
|
|
#include <algorithm>
|
2013-09-29 01:44:50 +00:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
2013-11-11 19:11:41 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
# include <SDKDDKVer.h>
|
|
|
|
# include <Windows.h>
|
|
|
|
# undef min
|
|
|
|
# undef max
|
|
|
|
#endif
|
2012-08-28 02:49:00 +00:00
|
|
|
|
2014-11-18 22:07:26 +00:00
|
|
|
#include "FasTC/Image.h"
|
|
|
|
#include "FasTC/ImageFile.h"
|
|
|
|
#include "FasTC/TexComp.h"
|
|
|
|
#include "FasTC/ThreadSafeStreambuf.h"
|
2012-08-28 02:49:00 +00:00
|
|
|
|
2012-08-30 21:37:23 +00:00
|
|
|
void PrintUsage() {
|
2013-02-07 22:01:21 +00:00
|
|
|
fprintf(stderr, "Usage: tc [OPTIONS] imagefile\n");
|
|
|
|
fprintf(stderr, "\n");
|
2013-11-08 21:21:01 +00:00
|
|
|
fprintf(stderr, "\t-v\t\tVerbose mode: prints out Entropy, Mean Local Entropy, and MSSIM\n");
|
2013-12-09 16:45:57 +00:00
|
|
|
fprintf(stderr, "\t-f <fmt>\tFormat to use. Either \"BPTC\", \"ETC1\", \"DXT1\", \"DXT5\", or \"PVRTC\". Default: BPTC\n");
|
2013-02-07 22:01:21 +00:00
|
|
|
fprintf(stderr, "\t-l\t\tSave an output log.\n");
|
2014-01-24 19:00:14 +00:00
|
|
|
fprintf(stderr, "\t-d <file>\tSpecify decompressed output (default: basename-<fmt>.png)\n");
|
2013-12-09 16:45:57 +00:00
|
|
|
fprintf(stderr, "\t-nd\t\tSuppress decompressed output\n");
|
2013-02-07 22:01:21 +00:00
|
|
|
fprintf(stderr, "\t-q <quality>\tSet compression quality level. Default: 50\n");
|
|
|
|
fprintf(stderr, "\t-n <num>\tCompress the image num times and give the average time and PSNR. Default: 1\n");
|
|
|
|
fprintf(stderr, "\t-simd\t\tUse SIMD compression path\n");
|
|
|
|
fprintf(stderr, "\t-t <num>\tCompress the image using <num> threads. Default: 1\n");
|
2013-03-07 07:31:21 +00:00
|
|
|
fprintf(stderr, "\t-a \t\tCompress the image using synchronization via atomic operations. Default: Off\n");
|
2013-02-07 22:01:21 +00:00
|
|
|
fprintf(stderr, "\t-j <num>\tUse <num> blocks for each work item in a worker queue threading model. Default: (Blocks / Threads)\n");
|
2012-08-30 21:37:23 +00:00
|
|
|
}
|
|
|
|
|
2013-11-11 19:11:41 +00:00
|
|
|
void ExtractBasename(const char *filename, char *buf, size_t bufSz) {
|
|
|
|
size_t len = strlen(filename);
|
2013-01-28 16:51:36 +00:00
|
|
|
const char *end = filename + len;
|
2013-09-30 15:17:17 +00:00
|
|
|
const char *ext = end;
|
2014-11-19 20:24:08 +00:00
|
|
|
const char *base = NULL;
|
2013-09-30 15:17:17 +00:00
|
|
|
while(--end != filename && !base) {
|
|
|
|
if(*end == '.') {
|
|
|
|
ext = end;
|
|
|
|
} else if(*end == '\\' || *end == '/') {
|
|
|
|
base = end + 1;
|
2013-01-28 16:51:36 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-30 15:17:17 +00:00
|
|
|
|
2015-02-12 05:26:31 +00:00
|
|
|
if (!base) {
|
|
|
|
base = end;
|
|
|
|
}
|
|
|
|
|
2013-11-17 19:17:00 +00:00
|
|
|
size_t numChars = ext - base + 1;
|
2013-11-11 19:11:41 +00:00
|
|
|
size_t toCopy = ::std::min(numChars, bufSz);
|
2013-09-30 15:17:17 +00:00
|
|
|
memcpy(buf, base, toCopy);
|
|
|
|
buf[toCopy - 1] = '\0';
|
|
|
|
return;
|
2012-10-21 18:07:46 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2014-11-03 23:24:19 +00:00
|
|
|
if (fileArg == argc) {
|
2012-09-13 20:32:07 +00:00
|
|
|
PrintUsage();
|
|
|
|
exit(1);
|
|
|
|
}
|
2012-08-30 21:37:23 +00:00
|
|
|
|
2014-11-03 23:24:19 +00:00
|
|
|
char decompressedOutput[256];
|
|
|
|
decompressedOutput[0] = '\0';
|
|
|
|
bool bDecompress = true;
|
2012-09-21 22:43:35 +00:00
|
|
|
int numJobs = 0;
|
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;
|
2012-10-08 22:51:41 +00:00
|
|
|
bool bSaveLog = false;
|
2013-03-07 07:31:21 +00:00
|
|
|
bool bUseAtomics = false;
|
2013-09-30 16:46:23 +00:00
|
|
|
bool bUsePVRTexLib = false;
|
2013-11-19 17:03:03 +00:00
|
|
|
bool bUseNVTT = false;
|
2013-11-06 23:23:19 +00:00
|
|
|
bool bVerbose = false;
|
2013-11-08 21:21:01 +00:00
|
|
|
FasTC::ECompressionFormat format = FasTC::eCompressionFormat_BPTC;
|
2013-09-20 16:43:59 +00:00
|
|
|
|
2012-08-30 21:37:23 +00:00
|
|
|
bool knowArg = false;
|
|
|
|
do {
|
|
|
|
knowArg = false;
|
2012-09-15 14:29:36 +00:00
|
|
|
|
2014-11-03 23:24:19 +00:00
|
|
|
if (strcmp(argv[fileArg], "-n") == 0) {
|
2012-09-15 14:29:36 +00:00
|
|
|
fileArg++;
|
|
|
|
|
2014-11-03 23:24:19 +00:00
|
|
|
if (fileArg == argc || (numCompressions = atoi(argv[fileArg])) < 0) {
|
2012-09-15 14:29:36 +00:00
|
|
|
PrintUsage();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
fileArg++;
|
|
|
|
knowArg = true;
|
2012-09-29 19:35:22 +00:00
|
|
|
continue;
|
2012-09-15 14:29:36 +00:00
|
|
|
}
|
2012-10-08 22:51:41 +00:00
|
|
|
|
2014-11-03 23:24:19 +00:00
|
|
|
if (strcmp(argv[fileArg], "-f") == 0) {
|
2013-09-20 16:43:59 +00:00
|
|
|
fileArg++;
|
|
|
|
|
2014-11-03 23:24:19 +00:00
|
|
|
if (fileArg == argc) {
|
2013-09-20 16:43:59 +00:00
|
|
|
PrintUsage();
|
|
|
|
exit(1);
|
|
|
|
} else {
|
2014-11-03 23:24:19 +00:00
|
|
|
if (!strcmp(argv[fileArg], "PVRTC")) {
|
2014-03-12 18:01:31 +00:00
|
|
|
format = FasTC::eCompressionFormat_PVRTC4;
|
2014-11-03 23:24:19 +00:00
|
|
|
} else if (!strcmp(argv[fileArg], "PVRTCLib")) {
|
2014-03-12 18:01:31 +00:00
|
|
|
format = FasTC::eCompressionFormat_PVRTC4;
|
2013-09-30 16:46:23 +00:00
|
|
|
bUsePVRTexLib = true;
|
2014-11-03 23:24:19 +00:00
|
|
|
} else if (!strcmp(argv[fileArg], "BPTCLib")) {
|
2013-11-19 17:03:03 +00:00
|
|
|
format = FasTC::eCompressionFormat_BPTC;
|
|
|
|
bUseNVTT = true;
|
2014-11-03 23:24:19 +00:00
|
|
|
} else if (!strcmp(argv[fileArg], "ETC1")) {
|
2013-11-08 21:21:01 +00:00
|
|
|
format = FasTC::eCompressionFormat_ETC1;
|
2014-11-03 23:24:19 +00:00
|
|
|
} else if (!strcmp(argv[fileArg], "DXT1")) {
|
2013-11-08 21:21:01 +00:00
|
|
|
format = FasTC::eCompressionFormat_DXT1;
|
2014-11-03 23:24:19 +00:00
|
|
|
} else if (!strcmp(argv[fileArg], "DXT5")) {
|
2013-11-08 21:21:01 +00:00
|
|
|
format = FasTC::eCompressionFormat_DXT5;
|
2013-09-20 16:43:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fileArg++;
|
|
|
|
knowArg = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-11-03 23:24:19 +00:00
|
|
|
if (strcmp(argv[fileArg], "-d") == 0) {
|
2013-12-09 16:45:57 +00:00
|
|
|
fileArg++;
|
2014-11-03 23:24:19 +00:00
|
|
|
|
|
|
|
if (fileArg == argc) {
|
2013-12-09 16:45:57 +00:00
|
|
|
PrintUsage();
|
|
|
|
exit(1);
|
|
|
|
} else {
|
|
|
|
size_t sz = 255;
|
|
|
|
sz = ::std::min(sz, static_cast<size_t>(strlen(argv[fileArg])));
|
|
|
|
memcpy(decompressedOutput, argv[fileArg], sz + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
fileArg++;
|
|
|
|
knowArg = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-11-03 23:24:19 +00:00
|
|
|
if (strcmp(argv[fileArg], "-nd") == 0) {
|
2013-12-09 16:45:57 +00:00
|
|
|
fileArg++;
|
2014-11-03 23:24:19 +00:00
|
|
|
bDecompress = false;
|
2013-12-09 16:45:57 +00:00
|
|
|
knowArg = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-11-03 23:24:19 +00:00
|
|
|
if (strcmp(argv[fileArg], "-l") == 0) {
|
2012-10-08 22:51:41 +00:00
|
|
|
fileArg++;
|
|
|
|
bSaveLog = true;
|
|
|
|
knowArg = true;
|
|
|
|
continue;
|
|
|
|
}
|
2014-11-03 23:24:19 +00:00
|
|
|
|
|
|
|
if (strcmp(argv[fileArg], "-v") == 0) {
|
2013-11-06 23:23:19 +00:00
|
|
|
fileArg++;
|
|
|
|
bVerbose = true;
|
|
|
|
knowArg = true;
|
|
|
|
continue;
|
|
|
|
}
|
2014-11-03 23:24:19 +00:00
|
|
|
|
|
|
|
if (strcmp(argv[fileArg], "-simd") == 0) {
|
2012-08-30 21:37:23 +00:00
|
|
|
fileArg++;
|
|
|
|
bUseSIMD = true;
|
|
|
|
knowArg = true;
|
2012-09-29 19:35:22 +00:00
|
|
|
continue;
|
2012-08-30 21:37:23 +00:00
|
|
|
}
|
|
|
|
|
2014-11-03 23:24:19 +00:00
|
|
|
if (strcmp(argv[fileArg], "-t") == 0) {
|
2012-08-30 21:37:23 +00:00
|
|
|
fileArg++;
|
2014-11-03 23:24:19 +00:00
|
|
|
|
|
|
|
if (fileArg == argc || (numThreads = atoi(argv[fileArg])) < 1) {
|
2013-03-07 07:31:21 +00:00
|
|
|
PrintUsage();
|
|
|
|
exit(1);
|
2012-08-30 21:37:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fileArg++;
|
|
|
|
knowArg = true;
|
2012-09-29 19:35:22 +00:00
|
|
|
continue;
|
2012-08-30 21:37:23 +00:00
|
|
|
}
|
|
|
|
|
2014-11-03 23:24:19 +00:00
|
|
|
if (strcmp(argv[fileArg], "-q") == 0) {
|
2012-08-30 21:37:23 +00:00
|
|
|
fileArg++;
|
2014-11-03 23:24:19 +00:00
|
|
|
|
|
|
|
if (fileArg == argc || (quality = atoi(argv[fileArg])) < 0) {
|
2013-03-07 07:31:21 +00:00
|
|
|
PrintUsage();
|
|
|
|
exit(1);
|
2012-08-30 21:37:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fileArg++;
|
|
|
|
knowArg = true;
|
2012-09-29 19:35:22 +00:00
|
|
|
continue;
|
2012-08-30 21:37:23 +00:00
|
|
|
}
|
|
|
|
|
2014-11-03 23:24:19 +00:00
|
|
|
if (strcmp(argv[fileArg], "-j") == 0) {
|
2012-09-21 22:43:35 +00:00
|
|
|
fileArg++;
|
2014-11-03 23:24:19 +00:00
|
|
|
|
|
|
|
if (fileArg == argc || (numJobs = atoi(argv[fileArg])) < 0) {
|
2013-03-07 07:31:21 +00:00
|
|
|
PrintUsage();
|
|
|
|
exit(1);
|
2012-09-21 22:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fileArg++;
|
|
|
|
knowArg = true;
|
2012-09-29 19:35:22 +00:00
|
|
|
continue;
|
2012-09-21 22:43:35 +00:00
|
|
|
}
|
|
|
|
|
2014-11-03 23:24:19 +00:00
|
|
|
if (strcmp(argv[fileArg], "-a") == 0) {
|
2013-03-07 07:31:21 +00:00
|
|
|
fileArg++;
|
|
|
|
bUseAtomics = true;
|
|
|
|
knowArg = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-11-03 23:24:19 +00:00
|
|
|
} while (knowArg && fileArg < argc);
|
2012-08-30 21:37:23 +00:00
|
|
|
|
2014-11-03 23:24:19 +00:00
|
|
|
if (fileArg == argc) {
|
2012-08-30 21:37:23 +00:00
|
|
|
PrintUsage();
|
2012-08-28 02:49:00 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2013-01-28 16:51:36 +00:00
|
|
|
char basename[256];
|
|
|
|
ExtractBasename(argv[fileArg], basename, 256);
|
2012-10-21 18:07:46 +00:00
|
|
|
|
2014-11-03 23:24:19 +00:00
|
|
|
ImageFile file(argv[fileArg]);
|
|
|
|
if (!file.Load()) {
|
2012-09-21 20:42:15 +00:00
|
|
|
return 1;
|
2013-01-28 16:51:36 +00:00
|
|
|
}
|
2012-10-07 04:34:06 +00:00
|
|
|
|
2013-10-04 22:35:18 +00:00
|
|
|
FasTC::Image<> img(*file.GetImage());
|
2012-10-20 23:30:14 +00:00
|
|
|
|
2014-11-03 23:24:19 +00:00
|
|
|
if (bVerbose) {
|
2013-11-06 23:23:19 +00:00
|
|
|
fprintf(stdout, "Entropy: %.5f\n", img.ComputeEntropy());
|
|
|
|
fprintf(stdout, "Mean Local Entropy: %.5f\n", img.ComputeMeanLocalEntropy());
|
|
|
|
}
|
2013-10-18 08:12:49 +00:00
|
|
|
|
2013-09-29 01:44:50 +00:00
|
|
|
std::ofstream logFile;
|
2013-09-29 02:40:14 +00:00
|
|
|
ThreadSafeStreambuf streamBuf(logFile);
|
2013-09-29 01:44:50 +00:00
|
|
|
std::ostream logStream(&streamBuf);
|
2014-11-03 23:24:19 +00:00
|
|
|
if (bSaveLog) {
|
2013-09-29 01:44:50 +00:00
|
|
|
char logname[256];
|
|
|
|
sprintf(logname, "%s.log", basename);
|
|
|
|
logFile.open(logname);
|
2012-10-08 22:51:41 +00:00
|
|
|
}
|
2014-11-03 23:24:19 +00:00
|
|
|
|
2012-08-28 02:49:00 +00:00
|
|
|
SCompressionSettings settings;
|
2013-09-20 16:43:59 +00:00
|
|
|
settings.format = format;
|
2012-08-30 21:37:23 +00:00
|
|
|
settings.bUseSIMD = bUseSIMD;
|
2013-03-07 07:31:21 +00:00
|
|
|
settings.bUseAtomics = bUseAtomics;
|
2012-08-30 21:37:23 +00:00
|
|
|
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-09-21 22:43:35 +00:00
|
|
|
settings.iJobSize = numJobs;
|
2013-09-30 16:46:23 +00:00
|
|
|
settings.bUsePVRTexLib = bUsePVRTexLib;
|
2013-11-19 17:03:03 +00:00
|
|
|
settings.bUseNVTT = bUseNVTT;
|
2014-11-03 23:24:19 +00:00
|
|
|
if (bSaveLog) {
|
2013-09-30 15:08:33 +00:00
|
|
|
settings.logStream = &logStream;
|
|
|
|
} else {
|
|
|
|
settings.logStream = NULL;
|
|
|
|
}
|
2012-08-30 21:37:23 +00:00
|
|
|
|
2013-09-13 23:36:37 +00:00
|
|
|
CompressedImage *ci = CompressImage(&img, settings);
|
2014-11-03 23:24:19 +00:00
|
|
|
if (NULL == ci) {
|
2012-09-19 02:33:18 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2012-10-20 23:37:21 +00:00
|
|
|
|
2014-11-03 23:24:19 +00:00
|
|
|
if (ci->GetWidth() != img.GetWidth() ||
|
2014-11-19 20:24:08 +00:00
|
|
|
ci->GetHeight() != img.GetHeight()) {
|
2014-11-03 23:24:19 +00:00
|
|
|
fprintf(stderr, "Cannot compute image metrics: compressed and uncompressed dimensions differ.\n");
|
|
|
|
} else {
|
|
|
|
double PSNR = img.ComputePSNR(ci);
|
|
|
|
if(PSNR > 0.0) {
|
|
|
|
fprintf(stdout, "PSNR: %.3f\n", PSNR);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "Error computing PSNR\n");
|
|
|
|
}
|
2012-09-18 23:00:20 +00:00
|
|
|
|
2014-11-03 23:24:19 +00:00
|
|
|
if(bVerbose) {
|
|
|
|
double SSIM = img.ComputeSSIM(ci);
|
|
|
|
if(SSIM > 0.0) {
|
|
|
|
fprintf(stdout, "SSIM: %.9f\n", SSIM);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Error computing SSIM\n");
|
|
|
|
}
|
2013-11-06 23:23:19 +00:00
|
|
|
}
|
2013-10-11 17:09:33 +00:00
|
|
|
}
|
|
|
|
|
2014-11-03 23:24:19 +00:00
|
|
|
if(bDecompress) {
|
2013-12-09 16:45:57 +00:00
|
|
|
if(decompressedOutput[0] != '\0') {
|
|
|
|
memcpy(basename, decompressedOutput, 256);
|
|
|
|
} else if(format == FasTC::eCompressionFormat_BPTC) {
|
2014-01-21 19:46:25 +00:00
|
|
|
strcat(basename, "-bptc.png");
|
2014-03-12 18:01:31 +00:00
|
|
|
} else if(format == FasTC::eCompressionFormat_PVRTC4) {
|
|
|
|
strcat(basename, "-pvrtc-4bpp.png");
|
2013-12-09 16:45:57 +00:00
|
|
|
} else if(format == FasTC::eCompressionFormat_DXT1) {
|
|
|
|
strcat(basename, "-dxt1.png");
|
|
|
|
} else if(format == FasTC::eCompressionFormat_ETC1) {
|
|
|
|
strcat(basename, "-etc1.png");
|
|
|
|
}
|
2013-09-25 20:36:34 +00:00
|
|
|
|
2014-01-24 19:00:14 +00:00
|
|
|
EImageFileFormat fmt = ImageFile::DetectFileFormat(basename);
|
|
|
|
ImageFile cImgFile (basename, fmt, *ci);
|
2013-12-09 16:45:57 +00:00
|
|
|
cImgFile.Write();
|
|
|
|
}
|
2012-10-20 23:37:21 +00:00
|
|
|
|
2012-08-28 02:49:00 +00:00
|
|
|
// Cleanup
|
2012-09-19 02:33:18 +00:00
|
|
|
delete ci;
|
2013-09-29 01:44:50 +00:00
|
|
|
if(bSaveLog) {
|
|
|
|
logFile.close();
|
|
|
|
}
|
2012-08-28 02:49:00 +00:00
|
|
|
return 0;
|
2013-11-19 17:03:03 +00:00
|
|
|
}
|