2012-08-26 18:46:47 +00:00
|
|
|
#include "ImageFile.h"
|
2012-08-26 23:05:18 +00:00
|
|
|
#include <string.h>
|
2012-08-26 18:46:47 +00:00
|
|
|
|
2012-08-26 20:37:10 +00:00
|
|
|
ImageFile::ImageFile(const char *filename) :
|
2012-08-26 23:05:18 +00:00
|
|
|
m_PixelData(0),
|
|
|
|
m_FileFormat( DetectFileFormat(filename) )
|
2012-08-26 20:37:10 +00:00
|
|
|
{
|
|
|
|
unsigned char *rawData = ReadFileData(filename);
|
|
|
|
LoadImage(rawData);
|
|
|
|
delete [] rawData;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageFile::ImageFile(const char *filename, EImageFileFormat format) :
|
|
|
|
m_FileFormat(format),
|
|
|
|
m_PixelData(0)
|
|
|
|
{
|
|
|
|
unsigned char *rawData = ReadFileData(filename);
|
|
|
|
LoadImage(rawData);
|
|
|
|
delete [] rawData;
|
2012-08-26 18:46:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ImageFile::~ImageFile() {
|
2012-08-26 20:37:10 +00:00
|
|
|
if(m_PixelData) {
|
|
|
|
delete [] m_PixelData;
|
|
|
|
}
|
2012-08-26 18:46:47 +00:00
|
|
|
}
|
|
|
|
|
2012-08-26 23:05:18 +00:00
|
|
|
EImageFileFormat ImageFile::DetectFileFormat(const char *filename) {
|
2012-08-26 18:46:47 +00:00
|
|
|
|
2012-08-26 23:05:18 +00:00
|
|
|
int len = strlen(filename);
|
|
|
|
if(len >= 256) {
|
|
|
|
// !FIXME! Report Error...
|
|
|
|
return kNumImageFileFormats;
|
|
|
|
}
|
2012-08-26 18:46:47 +00:00
|
|
|
|
2012-08-26 23:05:18 +00:00
|
|
|
int dotPos = len - 1;
|
|
|
|
|
|
|
|
while(dotPos >= 0 && filename[dotPos--] != '.');
|
2012-08-26 18:46:47 +00:00
|
|
|
|
2012-08-26 23:05:18 +00:00
|
|
|
if(dotPos < 0) {
|
|
|
|
// !FIXME! Report Error.....
|
|
|
|
return kNumImageFileFormats;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *ext = &filename[dotPos];
|
|
|
|
|
|
|
|
if(strcmp(ext, ".png") == 0) {
|
|
|
|
return eFileFormat_PNG;
|
|
|
|
}
|
|
|
|
return kNumImageFileFormats;
|
2012-08-26 18:46:47 +00:00
|
|
|
}
|
|
|
|
|
2012-08-26 23:05:18 +00:00
|
|
|
bool ImageFile::LoadImage(const unsigned char *rawImageData) {
|
|
|
|
return false;
|
2012-08-26 18:46:47 +00:00
|
|
|
}
|
|
|
|
|
2012-08-26 20:37:10 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
unsigned char *ImageFile::ReadFileData(const char *filename) {
|
2012-08-26 18:46:47 +00:00
|
|
|
|
|
|
|
}
|
2012-08-26 20:37:10 +00:00
|
|
|
#else
|
|
|
|
unsigned char *ImageFile::ReadFileData(const char *filename) {
|
2012-08-26 18:46:47 +00:00
|
|
|
|
2012-08-26 20:37:10 +00:00
|
|
|
}
|
2012-08-26 18:46:47 +00:00
|
|
|
#endif
|