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
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
16
#ifndef __C_IMAGE_LOADER_RGB_H_INCLUDED__
17
#define __C_IMAGE_LOADER_RGB_H_INCLUDED__
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_
23
#include "IrrCompileConfig.h"
25
#ifdef _IRR_COMPILE_WITH_RGB_LOADER_
27
#include "IImageLoader.h"
34
// byte-align structures
35
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
36
# pragma pack( push, packing )
39
#elif defined( __GNUC__ )
40
# define PACK_STRUCT __attribute__((packed))
42
# error compiler not supported
45
// the RGB image file header structure
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
65
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
66
# pragma pack( pop, packing )
71
// this structure holds context specific data about the file being loaded.
73
typedef struct _RGBdata
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
86
SRGBHeader Header; // define the .rgb file header
91
_RGBdata() : tmp(0), tmpR(0), tmpG(0), tmpB(0), tmpA(0),
92
StartTable(0), LengthTable(0), TableLen(0), ImageSize(0), rgbData(0)
103
delete [] StartTable;
104
delete [] LengthTable;
110
tmp = tmpR = tmpG = tmpB = tmpA = 0;
111
tmp = new u8 [Header.Xsize * 256 * Header.BPC];
115
if (Header.Zsize >= 1)
117
if ( !(tmpR = new u8 [Header.Xsize * Header.BPC]) )
120
if (Header.Zsize >= 2)
122
if ( !(tmpG = new u8 [Header.Xsize * Header.BPC]) )
125
if (Header.Zsize >= 3)
127
if ( !(tmpB = new u8 [Header.Xsize * Header.BPC]) )
130
if (Header.Zsize >= 4)
132
if ( !(tmpA = new u8 [Header.Xsize * Header.BPC]) )
140
//! Surface Loader for Silicon Graphics RGB files
141
class CImageLoaderRGB : public IImageLoader
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;
152
//! returns true if the file maybe is able to be loaded by this class
153
virtual bool isALoadableFileFormat(io::IReadFile* file) const;
155
//! creates a surface from the file
156
virtual IImage* loadImage(io::IReadFile* file) const;
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;
168
} // end namespace video
169
} // end namespace irr
171
#endif // _IRR_COMPILE_WITH_RGB_LOADER_
172
#endif // __C_IMAGE_LOADER_RGB_H_INCLUDED__