Add hooks to support filenames with .ktx extension

This commit is contained in:
Pavel Krajcevski 2014-01-24 14:00:14 -05:00
parent 552b8440b1
commit 1b5b8c3900
6 changed files with 20 additions and 4 deletions

View file

@ -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-v\t\tVerbose mode: prints out Entropy, Mean Local Entropy, and MSSIM\n");
fprintf(stderr, "\t-f <fmt>\tFormat to use. Either \"BPTC\", \"ETC1\", \"DXT1\", \"DXT5\", or \"PVRTC\". Default: BPTC\n"); fprintf(stderr, "\t-f <fmt>\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-l\t\tSave an output log.\n");
fprintf(stderr, "\t-d <file>\tSpecify decompressed output (currently only png files supported, default: basename-<fmt>.png)\n"); fprintf(stderr, "\t-d <file>\tSpecify decompressed output (default: basename-<fmt>.png)\n");
fprintf(stderr, "\t-nd\t\tSuppress decompressed output\n"); fprintf(stderr, "\t-nd\t\tSuppress decompressed output\n");
fprintf(stderr, "\t-q <quality>\tSet compression quality level. Default: 50\n"); 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-n <num>\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"); strcat(basename, "-etc1.png");
} }
ImageFile cImgFile (basename, eFileFormat_PNG, *ci); EImageFileFormat fmt = ImageFile::DetectFileFormat(basename);
ImageFile cImgFile (basename, fmt, *ci);
cImgFile.Write(); cImgFile.Write();
} }

View file

@ -119,6 +119,7 @@ ADD_LIBRARY(FasTCIO
) )
TARGET_LINK_LIBRARIES( FasTCIO FasTCBase ) TARGET_LINK_LIBRARIES( FasTCIO FasTCBase )
TARGET_LINK_LIBRARIES( FasTCIO FasTCCore )
IF( PNG_FOUND ) IF( PNG_FOUND )
TARGET_LINK_LIBRARIES( FasTCIO ${PNG_LIBRARY} ) TARGET_LINK_LIBRARIES( FasTCIO ${PNG_LIBRARY} )

View file

@ -70,6 +70,7 @@ public:
~ImageFile(); ~ImageFile();
static EImageFileFormat DetectFileFormat(const CHAR *filename);
unsigned int GetWidth() const { return m_Width; } unsigned int GetWidth() const { return m_Width; }
unsigned int GetHeight() const { return m_Height; } unsigned int GetHeight() const { return m_Height; }
FasTC::Image<> *GetImage() const { return m_Image; } FasTC::Image<> *GetImage() const { return m_Image; }
@ -98,7 +99,6 @@ public:
bool ReadFileData(const CHAR *filename); bool ReadFileData(const CHAR *filename);
static bool WriteImageDataToFile(const uint8 *data, const uint32 dataSz, 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; FasTC::Image<> *LoadImage() const;
}; };

View file

@ -48,6 +48,7 @@ enum EImageFileFormat {
eFileFormat_PNG, eFileFormat_PNG,
eFileFormat_PVR, eFileFormat_PVR,
eFileFormat_TGA, eFileFormat_TGA,
eFileFormat_KTX,
kNumImageFileFormats kNumImageFileFormats
}; };

View file

@ -67,6 +67,9 @@
#include "ImageLoaderTGA.h" #include "ImageLoaderTGA.h"
#include "ImageLoaderKTX.h"
#include "ImageWriterKTX.h"
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
// //
// Static helper functions // Static helper functions
@ -162,6 +165,10 @@ bool ImageFile::Write() {
break; break;
#endif // PNG_FOUND #endif // PNG_FOUND
case eFileFormat_KTX:
writer = new ImageWriterKTX(*m_Image);
break;
default: default:
fprintf(stderr, "Unable to write image: unknown file format.\n"); fprintf(stderr, "Unable to write image: unknown file format.\n");
return false; return false;
@ -202,6 +209,10 @@ FasTC::Image<> *ImageFile::LoadImage() const {
loader = new ImageLoaderTGA(m_FileData, m_FileDataSz); loader = new ImageLoaderTGA(m_FileData, m_FileDataSz);
break; break;
case eFileFormat_KTX:
loader = new ImageLoaderKTX(m_FileData, m_FileDataSz);
break;
default: default:
fprintf(stderr, "Unable to load image: unknown file format.\n"); fprintf(stderr, "Unable to load image: unknown file format.\n");
return NULL; return NULL;
@ -265,6 +276,9 @@ EImageFileFormat ImageFile::DetectFileFormat(const CHAR *filename) {
else if(strcmp(ext, ".tga") == 0) { else if(strcmp(ext, ".tga") == 0) {
return eFileFormat_TGA; return eFileFormat_TGA;
} }
else if(strcmp(ext, ".ktx") == 0) {
return eFileFormat_KTX;
}
return kNumImageFileFormats; return kNumImageFileFormats;
} }

View file

@ -86,7 +86,6 @@ ADD_LIBRARY( PVRTCEncoder
) )
TARGET_LINK_LIBRARIES( PVRTCEncoder FasTCBase ) TARGET_LINK_LIBRARIES( PVRTCEncoder FasTCBase )
TARGET_LINK_LIBRARIES( PVRTCEncoder FasTCCore )
TARGET_LINK_LIBRARIES( PVRTCEncoder FasTCIO ) TARGET_LINK_LIBRARIES( PVRTCEncoder FasTCIO )
IF( PVRTEXLIB_FOUND ) IF( PVRTEXLIB_FOUND )