#ifndef __C_IMAGE_LOADER_RGB_H_INCLUDED__
#define __C_IMAGE_LOADER_RGB_H_INCLUDED__
#define _IRR_RGB_FILE_INVERTED_IMAGE_
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_RGB_LOADER_
#include "IImageLoader.h"
namespace irr
{
namespace video
{
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
# pragma pack( push, packing )
# pragma pack( 1 )
# define PACK_STRUCT
#elif defined( __GNUC__ )
# define PACK_STRUCT __attribute__((packed))
#else
# error compiler not supported
#endif
struct SRGBHeader
{
u16 Magic;
u8 Storage;
u8 BPC;
u16 Dimension;
u16 Xsize;
u16 Ysize;
u16 Zsize;
u32 Pixmin;
u32 Pixmax;
u32 Dummy1;
char Imagename[80];
u32 Colormap;
} PACK_STRUCT;
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
# pragma pack( pop, packing )
#endif
#undef PACK_STRUCT
typedef struct _RGBdata
{
u8 *tmp,
*tmpR,
*tmpG,
*tmpB,
*tmpA;
u32 *StartTable;
u32 *LengthTable;
u32 TableLen;
SRGBHeader Header;
u32 ImageSize;
u8 *rgbData;
public:
_RGBdata() : tmp(0), tmpR(0), tmpG(0), tmpB(0), tmpA(0),
StartTable(0), LengthTable(0), TableLen(0), ImageSize(0), rgbData(0)
{
}
~_RGBdata()
{
delete [] tmp;
delete [] tmpR;
delete [] tmpG;
delete [] tmpB;
delete [] tmpA;
delete [] StartTable;
delete [] LengthTable;
delete [] rgbData;
}
bool allocateTemps()
{
tmp = tmpR = tmpG = tmpB = tmpA = 0;
tmp = new u8 [Header.Xsize * 256 * Header.BPC];
if (!tmp)
return false;
if (Header.Zsize >= 1)
{
if ( !(tmpR = new u8 [Header.Xsize * Header.BPC]) )
return false;
}
if (Header.Zsize >= 2)
{
if ( !(tmpG = new u8 [Header.Xsize * Header.BPC]) )
return false;
}
if (Header.Zsize >= 3)
{
if ( !(tmpB = new u8 [Header.Xsize * Header.BPC]) )
return false;
}
if (Header.Zsize >= 4)
{
if ( !(tmpA = new u8 [Header.Xsize * Header.BPC]) )
return false;
}
return true;
}
} rgbStruct;
class CImageLoaderRGB : public IImageLoader
{
public:
CImageLoaderRGB();
virtual bool isALoadableFileExtension(const io::path& filename) const;
virtual bool isALoadableFileFormat(io::IReadFile* file) const;
virtual IImage* loadImage(io::IReadFile* file) const;
private:
bool readHeader(io::IReadFile* file, rgbStruct& rgb) const;
void readRGBrow(u8 *buf, int y, int z, io::IReadFile* file, rgbStruct& rgb) const;
void processFile(io::IReadFile *file, rgbStruct& rgb) const;
bool checkFormat(io::IReadFile *file, rgbStruct& rgb) const;
bool readOffsetTables(io::IReadFile* file, rgbStruct& rgb) const;
void converttoARGB(u32* in, const u32 size) const;
};
}
}
#endif
#endif