1 // Copyright (C) 2009-2012 Gary Conway
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
7 Author: Gary Conway (Viper) - co-author of the ZIP file format, Feb 1989,
\r
8 see the story at http://www.idcnet.us/ziphistory.html
\r
9 Website: http://idcnet.us
\r
10 Email: codeslinger@vipergc.com
\r
11 Created: March 1, 2009
\r
16 #ifndef __C_IMAGE_LOADER_RGB_H_INCLUDED__
\r
17 #define __C_IMAGE_LOADER_RGB_H_INCLUDED__
\r
19 // define _IRR_RGB_FILE_INVERTED_IMAGE_ to preserve the inverted format of the RGB file
\r
20 // commenting this out will invert the inverted image,resulting in the image being upright
\r
21 #define _IRR_RGB_FILE_INVERTED_IMAGE_
\r
23 #include "IrrCompileConfig.h"
\r
25 #ifdef _IRR_COMPILE_WITH_RGB_LOADER_
\r
27 #include "IImageLoader.h"
\r
34 // byte-align structures
\r
35 #include "irrpack.h"
\r
37 // the RGB image file header structure
\r
41 u16 Magic; // IRIS image file magic number
\r
42 u8 Storage; // Storage format
\r
43 u8 BPC; // Number of bytes per pixel channel
\r
44 u16 Dimension; // Number of dimensions
\r
45 u16 Xsize; // X size in pixels
\r
46 u16 Ysize; // Y size in pixels
\r
47 u16 Zsize; // Z size in pixels
\r
48 u32 Pixmin; // Minimum pixel value
\r
49 u32 Pixmax; // Maximum pixel value
\r
50 u32 Dummy1; // ignored
\r
51 char Imagename[80];// Image name
\r
52 u32 Colormap; // Colormap ID
\r
53 // char Dummy2[404];// Ignored
\r
56 // Default alignment
\r
57 #include "irrunpack.h"
\r
59 // this structure holds context specific data about the file being loaded.
\r
61 typedef struct _RGBdata
\r
69 u32 *StartTable; // compressed data table, holds file offsets
\r
70 u32 *LengthTable; // length for the above data, hold lengths for above
\r
71 u32 TableLen; // len of above tables
\r
73 SRGBHeader Header; // define the .rgb file header
\r
78 _RGBdata() : tmp(0), tmpR(0), tmpG(0), tmpB(0), tmpA(0),
\r
79 StartTable(0), LengthTable(0), TableLen(0), ImageSize(0), rgbData(0)
\r
90 delete [] StartTable;
\r
91 delete [] LengthTable;
\r
95 bool allocateTemps()
\r
97 tmp = tmpR = tmpG = tmpB = tmpA = 0;
\r
98 tmp = new u8 [Header.Xsize * 256 * Header.BPC];
\r
102 if (Header.Zsize >= 1)
\r
104 tmpR = new u8[Header.Xsize * Header.BPC];
\r
108 if (Header.Zsize >= 2)
\r
110 tmpG = new u8[Header.Xsize * Header.BPC];
\r
114 if (Header.Zsize >= 3)
\r
116 tmpB = new u8[Header.Xsize * Header.BPC];
\r
120 if (Header.Zsize >= 4)
\r
122 tmpA = new u8[Header.Xsize * Header.BPC];
\r
131 //! Surface Loader for Silicon Graphics RGB files
\r
132 class CImageLoaderRGB : public IImageLoader
\r
139 //! returns true if the file maybe is able to be loaded by this class
\r
140 //! based on the file extension (e.g. ".tga")
\r
141 virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_;
\r
143 //! returns true if the file maybe is able to be loaded by this class
\r
144 virtual bool isALoadableFileFormat(io::IReadFile* file) const _IRR_OVERRIDE_;
\r
146 //! creates a surface from the file
\r
147 virtual IImage* loadImage(io::IReadFile* file) const _IRR_OVERRIDE_;
\r
151 bool readHeader(io::IReadFile* file, rgbStruct& rgb) const;
\r
152 void readRGBrow(u8 *buf, int y, int z, io::IReadFile* file, rgbStruct& rgb) const;
\r
153 void processFile(io::IReadFile *file, rgbStruct& rgb) const;
\r
154 bool checkFormat(io::IReadFile *file, rgbStruct& rgb) const;
\r
155 bool readOffsetTables(io::IReadFile* file, rgbStruct& rgb) const;
\r
156 void converttoARGB(u32* in, const u32 size) const;
\r
159 } // end namespace video
\r
160 } // end namespace irr
\r
162 #endif // _IRR_COMPILE_WITH_RGB_LOADER_
\r
163 #endif // __C_IMAGE_LOADER_RGB_H_INCLUDED__
\r