~baltix/+junk/irrlicht-test

« back to all changes in this revision

Viewing changes to source/Irrlicht/CImageLoaderRGB.h

  • Committer: Mantas Kriaučiūnas
  • Date: 2011-07-18 13:06:25 UTC
  • Revision ID: mantas@akl.lt-20110718130625-c5pvifp61e7kj1ol
Included whole irrlicht SVN libraries to work around launchpad recipe issue with quilt, see https://answers.launchpad.net/launchpad/+question/165193

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2009-2011 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
#if defined(_MSC_VER) ||  defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
 
36
#       pragma pack( push, packing )
 
37
#       pragma pack( 1 )
 
38
#       define PACK_STRUCT
 
39
#elif defined( __GNUC__ )
 
40
#       define PACK_STRUCT      __attribute__((packed))
 
41
#else
 
42
#       error compiler not supported
 
43
#endif
 
44
 
 
45
        // the RGB image file header structure
 
46
 
 
47
        struct SRGBHeader
 
48
        {
 
49
                u16     Magic;                                                  // IRIS image file magic number
 
50
                u8  Storage;                                            // Storage format
 
51
                u8  BPC;                                                        // Number of bytes per pixel channel
 
52
                u16 Dimension;                                          // Number of dimensions
 
53
                u16 Xsize;                                                      // X size in pixels
 
54
                u16 Ysize;                                                      // Y size in pixels
 
55
                u16 Zsize;                                                      // Z size in pixels
 
56
                u32 Pixmin;                                                     // Minimum pixel value
 
57
                u32 Pixmax;                                                     // Maximum pixel value
 
58
                u32 Dummy1;                                                     // ignored
 
59
                char Imagename[80];                                     // Image name
 
60
                u32 Colormap;                                           // Colormap ID
 
61
//              char Dummy2[404];                                       // Ignored
 
62
        } PACK_STRUCT;
 
63
 
 
64
// Default alignment
 
65
#if defined(_MSC_VER) ||  defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
 
66
#       pragma pack( pop, packing )
 
67
#endif
 
68
 
 
69
#undef PACK_STRUCT
 
70
 
 
71
        // this structure holds context specific data about the file being loaded.
 
72
 
 
73
        typedef struct _RGBdata
 
74
        {
 
75
                u8 *tmp,
 
76
                   *tmpR,
 
77
                   *tmpG,
 
78
                   *tmpB,
 
79
                   *tmpA;
 
80
 
 
81
 
 
82
                u32 *StartTable;        // compressed data table, holds file offsets
 
83
                u32 *LengthTable;       // length for the above data, hold lengths for above
 
84
                u32 TableLen;           // len of above tables
 
85
 
 
86
                SRGBHeader Header;      // define the .rgb file header
 
87
                u32 ImageSize;
 
88
                u8 *rgbData;
 
89
 
 
90
        public:
 
91
                _RGBdata() : tmp(0), tmpR(0), tmpG(0), tmpB(0), tmpA(0),
 
92
                        StartTable(0), LengthTable(0), TableLen(0), ImageSize(0), rgbData(0)
 
93
                {
 
94
                }
 
95
 
 
96
                ~_RGBdata()
 
97
                {
 
98
                        delete [] tmp;
 
99
                        delete [] tmpR;
 
100
                        delete [] tmpG;
 
101
                        delete [] tmpB;
 
102
                        delete [] tmpA;
 
103
                        delete [] StartTable;
 
104
                        delete [] LengthTable;
 
105
                        delete [] rgbData;
 
106
                }
 
107
 
 
108
                bool allocateTemps()
 
109
                {
 
110
                        tmp = tmpR = tmpG = tmpB = tmpA = 0;
 
111
                        tmp = new u8 [Header.Xsize * 256 * Header.BPC];
 
112
                        if (!tmp)
 
113
                                return false;
 
114
 
 
115
                        if (Header.Zsize >= 1)
 
116
                        {
 
117
                                if ( !(tmpR = new u8 [Header.Xsize * Header.BPC]) )
 
118
                                        return false;
 
119
                        }
 
120
                        if (Header.Zsize >= 2)
 
121
                        {
 
122
                                if ( !(tmpG = new u8 [Header.Xsize * Header.BPC]) )
 
123
                                        return false;
 
124
                        }
 
125
                        if (Header.Zsize >= 3)
 
126
                        {
 
127
                                if ( !(tmpB = new u8 [Header.Xsize * Header.BPC]) )
 
128
                                        return false;
 
129
                        }
 
130
                        if (Header.Zsize >= 4)
 
131
                        {
 
132
                                if ( !(tmpA = new u8 [Header.Xsize * Header.BPC]) )
 
133
                                        return false;
 
134
                        }
 
135
                        return true;
 
136
                }
 
137
        } rgbStruct;
 
138
 
 
139
 
 
140
//! Surface Loader for Silicon Graphics RGB files
 
141
class CImageLoaderRGB : public IImageLoader
 
142
{
 
143
public:
 
144
 
 
145
        //! constructor
 
146
        CImageLoaderRGB();
 
147
 
 
148
        //! returns true if the file maybe is able to be loaded by this class
 
149
        //! based on the file extension (e.g. ".tga")
 
150
        virtual bool isALoadableFileExtension(const io::path& filename) const;
 
151
 
 
152
        //! returns true if the file maybe is able to be loaded by this class
 
153
        virtual bool isALoadableFileFormat(io::IReadFile* file) const;
 
154
 
 
155
        //! creates a surface from the file
 
156
        virtual IImage* loadImage(io::IReadFile* file) const;
 
157
 
 
158
private:
 
159
 
 
160
        bool readHeader(io::IReadFile* file, rgbStruct& rgb) const;
 
161
        void readRGBrow(u8 *buf, int y, int z, io::IReadFile* file, rgbStruct& rgb) const;
 
162
        void processFile(io::IReadFile *file, rgbStruct& rgb) const;
 
163
        bool checkFormat(io::IReadFile *file, rgbStruct& rgb) const;
 
164
        bool readOffsetTables(io::IReadFile* file, rgbStruct& rgb) const;
 
165
        void converttoARGB(u32* in, const u32 size) const;
 
166
};
 
167
 
 
168
} // end namespace video
 
169
} // end namespace irr
 
170
 
 
171
#endif // _IRR_COMPILE_WITH_RGB_LOADER_
 
172
#endif // __C_IMAGE_LOADER_RGB_H_INCLUDED__