Add some more skeleton code to prepare for png image loading.

This commit is contained in:
Pavel Krajcevski 2012-08-26 19:05:18 -04:00
parent ff5cab75ee
commit abb5ca2a44
5 changed files with 106 additions and 22 deletions

View file

@ -0,0 +1,14 @@
SET( SOURCES
ImageFile.cpp
)
SET( HEADERS
ImageLoader.h
ImageFile.h
)
ADD_LIBRARY(TexCompIO
${SOURCES}
${HEADERS}
)

View file

@ -1,10 +1,11 @@
#include "ImageFile.h" #include "ImageFile.h"
#include <string.h>
ImageFile::ImageFile(const char *filename) : ImageFile::ImageFile(const char *filename) :
m_PixelData(0) m_PixelData(0),
m_FileFormat( DetectFileFormat(filename) )
{ {
unsigned char *rawData = ReadFileData(filename); unsigned char *rawData = ReadFileData(filename);
DetectFileFormat(filename);
LoadImage(rawData); LoadImage(rawData);
delete [] rawData; delete [] rawData;
} }
@ -24,17 +25,33 @@ ImageFile::~ImageFile() {
} }
} }
void ImageFile::GetPixels() const { EImageFileFormat ImageFile::DetectFileFormat(const char *filename) {
int len = strlen(filename);
if(len >= 256) {
// !FIXME! Report Error...
return kNumImageFileFormats;
}
int dotPos = len - 1;
while(dotPos >= 0 && filename[dotPos--] != '.');
if(dotPos < 0) {
// !FIXME! Report Error.....
return kNumImageFileFormats;
}
const char *ext = &filename[dotPos];
if(strcmp(ext, ".png") == 0) {
return eFileFormat_PNG;
}
return kNumImageFileFormats;
} }
EImageFileFormat ImageFile::DetectFileFormat() { bool ImageFile::LoadImage(const unsigned char *rawImageData) {
} return false;
void ImageFile::LoadImage(const unsigend char *rawImageData) {
}
void ImageFile::LoadPNGImage(const unsigned char *rawImageData) {
} }
#ifdef _MSC_VER #ifdef _MSC_VER

View file

@ -1,11 +1,7 @@
#ifedef _IMAGE_FILE_H_ #ifndef _IMAGE_FILE_H_
#define _IMAGE_FILE_H_ #define _IMAGE_FILE_H_
enum EImageFileFormat { #include "ImageLoader.h"
eFileFormat_PNG,
kNumImageFileFormats
};
class ImageFile { class ImageFile {
@ -15,8 +11,8 @@ public:
ImageFile(const char *filename, EImageFileFormat format); ImageFile(const char *filename, EImageFileFormat format);
~ImageFile(); ~ImageFile();
void GetWidth() const { return m_Width; } unsigned int GetWidth() const { return m_Width; }
void GetHeight() const { return m_Height; } unsigned int GetHeight() const { return m_Height; }
const unsigned char *GetPixels() const { return m_PixelData; } const unsigned char *GetPixels() const { return m_PixelData; }
private: private:
@ -27,11 +23,8 @@ public:
const EImageFileFormat m_FileFormat; const EImageFileFormat m_FileFormat;
static unsigned char *ReadFileData(const char *filename); static unsigned char *ReadFileData(const char *filename);
static EFileFormat DetectFileFormat(const char *filename); static EImageFileFormat DetectFileFormat(const char *filename);
bool LoadImage(const unsigned char *rawImageData); bool LoadImage(const unsigned char *rawImageData);
bool LoadPNGImage(const unsigned char *rawImageData);
}; };
#endif // _IMAGE_FILE_H_ #endif // _IMAGE_FILE_H_

46
IO/ImageLoader.h Normal file
View file

@ -0,0 +1,46 @@
#ifndef _IMAGE_LOADER_H_
#define _IMAGE_LOADER_H_
enum EImageFileFormat {
eFileFormat_PNG,
kNumImageFileFormats
};
class ImageLoader {
protected:
int m_RedChannelPrecision;
unsigned char *m_RedData;
int m_GreenChannelPrecision;
unsigned char *m_GreenData;
int m_BlueChannelPrecision;
unsigned char *m_BlueData;
int m_AlphaChannelPrecision;
unsigned char *m_AlphaData;
const unsigned char *const m_RawData;
ImageLoader(const unsigned char *rawData);
virtual ~ImageLoader();
public:
virtual void ReadData() = 0;
int GetRedChannelPrecision() const { return m_RedChannelPrecision; }
unsigned char * GetRedPixelData() const { return m_RedData; }
int GetGreenChannelPrecision() const { return m_GreenChannelPrecision; }
unsigned char * GetGreenPixelData() const { return m_GreenData; }
int GetBlueChannelPrecision() const { return m_BlueChannelPrecision; }
unsigned char * GetBluePixelData() const { return m_BlueData; }
int GetAlphaChannelPrecision() const { return m_AlphaChannelPrecision; }
unsigned char * GetAlphaPixelData() const { return m_AlphaData; }
};
#endif // _IMAGE_LOADER_H_

14
IO/ImageLoaderPNG.h Normal file
View file

@ -0,0 +1,14 @@
#ifndef _IMAGE_LOADER_PNG_H_
#define _IMAGE_LOADER_PNG_H_
#include "ImageLoader.h"
class ImageLoaderPNG : public ImageLoader {
public:
ImageLoader(const unsigned char *rawData);
virtual ~ImageLoader();
void ReadData();
};
#endif // _IMAGE_LOADER_H_