ScummVM API documentation
tga.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /* Based on code from eos https://github.com/DrMcCoy/xoreos/
23  * relicensed under GPLv2+ with permission from DrMcCoy and clone2727
24  */
25 
26 /*
27  * TGA decoder used in engines:
28  * - titanic
29  * - wintermute
30  * - zvision
31  */
32 
33 #ifndef IMAGE_TGA_H
34 #define IMAGE_TGA_H
35 
36 #include "graphics/surface.h"
37 #include "image/image_decoder.h"
38 
39 namespace Common {
40 class SeekableReadStream;
41 }
42 
43 namespace Image {
44 
65 class TGADecoder : public ImageDecoder {
66 public:
67  TGADecoder();
68  virtual ~TGADecoder();
69  virtual void destroy();
70  virtual const Graphics::Surface *getSurface() const { return &_surface; }
71  virtual const byte *getPalette() const { return _colorMap; }
72  virtual uint16 getPaletteColorCount() const { return _colorMapLength; }
73  virtual bool loadStream(Common::SeekableReadStream &stream);
74 private:
75  // Format-spec from:
76  //http://www.ludorg.net/amnesia/TGA_File_Format_Spec.html
77  enum {
78  TYPE_CMAP = 1,
79  TYPE_TRUECOLOR = 2,
80  TYPE_BW = 3,
81  TYPE_RLE_CMAP = 9,
82  TYPE_RLE_TRUECOLOR = 10,
83  TYPE_RLE_BW = 11
84  };
85 
86  // Color-map:
87  bool _colorMapSize;
88  byte *_colorMap;
89  int16 _colorMapOrigin;
90  int16 _colorMapLength;
91  byte _colorMapEntryLength;
92 
93  // Origin may be at the top, or bottom
94  bool _originTop;
95 
96  Graphics::PixelFormat _format;
97  Graphics::Surface _surface;
98  // Loading helpers
99  bool readHeader(Common::SeekableReadStream &tga, byte &imageType, byte &pixelDepth);
100  bool readData(Common::SeekableReadStream &tga, byte imageType, byte pixelDepth);
101  bool readDataColorMapped(Common::SeekableReadStream &tga, byte imageType, byte indexDepth);
102  bool readDataRLE(Common::SeekableReadStream &tga, byte imageType, byte pixelDepth);
103  bool readColorMap(Common::SeekableReadStream &tga, byte imageType, byte pixelDepth);
104 };
106 } // End of namespace Image
107 
108 #endif
Definition: image_decoder.h:52
Definition: surface.h:67
Definition: tga.h:65
Definition: pixelformat.h:138
Definition: stream.h:745
virtual const byte * getPalette() const
Definition: tga.h:71
virtual const Graphics::Surface * getSurface() const
Definition: tga.h:70
Definition: algorithm.h:29
virtual uint16 getPaletteColorCount() const
Definition: tga.h:72
Definition: movie_decoder.h:32