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