ScummVM API documentation
bitmap.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 MOHAWK_BITMAP_H
23 #define MOHAWK_BITMAP_H
24 
25 #include "mohawk/graphics.h"
26 
27 #include "common/scummsys.h"
28 #include "common/stream.h"
29 #include "common/array.h"
30 #include "graphics/surface.h"
31 
32 namespace Mohawk {
33 
34 class MohawkSurface;
35 
36 enum BitmapFormat {
37  kBitsPerPixel1 = 0x0000,
38  kBitsPerPixel4 = 0x0001,
39  kBitsPerPixel8 = 0x0002,
40  kBitsPerPixel16 = 0x0003,
41  kBitsPerPixel24 = 0x0004,
42  kBitsPerPixelMask = 0x0007,
43  kBitmapHasCLUT = 0x0008,
44  kDrawMASK = 0x00f0,
45  kDrawRaw = 0x0000,
46  kDrawRLE8 = 0x0010,
47  kDrawMSRLE8 = 0x0020,
48  kDrawRLE = 0x0030,
49  kPackMASK = 0x0f00,
50  kPackNone = 0x0000,
51  kPackLZ = 0x0100,
52  kPackLZ1 = 0x0200,
53  kPackRiven = 0x0400,
54  kPackXDec = 0x0f00,
55  kFlagMASK = 0xf000,
56  kFlag16_80X86 = 0x1000, // 16 bit pixel data has been converted to 80X86 format
57  kFlag24_MAC = 0x1000 // 24 bit pixel data has been converted to MAC 32 bit format
58 };
59 
60 enum OldBitmapFormat {
61  kOldPackLZ = 0x0020,
62  kOldDrawRLE8 = 0x0100
63 };
64 
65 struct BitmapHeader {
66  uint16 width;
67  uint16 height;
68  int16 bytesPerRow;
69  uint16 format;
70 
71  struct ColorTable {
72  uint16 tableSize;
73  byte rgbBits;
74  byte colorCount;
75  byte* palette; // In 8bpp only
76  } colorTable;
77 };
78 
79 class MohawkBitmap {
80 public:
81  MohawkBitmap();
82  virtual ~MohawkBitmap();
83 
84  virtual MohawkSurface *decodeImage(Common::SeekableReadStream *stream);
86 
87 protected:
88  BitmapHeader _header;
89  virtual byte getBitsPerPixel();
90 
91  void decodeImageData(Common::SeekableReadStream *stream);
92 
93  // The actual LZ decoder
94  static Common::SeekableReadStream *decompressLZ(Common::SeekableReadStream *stream, uint32 uncompressedSize);
95 
96  // The current data stream
98 
99  // Create the output surface
100  Graphics::Surface *createSurface(uint16 width, uint16 height);
101 
102  // Draw Functions
103  void drawRLE8(Graphics::Surface *surface, bool isLE);
104  void drawRaw(Graphics::Surface *surface);
105  void drawRLE8(Graphics::Surface *surface) { return drawRLE8(surface, false); }
106 
107 private:
108  // Unpack Functions
109  void unpackRaw();
110  void unpackLZ();
111  void unpackRiven();
112 
113  // An unpacker
114  struct PackFunction {
115  uint16 flag;
116  const char *name;
117  void (MohawkBitmap::*func)();
118  };
119 
120  // A drawer
121  struct DrawFunction {
122  uint16 flag;
123  const char *name;
124  void (MohawkBitmap::*func)(Graphics::Surface *surface);
125  };
126 
127  // Unpack/Draw maps
128  const PackFunction *_packTable;
129  int _packTableSize;
130  const DrawFunction *_drawTable;
131  int _drawTableSize;
132 
133  // Unpack/Draw helpers
134  const char *getPackName();
135  void unpackImage();
136  const char *getDrawName();
137  void drawImage(Graphics::Surface *surface);
138 
139  // Riven Decoding
140  void handleRivenSubcommandStream(byte count, byte *&dst);
141 };
142 
143 #ifdef ENABLE_MYST
144 
145 // Myst uses a different image format than that of other Mohawk games.
146 // It essentially uses a Windows bitmap with the LZ encoding from the
147 // Mohawk Bitmap format.
148 class MystBitmap : public MohawkBitmap {
149 public:
150  MystBitmap() : MohawkBitmap(), _bitsPerPixel(8) {}
151  ~MystBitmap() override {}
152 
153  MohawkSurface *decodeImage(Common::SeekableReadStream *stream) override;
154 
155 protected:
156  byte getBitsPerPixel() override { return _bitsPerPixel; }
157 
158 private:
159  byte _bitsPerPixel;
160 };
161 
162 #endif
163 
165 public:
167  ~LivingBooksBitmap_v1() override {}
168 
169  MohawkSurface *decodeImageLB(Common::SeekableReadStreamEndian *stream);
170 
171 protected:
172  byte getBitsPerPixel() override { return 8; }
173 };
174 
175 class DOSBitmap : public MohawkBitmap {
176 public:
177  DOSBitmap() : MohawkBitmap() {}
178  ~DOSBitmap() override {}
179 
180  MohawkSurface *decodeImage(Common::SeekableReadStream *stream) override;
181 
182 protected:
183  byte getBitsPerPixel() override { return ((_header.format & 0x30) >> 4) + 1; }
184 
185 private:
186  void expandMonochromePlane(Graphics::Surface *surface, Common::SeekableReadStream *rawStream);
187  void expandEGAPlanes(Graphics::Surface *surface, Common::SeekableReadStream *rawStream);
188 };
189 
190 } // End of namespace Mohawk
191 
192 #endif
Definition: bitmap.h:79
Definition: graphics.h:40
Definition: surface.h:67
Definition: array.h:52
Definition: bitmap.h:175
Definition: stream.h:745
Definition: bitmap.h:65
Definition: stream.h:944
Definition: bitmap.h:71
Definition: bitmap.h:164
Definition: bitmap.h:32