diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/irrlicht-1.8.1/source/Irrlicht/CImageLoaderRGB.h | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8.1/source/Irrlicht/CImageLoaderRGB.h b/libraries/irrlicht-1.8.1/source/Irrlicht/CImageLoaderRGB.h new file mode 100644 index 0000000..1fe6454 --- /dev/null +++ b/libraries/irrlicht-1.8.1/source/Irrlicht/CImageLoaderRGB.h | |||
@@ -0,0 +1,165 @@ | |||
1 | // Copyright (C) 2009-2012 Gary Conway | ||
2 | // This file is part of the "Irrlicht Engine". | ||
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h | ||
4 | |||
5 | |||
6 | /* | ||
7 | Author: Gary Conway (Viper) - co-author of the ZIP file format, Feb 1989, | ||
8 | see the story at http://www.idcnet.us/ziphistory.html | ||
9 | Website: http://idcnet.us | ||
10 | Email: codeslinger@vipergc.com | ||
11 | Created: March 1, 2009 | ||
12 | Version: 1.0 | ||
13 | Updated: | ||
14 | */ | ||
15 | |||
16 | #ifndef __C_IMAGE_LOADER_RGB_H_INCLUDED__ | ||
17 | #define __C_IMAGE_LOADER_RGB_H_INCLUDED__ | ||
18 | |||
19 | // define _IRR_RGB_FILE_INVERTED_IMAGE_ to preserve the inverted format of the RGB file | ||
20 | // commenting this out will invert the inverted image,resulting in the image being upright | ||
21 | #define _IRR_RGB_FILE_INVERTED_IMAGE_ | ||
22 | |||
23 | #include "IrrCompileConfig.h" | ||
24 | |||
25 | #ifdef _IRR_COMPILE_WITH_RGB_LOADER_ | ||
26 | |||
27 | #include "IImageLoader.h" | ||
28 | |||
29 | namespace irr | ||
30 | { | ||
31 | namespace video | ||
32 | { | ||
33 | |||
34 | // byte-align structures | ||
35 | #include "irrpack.h" | ||
36 | |||
37 | // the RGB image file header structure | ||
38 | |||
39 | struct SRGBHeader | ||
40 | { | ||
41 | u16 Magic; // IRIS image file magic number | ||
42 | u8 Storage; // Storage format | ||
43 | u8 BPC; // Number of bytes per pixel channel | ||
44 | u16 Dimension; // Number of dimensions | ||
45 | u16 Xsize; // X size in pixels | ||
46 | u16 Ysize; // Y size in pixels | ||
47 | u16 Zsize; // Z size in pixels | ||
48 | u32 Pixmin; // Minimum pixel value | ||
49 | u32 Pixmax; // Maximum pixel value | ||
50 | u32 Dummy1; // ignored | ||
51 | char Imagename[80];// Image name | ||
52 | u32 Colormap; // Colormap ID | ||
53 | // char Dummy2[404];// Ignored | ||
54 | } PACK_STRUCT; | ||
55 | |||
56 | // Default alignment | ||
57 | #include "irrunpack.h" | ||
58 | |||
59 | // this structure holds context specific data about the file being loaded. | ||
60 | |||
61 | typedef struct _RGBdata | ||
62 | { | ||
63 | u8 *tmp, | ||
64 | *tmpR, | ||
65 | *tmpG, | ||
66 | *tmpB, | ||
67 | *tmpA; | ||
68 | |||
69 | |||
70 | u32 *StartTable; // compressed data table, holds file offsets | ||
71 | u32 *LengthTable; // length for the above data, hold lengths for above | ||
72 | u32 TableLen; // len of above tables | ||
73 | |||
74 | SRGBHeader Header; // define the .rgb file header | ||
75 | u32 ImageSize; | ||
76 | u8 *rgbData; | ||
77 | |||
78 | public: | ||
79 | _RGBdata() : tmp(0), tmpR(0), tmpG(0), tmpB(0), tmpA(0), | ||
80 | StartTable(0), LengthTable(0), TableLen(0), ImageSize(0), rgbData(0) | ||
81 | { | ||
82 | } | ||
83 | |||
84 | ~_RGBdata() | ||
85 | { | ||
86 | delete [] tmp; | ||
87 | delete [] tmpR; | ||
88 | delete [] tmpG; | ||
89 | delete [] tmpB; | ||
90 | delete [] tmpA; | ||
91 | delete [] StartTable; | ||
92 | delete [] LengthTable; | ||
93 | delete [] rgbData; | ||
94 | } | ||
95 | |||
96 | bool allocateTemps() | ||
97 | { | ||
98 | tmp = tmpR = tmpG = tmpB = tmpA = 0; | ||
99 | tmp = new u8 [Header.Xsize * 256 * Header.BPC]; | ||
100 | if (!tmp) | ||
101 | return false; | ||
102 | |||
103 | if (Header.Zsize >= 1) | ||
104 | { | ||
105 | tmpR = new u8[Header.Xsize * Header.BPC]; | ||
106 | if (!tmpR) | ||
107 | return false; | ||
108 | } | ||
109 | if (Header.Zsize >= 2) | ||
110 | { | ||
111 | tmpG = new u8[Header.Xsize * Header.BPC]; | ||
112 | if (!tmpG) | ||
113 | return false; | ||
114 | } | ||
115 | if (Header.Zsize >= 3) | ||
116 | { | ||
117 | tmpB = new u8[Header.Xsize * Header.BPC]; | ||
118 | if (!tmpB) | ||
119 | return false; | ||
120 | } | ||
121 | if (Header.Zsize >= 4) | ||
122 | { | ||
123 | tmpA = new u8[Header.Xsize * Header.BPC]; | ||
124 | if (!tmpA) | ||
125 | return false; | ||
126 | } | ||
127 | return true; | ||
128 | } | ||
129 | } rgbStruct; | ||
130 | |||
131 | |||
132 | //! Surface Loader for Silicon Graphics RGB files | ||
133 | class CImageLoaderRGB : public IImageLoader | ||
134 | { | ||
135 | public: | ||
136 | |||
137 | //! constructor | ||
138 | CImageLoaderRGB(); | ||
139 | |||
140 | //! returns true if the file maybe is able to be loaded by this class | ||
141 | //! based on the file extension (e.g. ".tga") | ||
142 | virtual bool isALoadableFileExtension(const io::path& filename) const; | ||
143 | |||
144 | //! returns true if the file maybe is able to be loaded by this class | ||
145 | virtual bool isALoadableFileFormat(io::IReadFile* file) const; | ||
146 | |||
147 | //! creates a surface from the file | ||
148 | virtual IImage* loadImage(io::IReadFile* file) const; | ||
149 | |||
150 | private: | ||
151 | |||
152 | bool readHeader(io::IReadFile* file, rgbStruct& rgb) const; | ||
153 | void readRGBrow(u8 *buf, int y, int z, io::IReadFile* file, rgbStruct& rgb) const; | ||
154 | void processFile(io::IReadFile *file, rgbStruct& rgb) const; | ||
155 | bool checkFormat(io::IReadFile *file, rgbStruct& rgb) const; | ||
156 | bool readOffsetTables(io::IReadFile* file, rgbStruct& rgb) const; | ||
157 | void converttoARGB(u32* in, const u32 size) const; | ||
158 | }; | ||
159 | |||
160 | } // end namespace video | ||
161 | } // end namespace irr | ||
162 | |||
163 | #endif // _IRR_COMPILE_WITH_RGB_LOADER_ | ||
164 | #endif // __C_IMAGE_LOADER_RGB_H_INCLUDED__ | ||
165 | |||