From abb5ca2a446f78e9b0844d3d9078dd51e38afc04 Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Sun, 26 Aug 2012 19:05:18 -0400 Subject: [PATCH] Add some more skeleton code to prepare for png image loading. --- IO/CMakeLists.txt | 14 ++++++++++++++ IO/ImageFile.cpp | 37 ++++++++++++++++++++++++++---------- IO/ImageFile.h | 17 +++++------------ IO/ImageLoader.h | 46 +++++++++++++++++++++++++++++++++++++++++++++ IO/ImageLoaderPNG.h | 14 ++++++++++++++ 5 files changed, 106 insertions(+), 22 deletions(-) create mode 100644 IO/ImageLoader.h create mode 100644 IO/ImageLoaderPNG.h diff --git a/IO/CMakeLists.txt b/IO/CMakeLists.txt index e69de29..c460015 100644 --- a/IO/CMakeLists.txt +++ b/IO/CMakeLists.txt @@ -0,0 +1,14 @@ + +SET( SOURCES + ImageFile.cpp +) + +SET( HEADERS + ImageLoader.h + ImageFile.h +) + +ADD_LIBRARY(TexCompIO + ${SOURCES} + ${HEADERS} +) diff --git a/IO/ImageFile.cpp b/IO/ImageFile.cpp index fd26238..00ee9a4 100644 --- a/IO/ImageFile.cpp +++ b/IO/ImageFile.cpp @@ -1,10 +1,11 @@ #include "ImageFile.h" +#include ImageFile::ImageFile(const char *filename) : - m_PixelData(0) + m_PixelData(0), + m_FileFormat( DetectFileFormat(filename) ) { unsigned char *rawData = ReadFileData(filename); - DetectFileFormat(filename); LoadImage(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() { -} - -void ImageFile::LoadImage(const unsigend char *rawImageData) { -} - -void ImageFile::LoadPNGImage(const unsigned char *rawImageData) { +bool ImageFile::LoadImage(const unsigned char *rawImageData) { + return false; } #ifdef _MSC_VER diff --git a/IO/ImageFile.h b/IO/ImageFile.h index f01f879..34d6593 100644 --- a/IO/ImageFile.h +++ b/IO/ImageFile.h @@ -1,11 +1,7 @@ -#ifedef _IMAGE_FILE_H_ +#ifndef _IMAGE_FILE_H_ #define _IMAGE_FILE_H_ -enum EImageFileFormat { - eFileFormat_PNG, - - kNumImageFileFormats -}; +#include "ImageLoader.h" class ImageFile { @@ -15,8 +11,8 @@ public: ImageFile(const char *filename, EImageFileFormat format); ~ImageFile(); - void GetWidth() const { return m_Width; } - void GetHeight() const { return m_Height; } + unsigned int GetWidth() const { return m_Width; } + unsigned int GetHeight() const { return m_Height; } const unsigned char *GetPixels() const { return m_PixelData; } private: @@ -27,11 +23,8 @@ public: const EImageFileFormat m_FileFormat; 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 LoadPNGImage(const unsigned char *rawImageData); }; - - #endif // _IMAGE_FILE_H_ diff --git a/IO/ImageLoader.h b/IO/ImageLoader.h new file mode 100644 index 0000000..4ce6473 --- /dev/null +++ b/IO/ImageLoader.h @@ -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_ diff --git a/IO/ImageLoaderPNG.h b/IO/ImageLoaderPNG.h new file mode 100644 index 0000000..d2bf7cf --- /dev/null +++ b/IO/ImageLoaderPNG.h @@ -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_