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 /**
24  * @file
25  * Image decoder used in engines:
26  *  - mohawk
27  *  - pegasus
28  *  - sci
29  */
30 
31 #ifndef IMAGE_PICT_H
32 #define IMAGE_PICT_H
33 
34 #include "common/array.h"
35 #include "common/rect.h"
36 #include "common/scummsys.h"
37 
38 #include "image/image_decoder.h"
39 
40 namespace Common {
41 class SeekableReadStream;
42 }
43 
44 namespace Graphics {
45 struct Surface;
46 }
47 
48 namespace Image {
49 
50 #define DECLARE_OPCODE(x) void x(Common::SeekableReadStream &stream)
51 
52 class PICTDecoder : public ImageDecoder {
53 public:
54 	PICTDecoder();
55 	~PICTDecoder();
56 
57 	// ImageDecoder API
58 	bool loadStream(Common::SeekableReadStream &stream);
59 	void destroy();
getSurface()60 	const Graphics::Surface *getSurface() const { return _outputSurface; }
getPalette()61 	const byte *getPalette() const { return _palette; }
getPaletteColorCount()62 	uint16 getPaletteColorCount() const { return _paletteColorCount; }
63 
64 	struct PixMap {
65 		uint32 baseAddr;
66 		uint16 rowBytes;
67 		Common::Rect bounds;
68 		uint16 pmVersion;
69 		uint16 packType;
70 		uint32 packSize;
71 		uint32 hRes;
72 		uint32 vRes;
73 		uint16 pixelType;
74 		uint16 pixelSize;
75 		uint16 cmpCount;
76 		uint16 cmpSize;
77 		uint32 planeBytes;
78 		uint32 pmTable;
79 		uint32 pmReserved;
80 	};
81 
82 	static PixMap readPixMap(Common::SeekableReadStream &stream, bool hasBaseAddr = true);
83 
84 private:
85 	Common::Rect _imageRect;
86 	byte _palette[256 * 3];
87 	uint16 _paletteColorCount;
88 	Graphics::Surface *_outputSurface;
89 	bool _continueParsing;
90 
91 	// Utility Functions
92 	void unpackBitsRect(Common::SeekableReadStream &stream, bool withPalette);
93 	void unpackBitsLine(byte *out, uint32 length, Common::SeekableReadStream *stream, byte bitsPerPixel, byte bytesPerPixel);
94 	void skipBitsRect(Common::SeekableReadStream &stream, bool withPalette);
95 	void decodeCompressedQuickTime(Common::SeekableReadStream &stream);
96 	void outputPixelBuffer(byte *&out, byte value, byte bitsPerPixel);
97 
98 	// Opcodes
99 	typedef void (PICTDecoder::*OpcodeProcPICT)(Common::SeekableReadStream &stream);
100 	struct PICTOpcode {
PICTOpcodePICTOpcode101 		PICTOpcode() { op = 0; proc = 0; desc = 0; }
PICTOpcodePICTOpcode102 		PICTOpcode(uint16 o, OpcodeProcPICT p, const char *d) { op = o; proc = p; desc = d; }
103 		uint16 op;
104 		OpcodeProcPICT proc;
105 		const char *desc;
106 	};
107 	Common::Array<PICTOpcode> _opcodes;
108 
109 	// Common Opcodes
110 	void setupOpcodesCommon();
111 	DECLARE_OPCODE(o_nop);
112 	DECLARE_OPCODE(o_clip);
113 	DECLARE_OPCODE(o_txFont);
114 	DECLARE_OPCODE(o_txFace);
115 	DECLARE_OPCODE(o_pnSize);
116 	DECLARE_OPCODE(o_txSize);
117 	DECLARE_OPCODE(o_txRatio);
118 	DECLARE_OPCODE(o_versionOp);
119 	DECLARE_OPCODE(o_longText);
120 	DECLARE_OPCODE(o_longComment);
121 	DECLARE_OPCODE(o_opEndPic);
122 	DECLARE_OPCODE(o_headerOp);
123 
124 	// Regular-mode Opcodes
125 	void setupOpcodesNormal();
126 	DECLARE_OPCODE(on_packBitsRect);
127 	DECLARE_OPCODE(on_directBitsRect);
128 	DECLARE_OPCODE(on_compressedQuickTime);
129 
130 	// QuickTime-mode Opcodes
131 	void setupOpcodesQuickTime();
132 	DECLARE_OPCODE(oq_packBitsRect);
133 	DECLARE_OPCODE(oq_directBitsRect);
134 	DECLARE_OPCODE(oq_compressedQuickTime);
135 };
136 
137 #undef DECLARE_OPCODE
138 
139 } // End of namespace Image
140 
141 #endif
142