]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CImageLoaderRGB.h
Merging r5975 through r6036 from trunk to ogl-es branch.
[irrlicht.git] / source / Irrlicht / CImageLoaderRGB.h
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
4 \r
5 \r
6 /*\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
12         Version:        1.0\r
13         Updated:\r
14 */\r
15 \r
16 #ifndef __C_IMAGE_LOADER_RGB_H_INCLUDED__\r
17 #define __C_IMAGE_LOADER_RGB_H_INCLUDED__\r
18 \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
22 \r
23 #include "IrrCompileConfig.h"\r
24 \r
25 #ifdef _IRR_COMPILE_WITH_RGB_LOADER_\r
26 \r
27 #include "IImageLoader.h"\r
28 \r
29 namespace irr\r
30 {\r
31 namespace video\r
32 {\r
33 \r
34 // byte-align structures\r
35 #include "irrpack.h"\r
36 \r
37         // the RGB image file header structure\r
38 \r
39         struct SRGBHeader\r
40         {\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
54         } PACK_STRUCT;\r
55 \r
56 // Default alignment\r
57 #include "irrunpack.h"\r
58 \r
59         // this structure holds context specific data about the file being loaded.\r
60 \r
61         typedef struct _RGBdata\r
62         {\r
63                 u8 *tmp;\r
64                 u8 *tmpR;\r
65                 u8 *tmpG;\r
66                 u8 *tmpB;\r
67                 u8 *tmpA;\r
68 \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
72 \r
73                 SRGBHeader Header;      // define the .rgb file header\r
74                 u32 ImageSize;\r
75                 u8 *rgbData;\r
76 \r
77         public:\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
80                 {\r
81                 }\r
82 \r
83                 ~_RGBdata()\r
84                 {\r
85                         delete [] tmp;\r
86                         delete [] tmpR;\r
87                         delete [] tmpG;\r
88                         delete [] tmpB;\r
89                         delete [] tmpA;\r
90                         delete [] StartTable;\r
91                         delete [] LengthTable;\r
92                         delete [] rgbData;\r
93                 }\r
94 \r
95                 bool allocateTemps()\r
96                 {\r
97                         tmp = tmpR = tmpG = tmpB = tmpA = 0;\r
98                         tmp = new u8 [Header.Xsize * 256 * Header.BPC];\r
99                         if (!tmp)\r
100                                 return false;\r
101 \r
102                         if (Header.Zsize >= 1)\r
103                         {\r
104                                 tmpR = new u8[Header.Xsize * Header.BPC];\r
105                                 if (!tmpR)\r
106                                         return false;\r
107                         }\r
108                         if (Header.Zsize >= 2)\r
109                         {\r
110                                 tmpG = new u8[Header.Xsize * Header.BPC];\r
111                                 if (!tmpG)\r
112                                         return false;\r
113                         }\r
114                         if (Header.Zsize >= 3)\r
115                         {\r
116                                 tmpB = new u8[Header.Xsize * Header.BPC];\r
117                                 if (!tmpB)\r
118                                         return false;\r
119                         }\r
120                         if (Header.Zsize >= 4)\r
121                         {\r
122                                 tmpA = new u8[Header.Xsize * Header.BPC];\r
123                                 if (!tmpA)\r
124                                         return false;\r
125                         }\r
126                         return true;\r
127                 }\r
128         } rgbStruct;\r
129 \r
130 \r
131 //! Surface Loader for Silicon Graphics RGB files\r
132 class CImageLoaderRGB : public IImageLoader\r
133 {\r
134 public:\r
135 \r
136         //! constructor\r
137         CImageLoaderRGB();\r
138 \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
142 \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
145 \r
146         //! creates a surface from the file\r
147         virtual IImage* loadImage(io::IReadFile* file) const _IRR_OVERRIDE_;\r
148 \r
149 private:\r
150 \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
157 };\r
158 \r
159 } // end namespace video\r
160 } // end namespace irr\r
161 \r
162 #endif // _IRR_COMPILE_WITH_RGB_LOADER_\r
163 #endif // __C_IMAGE_LOADER_RGB_H_INCLUDED__\r
164 \r