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 #include "graphics/palette.h"
29 
30 #include "image/image_decoder.h"
31 
32 namespace Common {
33 class SeekableReadStream;
34 }
35 
36 namespace Graphics {
37 struct Surface;
38 }
39 
40 namespace Image {
41 
55 #define DECLARE_OPCODE(x) void x(Common::SeekableReadStream &stream)
56 
57 class PICTDecoder : public ImageDecoder {
58 public:
59  PICTDecoder();
60  ~PICTDecoder();
61 
62  // ImageDecoder API
63  bool loadStream(Common::SeekableReadStream &stream) override;
64  void destroy() override;
65  const Graphics::Surface *getSurface() const override { return _outputSurface; }
66  const Graphics::Palette &getPalette() const override { return _palette; }
67 
68  struct PixMap {
69  uint32 baseAddr;
70  uint16 rowBytes;
71  Common::Rect bounds;
72  uint16 pmVersion;
73  uint16 packType;
74  uint32 packSize;
75  uint32 hRes;
76  uint32 vRes;
77  uint16 pixelType;
78  uint16 pixelSize;
79  uint16 cmpCount;
80  uint16 cmpSize;
81  uint32 planeBytes;
82  uint32 pmTable;
83  uint32 pmReserved;
84  };
85 
86  static PixMap readRowBytes(Common::SeekableReadStream &stream, bool hasBaseAddr = true);
87  static PixMap readPixMap(Common::SeekableReadStream &stream, bool hasBaseAddr = true, bool hasRowBytes = true);
88 
89 private:
90  Common::Rect _imageRect;
91  Graphics::Palette _palette;
92  byte _penPattern[8];
93  Common::Point _currentPenPosition;
94  Graphics::Surface *_outputSurface;
95  bool _continueParsing;
96  int _version;
97 
98  // Utility Functions
99  void unpackBitsRectOrRgn(Common::SeekableReadStream &stream, bool compressed, bool hasRegion);
100  void unpackBits(Common::SeekableReadStream &stream, bool compressed, bool hasRegion);
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_pnPat);
126  DECLARE_OPCODE(o_txSize);
127  DECLARE_OPCODE(o_txRatio);
128  DECLARE_OPCODE(o_versionOp);
129  DECLARE_OPCODE(o_shortLine);
130  DECLARE_OPCODE(o_shortLineFrom);
131  DECLARE_OPCODE(o_longText);
132  DECLARE_OPCODE(o_bitsRgn);
133  DECLARE_OPCODE(o_packBitsRgn);
134  DECLARE_OPCODE(o_shortComment);
135  DECLARE_OPCODE(o_longComment);
136  DECLARE_OPCODE(o_opEndPic);
137  DECLARE_OPCODE(o_headerOp);
138  DECLARE_OPCODE(o_versionOp1);
139 
140  // Regular-mode Opcodes
141  void setupOpcodesNormal();
142  DECLARE_OPCODE(on_bitsRect);
143  DECLARE_OPCODE(on_packBitsRect);
144  DECLARE_OPCODE(on_directBitsRect);
145  DECLARE_OPCODE(on_compressedQuickTime);
146 
147  // QuickTime-mode Opcodes
148  void setupOpcodesQuickTime();
149  DECLARE_OPCODE(oq_packBitsRect);
150  DECLARE_OPCODE(oq_directBitsRect);
151  DECLARE_OPCODE(oq_compressedQuickTime);
152 };
153 
154 #undef DECLARE_OPCODE
155 
156 } // End of namespace Image
157 
158 #endif
Definition: image_decoder.h:53
const Graphics::Surface * getSurface() const override
Definition: pict.h:65
Definition: surface.h:67
Definition: rect.h:524
Definition: stream.h:745
Definition: pict.h:68
const Graphics::Palette & getPalette() const override
Definition: pict.h:66
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: rect.h:144
Definition: pict.h:57
Simple class for handling a palette data.
Definition: palette.h:55
Definition: movie_decoder.h:32