Start working on command line tool -- Currently just making sure that everything builds and links. Also rearranged some function definitions to better accomodate this.

This commit is contained in:
Pavel Krajcevski 2012-08-27 22:49:00 -04:00
parent cff862344f
commit 9e625a4065
8 changed files with 61 additions and 7 deletions

View File

@ -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 )

21
CLTool/src/clunix.cpp Normal file
View File

@ -0,0 +1,21 @@
#include <stdlib.h>
#include <stdio.h>
#include "TexComp.h"
int main(int argc, char **argv) {
if(argc != 2) {
fprintf(stderr, "Usage: %s <imagefile>\n", argv[0]);
exit(1);
}
ImageFile file (argv[1]);
SCompressionSettings settings;
CompressedImage *ci = CompressImage(file, settings);
// Cleanup
delete ci;
return 0;
}

3
CLTool/src/clwin32.cpp Normal file
View File

@ -0,0 +1,3 @@
int main(int argc, char **argv) {
}

View File

@ -4,3 +4,5 @@ PROJECT(TexC)
ADD_SUBDIRECTORY(BPTCEncoder)
ADD_SUBDIRECTORY(IO)
ADD_SUBDIRECTORY(Core)
ADD_SUBDIRECTORY(CLTool)

View File

@ -20,6 +20,7 @@ class CompressedImage {
void InitData(const unsigned char *withData);
public:
CompressedImage();
CompressedImage(
const unsigned int width,
const unsigned int height,

View File

@ -11,9 +11,8 @@ struct SCompressionSettings {
int iNumThreads;
};
extern void CompressImage(
extern CompressedImage * CompressImage(
const ImageFile &,
CompressedImage &,
const SCompressionSettings &settings
);

View File

@ -3,6 +3,13 @@
#include <string.h>
#include <stdlib.h>
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)

View File

@ -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;
}