From 1b5b8c39006adb7ba2d8e6bd1e22b60922dee4be Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Fri, 24 Jan 2014 14:00:14 -0500 Subject: [PATCH] Add hooks to support filenames with .ktx extension --- CLTool/src/tc.cpp | 5 +++-- IO/CMakeLists.txt | 1 + IO/include/ImageFile.h | 2 +- IO/include/ImageFileFormat.h | 1 + IO/src/ImageFile.cpp | 14 ++++++++++++++ PVRTCEncoder/CMakeLists.txt | 1 - 6 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CLTool/src/tc.cpp b/CLTool/src/tc.cpp index fb02d98..e79e66d 100644 --- a/CLTool/src/tc.cpp +++ b/CLTool/src/tc.cpp @@ -77,7 +77,7 @@ void PrintUsage() { fprintf(stderr, "\t-v\t\tVerbose mode: prints out Entropy, Mean Local Entropy, and MSSIM\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-d \tSpecify decompressed output (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"); @@ -350,7 +350,8 @@ int main(int argc, char **argv) { strcat(basename, "-etc1.png"); } - ImageFile cImgFile (basename, eFileFormat_PNG, *ci); + EImageFileFormat fmt = ImageFile::DetectFileFormat(basename); + ImageFile cImgFile (basename, fmt, *ci); cImgFile.Write(); } diff --git a/IO/CMakeLists.txt b/IO/CMakeLists.txt index 49bc4de..dc90d3c 100644 --- a/IO/CMakeLists.txt +++ b/IO/CMakeLists.txt @@ -119,6 +119,7 @@ ADD_LIBRARY(FasTCIO ) TARGET_LINK_LIBRARIES( FasTCIO FasTCBase ) +TARGET_LINK_LIBRARIES( FasTCIO FasTCCore ) IF( PNG_FOUND ) TARGET_LINK_LIBRARIES( FasTCIO ${PNG_LIBRARY} ) diff --git a/IO/include/ImageFile.h b/IO/include/ImageFile.h index 5c222f8..2b7e01c 100644 --- a/IO/include/ImageFile.h +++ b/IO/include/ImageFile.h @@ -70,6 +70,7 @@ public: ~ImageFile(); + static EImageFileFormat DetectFileFormat(const CHAR *filename); unsigned int GetWidth() const { return m_Width; } unsigned int GetHeight() const { return m_Height; } FasTC::Image<> *GetImage() const { return m_Image; } @@ -98,7 +99,6 @@ public: bool ReadFileData(const CHAR *filename); static bool WriteImageDataToFile(const uint8 *data, const uint32 dataSz, const CHAR *filename); - static EImageFileFormat DetectFileFormat(const CHAR *filename); FasTC::Image<> *LoadImage() const; }; diff --git a/IO/include/ImageFileFormat.h b/IO/include/ImageFileFormat.h index 6035a81..fc4557e 100644 --- a/IO/include/ImageFileFormat.h +++ b/IO/include/ImageFileFormat.h @@ -48,6 +48,7 @@ enum EImageFileFormat { eFileFormat_PNG, eFileFormat_PVR, eFileFormat_TGA, + eFileFormat_KTX, kNumImageFileFormats }; diff --git a/IO/src/ImageFile.cpp b/IO/src/ImageFile.cpp index 5199cba..e4d767f 100644 --- a/IO/src/ImageFile.cpp +++ b/IO/src/ImageFile.cpp @@ -67,6 +67,9 @@ #include "ImageLoaderTGA.h" +#include "ImageLoaderKTX.h" +#include "ImageWriterKTX.h" + ////////////////////////////////////////////////////////////////////////////////////////// // // Static helper functions @@ -162,6 +165,10 @@ bool ImageFile::Write() { break; #endif // PNG_FOUND + case eFileFormat_KTX: + writer = new ImageWriterKTX(*m_Image); + break; + default: fprintf(stderr, "Unable to write image: unknown file format.\n"); return false; @@ -202,6 +209,10 @@ FasTC::Image<> *ImageFile::LoadImage() const { loader = new ImageLoaderTGA(m_FileData, m_FileDataSz); break; + case eFileFormat_KTX: + loader = new ImageLoaderKTX(m_FileData, m_FileDataSz); + break; + default: fprintf(stderr, "Unable to load image: unknown file format.\n"); return NULL; @@ -265,6 +276,9 @@ EImageFileFormat ImageFile::DetectFileFormat(const CHAR *filename) { else if(strcmp(ext, ".tga") == 0) { return eFileFormat_TGA; } + else if(strcmp(ext, ".ktx") == 0) { + return eFileFormat_KTX; + } return kNumImageFileFormats; } diff --git a/PVRTCEncoder/CMakeLists.txt b/PVRTCEncoder/CMakeLists.txt index 756e63c..2f8845b 100644 --- a/PVRTCEncoder/CMakeLists.txt +++ b/PVRTCEncoder/CMakeLists.txt @@ -86,7 +86,6 @@ ADD_LIBRARY( PVRTCEncoder ) TARGET_LINK_LIBRARIES( PVRTCEncoder FasTCBase ) -TARGET_LINK_LIBRARIES( PVRTCEncoder FasTCCore ) TARGET_LINK_LIBRARIES( PVRTCEncoder FasTCIO ) IF( PVRTEXLIB_FOUND )