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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 /* Based on code from eos https://github.com/DrMcCoy/xoreos/
24  * relicensed under GPLv2+ with permission from DrMcCoy and clone2727
25  */
26 
27 /*
28  * TGA decoder used in engines:
29  *	- titanic
30  *  - wintermute
31  *  - zvision
32  */
33 
34 #ifndef IMAGE_TGA_H
35 #define IMAGE_TGA_H
36 
37 #include "graphics/surface.h"
38 #include "image/image_decoder.h"
39 
40 namespace Common {
41 class SeekableReadStream;
42 }
43 
44 namespace Image {
45 
46 /** TarGa image-decoder
47  * The following variations of TGA are supported:
48  * - Type 1 - Color-mapped images in 16/24/32 bpp with 8 bit indexes
49  * - Type 2 - 16/24/32 bpp Top AND Bottom origined.
50  * - Type 3 - Black/White images, 8bpp.
51  * - Type 9 - RLE-encoded color-mapped images. (8 bit indexes only)
52  * - Type 10 - RLE-encoded TrueColor, 24/32bpp.
53  * - Type 11 - RLE-encoded Black/White, 8bpp.
54  *
55  * No images are returned with a palette, instead they are converted
56  * to 16 bpp for Type 1, or 32 bpp for Black/White-images.
57  */
58 class TGADecoder : public ImageDecoder {
59 public:
60 	TGADecoder();
61 	virtual ~TGADecoder();
62 	virtual void destroy();
getSurface()63 	virtual const Graphics::Surface *getSurface() const { return &_surface; }
getPalette()64 	virtual const byte *getPalette() const { return _colorMap; }
getPaletteColorCount()65 	virtual uint16 getPaletteColorCount() const { return _colorMapLength; }
66 	virtual bool loadStream(Common::SeekableReadStream &stream);
67 private:
68 	// Format-spec from:
69 	//http://www.ludorg.net/amnesia/TGA_File_Format_Spec.html
70 	enum {
71 	    TYPE_CMAP = 1,
72 	    TYPE_TRUECOLOR = 2,
73 	    TYPE_BW = 3,
74 	    TYPE_RLE_CMAP = 9,
75 	    TYPE_RLE_TRUECOLOR = 10,
76 	    TYPE_RLE_BW = 11
77 	};
78 
79 	// Color-map:
80 	bool _colorMapSize;
81 	byte *_colorMap;
82 	int16 _colorMapOrigin;
83 	int16 _colorMapLength;
84 	byte _colorMapEntryLength;
85 
86 	// Origin may be at the top, or bottom
87 	bool _originTop;
88 
89 	Graphics::PixelFormat _format;
90 	Graphics::Surface _surface;
91 	// Loading helpers
92 	bool readHeader(Common::SeekableReadStream &tga, byte &imageType, byte &pixelDepth);
93 	bool readData(Common::SeekableReadStream &tga, byte imageType, byte pixelDepth);
94 	bool readDataColorMapped(Common::SeekableReadStream &tga, byte imageType, byte indexDepth);
95 	bool readDataRLE(Common::SeekableReadStream &tga, byte imageType, byte pixelDepth);
96 	bool readColorMap(Common::SeekableReadStream &tga, byte imageType, byte pixelDepth);
97 };
98 
99 } // End of namespace Image
100 
101 #endif
102