xoreos  0.0.5
decoder.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef GRAPHICS_IMAGES_DECODER_H
26 #define GRAPHICS_IMAGES_DECODER_H
27 
28 #include <vector>
29 
30 #include <boost/noncopyable.hpp>
31 
32 #include "src/common/types.h"
33 #include "src/common/scopedptr.h"
34 #include "src/common/ptrvector.h"
35 
36 #include "src/graphics/types.h"
37 
39 
40 namespace Common {
41  class SeekableReadStream;
42  class UString;
43 }
44 
45 namespace Graphics {
46 
48 class ImageDecoder : boost::noncopyable {
49 public:
51  struct MipMap {
52  int width;
53  int height;
55 
57 
59 
60  MipMap(const ImageDecoder *i = 0);
61  MipMap(const MipMap &mipMap, const ImageDecoder *i = 0);
62  ~MipMap();
63 
64  void swap(MipMap &right);
65 
67  void getPixel(int x, int y, float &r, float &g, float &b, float &a) const;
69  void getPixel(int n, float &r, float &g, float &b, float &a) const;
70 
72  void setPixel(int x, int y, float r, float g, float b, float a);
74  void setPixel(int n, float r, float g, float b, float a);
75  };
76 
77  ImageDecoder();
78  ImageDecoder(const ImageDecoder &image);
79  virtual ~ImageDecoder();
80 
81  ImageDecoder &operator=(const ImageDecoder &image);
82 
84  bool isCompressed() const;
85 
87  bool hasAlpha() const;
88 
90  PixelFormat getFormat() const;
94  PixelDataType getDataType() const;
95 
97  size_t getMipMapCount() const;
99  size_t getLayerCount() const;
100 
102  bool isCubeMap() const;
103 
105  const MipMap &getMipMap(size_t mipMap, size_t layer = 0) const;
106 
108  void decompress();
109 
111  const TXI &getTXI() const;
112 
114  bool dumpTGA(const Common::UString &fileName) const;
115 
116 protected:
118 
120  bool _hasAlpha;
121 
125 
127  size_t _layerCount;
130 
132 
134 
135  static void decompress(MipMap &out, const MipMap &in, PixelFormatRaw format);
136 };
137 
138 } // End of namespace Graphics
139 
140 #endif // GRAPHICS_IMAGES_DECODER_H
PixelFormat getFormat() const
Return the image data&#39;s general format.
Definition: decoder.cpp:176
Definition: 2dafile.h:39
void getPixel(int x, int y, float &r, float &g, float &b, float &a) const
Get the color values of the pixel at this position.
Definition: decoder.cpp:64
A class holding an UTF-8 string.
Definition: ustring.h:48
MipMap(const ImageDecoder *i=0)
Definition: decoder.cpp:41
Common::ScopedArray< byte > data
The mip map&#39;s data.
Definition: decoder.h:56
bool _isCubeMap
Is this image a cube map? A cube map always needs to have 6 layers!
Definition: decoder.h:129
const TXI & getTXI() const
Return the texture information TXI, which may be embedded in the image.
Definition: decoder.cpp:164
PixelDataType
Definition: types.h:65
Basic graphics types.
PixelFormatRaw
Definition: types.h:55
bool isCubeMap() const
Is this image a cube map?
Definition: decoder.cpp:198
PixelDataType _dataType
Definition: decoder.h:124
size_t getLayerCount() const
Return the number of layers contained in the image.
Definition: decoder.cpp:194
int height
The mip map&#39;s height.
Definition: decoder.h:53
A simple scoped smart pointer template.
void decompress()
Manually decompress the texture image data.
Definition: decoder.cpp:242
bool dumpTGA(const Common::UString &fileName) const
Dump the image into a TGA.
Definition: decoder.cpp:260
virtual ~ImageDecoder()
Definition: decoder.cpp:139
void swap(MipMap &right)
Definition: decoder.cpp:55
PixelFormat _format
Definition: decoder.h:122
void setPixel(int x, int y, float r, float g, float b, float a)
Set the color values of the pixel at this position.
Definition: decoder.cpp:97
size_t _layerCount
Number of layers in this image.
Definition: decoder.h:127
PixelFormatRaw getFormatRaw() const
Return the image data&#39;s raw format.
Definition: decoder.cpp:180
PixelFormatRaw _formatRaw
Definition: decoder.h:123
const MipMap & getMipMap(size_t mipMap, size_t layer=0) const
Return a mip map.
Definition: decoder.cpp:204
Low-level type definitions to handle fixed width types portably.
Texture information.
A vector storing pointer to objects, with automatic deletion.
const ImageDecoder * image
The image the mip map belongs to.
Definition: decoder.h:58
PixelDataType getDataType() const
Return the image data pixel&#39;s type.
Definition: decoder.cpp:184
int width
The mip map&#39;s width.
Definition: decoder.h:52
ImageDecoder & operator=(const ImageDecoder &image)
Definition: decoder.cpp:142
uint32_t uint32
Definition: types.h:204
Texture information.
Definition: txi.h:40
Common::PtrVector< MipMap > MipMaps
Definition: decoder.h:117
A generic interface for image decoders.
Definition: decoder.h:48
PixelFormat
Definition: types.h:48
size_t getMipMapCount() const
Return the number of mip maps contained in the image.
Definition: decoder.cpp:188
uint32 size
The mip map&#39;s size in bytes.
Definition: decoder.h:54
bool hasAlpha() const
Does the image data have alpha? .
Definition: decoder.cpp:172
bool isCompressed() const
Is the image data compressed?
Definition: decoder.cpp:168