From f2c153febadcaab272f7cfa323c3c5edbd170fe1 Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Mon, 9 Dec 2013 11:45:57 -0500 Subject: [PATCH] Add a command line switch to not produce decompressed output --- CLTool/src/tc.cpp | 56 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/CLTool/src/tc.cpp b/CLTool/src/tc.cpp index 234e931..fb02d98 100644 --- a/CLTool/src/tc.cpp +++ b/CLTool/src/tc.cpp @@ -75,8 +75,10 @@ void PrintUsage() { fprintf(stderr, "Usage: tc [OPTIONS] imagefile\n"); fprintf(stderr, "\n"); fprintf(stderr, "\t-v\t\tVerbose mode: prints out Entropy, Mean Local Entropy, and MSSIM\n"); - fprintf(stderr, "\t-f\t\tFormat to use. Either \"BPTC\", \"ETC1\", \"DXT1\", \"DXT5\", or \"PVRTC\". Default: BPTC\n"); + fprintf(stderr, "\t-f \tFormat to use. Either \"BPTC\", \"ETC1\", \"DXT1\", \"DXT5\", or \"PVRTC\". Default: BPTC\n"); fprintf(stderr, "\t-l\t\tSave an output log.\n"); + fprintf(stderr, "\t-d \tSpecify decompressed output (currently only png files supported, default: basename-.png)\n"); + fprintf(stderr, "\t-nd\t\tSuppress decompressed output\n"); fprintf(stderr, "\t-q \tSet compression quality level. Default: 50\n"); fprintf(stderr, "\t-n \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"); @@ -113,6 +115,8 @@ int main(int argc, char **argv) { exit(1); } + char decompressedOutput[256]; decompressedOutput[0] = '\0'; + bool bNoDecompress = false; int numJobs = 0; int quality = 50; int numThreads = 1; @@ -171,6 +175,30 @@ int main(int argc, char **argv) { continue; } + if(strcmp(argv[fileArg], "-d") == 0) { + fileArg++; + + if(fileArg == argc) { + PrintUsage(); + exit(1); + } else { + size_t sz = 255; + sz = ::std::min(sz, static_cast(strlen(argv[fileArg]))); + memcpy(decompressedOutput, argv[fileArg], sz + 1); + } + + fileArg++; + knowArg = true; + continue; + } + + if(strcmp(argv[fileArg], "-nd") == 0) { + fileArg++; + bNoDecompress = true; + knowArg = true; + continue; + } + if(strcmp(argv[fileArg], "-l") == 0) { fileArg++; bSaveLog = true; @@ -309,18 +337,22 @@ int main(int argc, char **argv) { } } - if(format == FasTC::eCompressionFormat_BPTC) { - strcat(basename, "-bc7.png"); - } else if(format == FasTC::eCompressionFormat_PVRTC) { - strcat(basename, "-pvrtc.png"); - } else if(format == FasTC::eCompressionFormat_DXT1) { - strcat(basename, "-dxt1.png"); - } else if(format == FasTC::eCompressionFormat_ETC1) { - strcat(basename, "-etc1.png"); - } + if(!bNoDecompress) { + if(decompressedOutput[0] != '\0') { + memcpy(basename, decompressedOutput, 256); + } else if(format == FasTC::eCompressionFormat_BPTC) { + strcat(basename, "-bc7.png"); + } else if(format == FasTC::eCompressionFormat_PVRTC) { + strcat(basename, "-pvrtc.png"); + } else if(format == FasTC::eCompressionFormat_DXT1) { + strcat(basename, "-dxt1.png"); + } else if(format == FasTC::eCompressionFormat_ETC1) { + strcat(basename, "-etc1.png"); + } - ImageFile cImgFile (basename, eFileFormat_PNG, *ci); - cImgFile.Write(); + ImageFile cImgFile (basename, eFileFormat_PNG, *ci); + cImgFile.Write(); + } // Cleanup delete ci;