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  byte _penPattern[8];
95  Common::Point _currentPenPosition;
96  Graphics::Surface *_outputSurface;
97  bool _continueParsing;
98  int _version;
99 
100  // Utility Functions
101  void unpackBitsRectOrRgn(Common::SeekableReadStream &stream, bool compressed, bool hasRegion);
102  void unpackBits(Common::SeekableReadStream &stream, bool compressed, bool hasRegion);
103  void unpackBitsRect(Common::SeekableReadStream &stream, bool withPalette, PixMap pixMap);
104  void unpackBitsLine(byte *out, uint32 length, Common::SeekableReadStream *stream, byte bitsPerPixel, byte bytesPerPixel);
105  void skipBitsRect(Common::SeekableReadStream &stream, bool withPalette);
106  void decodeCompressedQuickTime(Common::SeekableReadStream &stream);
107  void outputPixelBuffer(byte *&out, byte value, byte bitsPerPixel);
108 
109  // Opcodes
110  typedef void (PICTDecoder::*OpcodeProcPICT)(Common::SeekableReadStream &stream);
111  struct PICTOpcode {
112  PICTOpcode() { op = 0; proc = 0; desc = 0; }
113  PICTOpcode(uint16 o, OpcodeProcPICT p, const char *d) { op = o; proc = p; desc = d; }
114  uint16 op;
115  OpcodeProcPICT proc;
116  const char *desc;
117  };
118  Common::Array<PICTOpcode> _opcodes;
119 
120  // Common Opcodes
121  void setupOpcodesCommon();
122  DECLARE_OPCODE(o_nop);
123  DECLARE_OPCODE(o_clip);
124  DECLARE_OPCODE(o_txFont);
125  DECLARE_OPCODE(o_txFace);
126  DECLARE_OPCODE(o_pnSize);
127  DECLARE_OPCODE(o_pnPat);
128  DECLARE_OPCODE(o_txSize);
129  DECLARE_OPCODE(o_txRatio);
130  DECLARE_OPCODE(o_versionOp);
131  DECLARE_OPCODE(o_shortLine);
132  DECLARE_OPCODE(o_shortLineFrom);
133  DECLARE_OPCODE(o_longText);
134  DECLARE_OPCODE(o_bitsRgn);
135  DECLARE_OPCODE(o_packBitsRgn);
136  DECLARE_OPCODE(o_shortComment);
137  DECLARE_OPCODE(o_longComment);
138  DECLARE_OPCODE(o_opEndPic);
139  DECLARE_OPCODE(o_headerOp);
140  DECLARE_OPCODE(o_versionOp1);
141 
142  // Regular-mode Opcodes
143  void setupOpcodesNormal();
144  DECLARE_OPCODE(on_bitsRect);
145  DECLARE_OPCODE(on_packBitsRect);
146  DECLARE_OPCODE(on_directBitsRect);
147  DECLARE_OPCODE(on_compressedQuickTime);
148 
149  // QuickTime-mode Opcodes
150  void setupOpcodesQuickTime();
151  DECLARE_OPCODE(oq_packBitsRect);
152  DECLARE_OPCODE(oq_directBitsRect);
153  DECLARE_OPCODE(oq_compressedQuickTime);
154 };
155 
156 #undef DECLARE_OPCODE
157 
158 } // End of namespace Image
159 
160 #endif
Definition: image_decoder.h:52
Definition: surface.h:67
Definition: rect.h:144
Definition: stream.h:745
Definition: pict.h:69
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: rect.h:45
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