diff --git a/CLTool/CMakeLists.txt b/CLTool/CMakeLists.txt index e69de29..9e2eeb8 100644 --- a/CLTool/CMakeLists.txt +++ b/CLTool/CMakeLists.txt @@ -0,0 +1,18 @@ + +IF( MSVC ) + SET( SOURCES "src/clwin32.cpp" ) +ELSE() + SET( SOURCES "src/clunix.cpp" ) +ENDIF() + +INCLUDE_DIRECTORIES( ${TexC_SOURCE_DIR}/Core/include ) +INCLUDE_DIRECTORIES( ${TexC_SOURCE_DIR}/IO/include ) + +ADD_EXECUTABLE( + tc + ${SOURCES} +) + +TARGET_LINK_LIBRARIES( tc TexCompIO ) +TARGET_LINK_LIBRARIES( tc TexCompCore ) +TARGET_LINK_LIBRARIES( tc BPTCEncoder ) diff --git a/CLTool/src/clunix.cpp b/CLTool/src/clunix.cpp new file mode 100644 index 0000000..a2cdb68 --- /dev/null +++ b/CLTool/src/clunix.cpp @@ -0,0 +1,21 @@ +#include +#include + +#include "TexComp.h" + +int main(int argc, char **argv) { + + if(argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(1); + } + + ImageFile file (argv[1]); + + SCompressionSettings settings; + CompressedImage *ci = CompressImage(file, settings); + + // Cleanup + delete ci; + return 0; +} diff --git a/CLTool/src/clwin32.cpp b/CLTool/src/clwin32.cpp new file mode 100644 index 0000000..202de88 --- /dev/null +++ b/CLTool/src/clwin32.cpp @@ -0,0 +1,3 @@ + +int main(int argc, char **argv) { +} diff --git a/CMakeLists.txt b/CMakeLists.txt index 07f8878..b179974 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,3 +4,5 @@ PROJECT(TexC) ADD_SUBDIRECTORY(BPTCEncoder) ADD_SUBDIRECTORY(IO) ADD_SUBDIRECTORY(Core) + +ADD_SUBDIRECTORY(CLTool) diff --git a/Core/include/CompressedImage.h b/Core/include/CompressedImage.h index f7737fa..bfce349 100644 --- a/Core/include/CompressedImage.h +++ b/Core/include/CompressedImage.h @@ -20,6 +20,7 @@ class CompressedImage { void InitData(const unsigned char *withData); public: + CompressedImage(); CompressedImage( const unsigned int width, const unsigned int height, diff --git a/Core/include/TexComp.h b/Core/include/TexComp.h index 41a6b58..e789bf0 100644 --- a/Core/include/TexComp.h +++ b/Core/include/TexComp.h @@ -11,9 +11,8 @@ struct SCompressionSettings { int iNumThreads; }; -extern void CompressImage( +extern CompressedImage * CompressImage( const ImageFile &, - CompressedImage &, const SCompressionSettings &settings ); diff --git a/Core/src/CompressedImage.cpp b/Core/src/CompressedImage.cpp index 5e1b639..db616cc 100644 --- a/Core/src/CompressedImage.cpp +++ b/Core/src/CompressedImage.cpp @@ -3,6 +3,13 @@ #include #include +CompressedImage::CompressedImage() + : m_Width(0) + , m_Height(0) + , m_Format(ECompressionFormat(-1)) + , m_Data(0) +{ } + CompressedImage::CompressedImage( const CompressedImage &other ) : m_Width(other.m_Width) , m_Height(other.m_Height) diff --git a/Core/src/TexComp.cpp b/Core/src/TexComp.cpp index 6e88e9e..0f47171 100644 --- a/Core/src/TexComp.cpp +++ b/Core/src/TexComp.cpp @@ -17,9 +17,8 @@ static void ReportError(const char *msg) { fprintf(stderr, "TexComp -- %s\n", msg); } -void CompressImage( +CompressedImage * CompressImage( const ImageFile &img, - CompressedImage &outImg, const SCompressionSettings &settings ) { @@ -35,21 +34,25 @@ void CompressImage( if(cmpDataSz == 0) { ReportError("Unknown compression format"); - return; + return NULL; } + CompressedImage *outImg = NULL; unsigned char *cmpData = new unsigned char[cmpDataSz]; CompressionFunc f = ChooseFuncFromSettings(settings); if(f) { (*f)(img.GetPixels(), cmpData, img.GetWidth(), img.GetHeight()); - outImg = CompressedImage(img.GetWidth(), img.GetHeight(), settings.format, cmpData); + outImg = new CompressedImage(img.GetWidth(), img.GetHeight(), settings.format, cmpData); } else { ReportError("Could not find adequate compression function for specified settings"); - // return + delete [] cmpData; + return NULL; } // Cleanup delete [] cmpData; + + return outImg; }