ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
wiz_he.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 #if !defined(SCUMM_HE_WIZ_HE_H) && defined(ENABLE_HE)
23 #define SCUMM_HE_WIZ_HE_H
24 
25 //#define WIZ_DEBUG_BUFFERS
26 
27 #include "common/rect.h"
28 
29 namespace Scumm {
30 
31 #define WIZBLOCK_WIZH_DATA_SIZE (4 * 3)
32 #define WIZBLOCK_RGBS_DATA_SIZE (768)
33 #define WIZBLOCK_SPOT_DATA_SIZE (4 * 2)
34 #define WIZBLOCK_RMAP_DATA_SIZE (256 + 4)
35 
36 #define WIZBLOCK_WIZH_SIZE (8 + (WIZBLOCK_WIZH_DATA_SIZE))
37 #define WIZBLOCK_RGBS_SIZE (8 + (WIZBLOCK_RGBS_DATA_SIZE))
38 #define WIZBLOCK_SPOT_SIZE (8 + (WIZBLOCK_SPOT_DATA_SIZE))
39 #define WIZBLOCK_RMAP_SIZE (8 + (WIZBLOCK_RMAP_DATA_SIZE))
40 
41 #define DW_LOAD_SUCCESS 0
42 #define DW_LOAD_NOT_TYPE -1
43 #define DW_LOAD_READ_FAILURE -2
44 #define DW_LOAD_OPEN_FAILURE -3
45 
46 #define DW_SAVE_SUCCESS 0
47 #define DW_SAVE_NOT_TYPE -1
48 #define DW_SAVE_WRITE_FAILURE -2
49 #define DW_SAVE_CREATE_FAILURE -3
50 
51 #define DW_SAVE_WIZ_FORMAT 0
52 #define DW_SAVE_PCX_FORMAT 1
53 #define DW_SAVE_RAW_FORMAT 2
54 
55 #if defined SCUMM_LITTLE_ENDIAN
56 #define NATIVE_WIZ_COMP_NONE_16BPP kWCTNone16Bpp
57 #define NATIVE_WIZ_COMP_TRLE_16BPP kWCTTRLE16Bpp
58 
59 #elif defined SCUMM_BIG_ENDIAN
60 #define NATIVE_WIZ_COMP_NONE_16BPP kWCTNone16BppBigEndian
61 #define NATIVE_WIZ_COMP_TRLE_16BPP kWCTTRLE16BppBigEndian
62 #endif
63 
64 #define LITTLE_ENDIAN_WIZ(wizComp) \
65  (wizComp) == kWCTNone16Bpp || \
66  (wizComp) == kWCTTRLE16Bpp
67 
68 #define NATIVE_WIZ_TYPE(wizComp) \
69  (wizComp) == NATIVE_WIZ_COMP_NONE_16BPP || \
70  (wizComp) == NATIVE_WIZ_COMP_TRLE_16BPP \
71 
72 #define WIZ_16BPP(wizComp) \
73  (wizComp) == kWCTNone16Bpp || \
74  (wizComp) == kWCTTRLE16Bpp || \
75  (wizComp) == kWCTNone16BppBigEndian || \
76  (wizComp) == kWCTTRLE16BppBigEndian
77 
78 #define WIZ_MAGIC_REMAP_NUMBER 0x76543210
79 
80 #define WIZRAWPIXEL_R_MASK (_uses16BitColor ? 0x7C00 : 0xFF)
81 #define WIZRAWPIXEL_G_MASK (_uses16BitColor ? 0x03E0 : 0xFF)
82 #define WIZRAWPIXEL_B_MASK (_uses16BitColor ? 0x001F : 0xFF)
83 
84 #define WIZRAWPIXEL_R_SHIFT (_uses16BitColor ? 10 : 0)
85 #define WIZRAWPIXEL_G_SHIFT (_uses16BitColor ? 5 : 0)
86 #define WIZRAWPIXEL_B_SHIFT (0)
87 
88 #define WIZRAWPIXEL_MASK (_uses16BitColor ? 0xFFFF : 0xFF)
89 
90 #define WIZRAWPIXEL_LO_R_BIT (1 << WIZRAWPIXEL_R_SHIFT)
91 #define WIZRAWPIXEL_LO_G_BIT (1 << WIZRAWPIXEL_G_SHIFT)
92 #define WIZRAWPIXEL_LO_B_BIT (1 << WIZRAWPIXEL_B_SHIFT)
93 #define WIZRAWPIXEL_LO_BITS ((WIZRAWPIXEL_LO_R_BIT) | (WIZRAWPIXEL_LO_G_BIT) | (WIZRAWPIXEL_LO_B_BIT))
94 #define WIZRAWPIXEL_HI_BITS ~WIZRAWPIXEL_LO_BITS
95 
96 #define WIZ_COLOR16_COMPONENT_COUNT (1 << 5)
97 #define WIZ_QUANTIZED_ALPHA_COUNT 16
98 #define WIZ_QUANTIZED_ALPHA_DIV ((256) / (WIZ_QUANTIZED_ALPHA_COUNT))
99 
100 #define WIZRAWPIXEL_50_50_PREMIX_COLOR(__rawColor__) (((__rawColor__) & WIZRAWPIXEL_HI_BITS) >> 1)
101 #define WIZRAWPIXEL_50_50_MIX(__colorA__, __colorB__) ((__colorA__) + (__colorB__))
102 
103 #define WIZRAWPIXEL_ADDITIVE_MIX(__colorA__, __colorB__) \
104  (MIN<int>(WIZRAWPIXEL_R_MASK, (((__colorA__) & WIZRAWPIXEL_R_MASK) + ((__colorB__) & WIZRAWPIXEL_R_MASK))) | \
105  MIN<int>(WIZRAWPIXEL_G_MASK, (((__colorA__) & WIZRAWPIXEL_G_MASK) + ((__colorB__) & WIZRAWPIXEL_G_MASK))) | \
106  MIN<int>(WIZRAWPIXEL_B_MASK, (((__colorA__) & WIZRAWPIXEL_B_MASK) + ((__colorB__) & WIZRAWPIXEL_B_MASK))))
107 
108 #define WIZRAWPIXEL_SUBTRACTIVE_MIX(__colorA__, __colorB__) \
109  (MAX<int>(WIZRAWPIXEL_LO_R_BIT, (((__colorA__) & WIZRAWPIXEL_R_MASK) - ((__colorB__) & WIZRAWPIXEL_R_MASK))) | \
110  MAX<int>(WIZRAWPIXEL_LO_G_BIT, (((__colorA__) & WIZRAWPIXEL_G_MASK) - ((__colorB__) & WIZRAWPIXEL_G_MASK))) | \
111  MAX<int>(WIZRAWPIXEL_LO_B_BIT, (((__colorA__) & WIZRAWPIXEL_B_MASK) - ((__colorB__) & WIZRAWPIXEL_B_MASK))))
112 
113 
114 typedef uint16 WizRawPixel;
115 typedef uint8 WizRawPixel8;
116 typedef uint16 WizRawPixel16;
117 
118 struct WizPolygon {
119  Common::Point points[5];
120  Common::Rect boundingRect;
121  int id;
122  int numPoints;
123  bool flag;
124 
125  void reset() {
126  for (int i = 0; i < ARRAYSIZE(points); i++) {
127  points[i].x = points[i].y = 0;
128  }
129  boundingRect.top = boundingRect.left = boundingRect.bottom = boundingRect.right = 0;
130  id = 0;
131  numPoints = 0;
132  flag = 0;
133  }
134 };
135 
136 struct WizBufferElement {
137  int image;
138  int x;
139  int y;
140  int z;
141  int state;
142  int flags;
143  int shadow;
144  int zbuffer;
145  int palette;
146 };
147 
148 struct WizFontProperties {
149  byte string[4096];
150  byte fontName[4096];
151  int fgColor;
152  int bgColor;
153  int style;
154  int size;
155  int xPos;
156  int yPos;
157 };
158 
159 struct WizEllipseProperties {
160  int px;
161  int py;
162  int qx;
163  int qy;
164  int kx;
165  int ky;
166  int lod;
167  WizRawPixel color;
168 };
169 
170 struct WizExtendedRenderInfo {
171  int32 blendFlags;
172  int32 sprite;
173  int32 group;
174  int32 conditionBits;
175 };
176 
177 struct WizImageCommand {
178  int dwSize;
179  byte filename[260];
180  Common::Rect box;
181  int actionFlags;
182  int actionType;
183  int params[8];
184  int flags;
185  int xPos;
186  int yPos;
187  int zPos;
188  int compressionType;
189  int fileType;
190  int angle;
191  int state;
192  int scale;
193  int shadow;
194  int polygon;
195  int polygon2;
196  int image;
197  int width;
198  int height;
199  int palette;
200  int sourceImage;
201  int propertyValue;
202  int propertyNumber;
203  uint8 remapTable[256];
204  uint8 remapList[256];
205  int remapCount;
206  int destImageNumber;
207  int zbufferImage;
208  WizRawPixel colorValue;
209  WizFontProperties fontProperties;
210  WizEllipseProperties ellipseProperties;
211  Common::Rect renderCoords;
212  WizExtendedRenderInfo extendedRenderInfo;
213 
214  void reset() {
215  dwSize = 0;
216  memset(filename, 0, sizeof(filename));
217  box.top = box.left = box.bottom = box.right = 0;
218  actionFlags = 0;
219  actionType = 0;
220  memset(params, 0, sizeof(params));
221  image = 0;
222  xPos = 0;
223  yPos = 0;
224  zPos = 0;
225  state = 0;
226  flags = 0;
227  shadow = 0;
228  zbufferImage = 0;
229  palette = 0;
230  compressionType = 0;
231  fileType = 0;
232  angle = 0;
233  scale = 0;
234  polygon = 0;
235  polygon2 = 0;
236  width = 0;
237  height = 0;
238  sourceImage = 0;
239  propertyValue = 0;
240  propertyNumber = 0;
241  memset(remapTable, 0, sizeof(remapTable));
242  memset(remapList, 0, sizeof(remapList));
243  remapCount = 0;
244  destImageNumber = 0;
245  colorValue = 0;
246  memset(&fontProperties, 0, sizeof(WizFontProperties));
247  memset(&ellipseProperties, 0, sizeof(WizEllipseProperties));
248  renderCoords.left = renderCoords.top = renderCoords.bottom = renderCoords.right = 0;
249  memset(&extendedRenderInfo, 0, sizeof(WizExtendedRenderInfo));
250  }
251 };
252 
253 struct FloodFillCommand {
254  Common::Rect box;
255  int32 x;
256  int32 y;
257  int32 flags;
258  int32 color;
259 
260  void reset() {
261  box.top = box.left = box.bottom = box.right = 0;
262  x = 0;
263  y = 0;
264  flags = 0;
265  color = 0;
266  }
267 };
268 
269 #ifdef WIZ_DEBUG_BUFFERS
270 #define WizPxShrdBufferD(a, b) WizPxShrdBuffer(a, b, __FUNCTION__, __LINE__)
271 struct DbgEntry {
272  DbgEntry(const void *a, const char *lpr, int ln) : addr(a), msg(Common::String::format("buffer allocated in: %s(), line %d", lpr, ln)) {}
273  bool operator==(const void *ptr) const { return addr == ptr; }
274  const void *addr;
275  Common::String msg;
276 };
277 #else
278 #define WizPxShrdBufferD(a, b) WizPxShrdBuffer(a, b)
279 #endif
280 
281 class WizPxShrdBuffer {
282 public:
283 #ifdef WIZ_DEBUG_BUFFERS
284  static void dbgLeakRpt() {
285  if (!_allocLocs)
286  return;
287  for (Common::Array<DbgEntry>::iterator i = _allocLocs->begin(); i != _allocLocs->end(); ++i)
288  debug("Leaked: %s", i->msg.c_str());
289  _allocLocs->clear();
290  delete _allocLocs;
291  _allocLocs = nullptr;
292  }
293  static Common::Array<DbgEntry> *_allocLocs;
294 #endif
295  WizPxShrdBuffer() : _buff(nullptr), _lifes(nullptr), _xstart(0) {}
296 #ifdef WIZ_DEBUG_BUFFERS
297  WizPxShrdBuffer(void *buff, bool hasOwnerShip) : WizPxShrdBuffer(buff, hasOwnerShip, 0, 0) {}
298  WizPxShrdBuffer(void *buff, bool hasOwnerShip, const char *func, int line)
299 #else
300  WizPxShrdBuffer(void *buff, bool hasOwnerShip)
301 #endif
302  : _buff(reinterpret_cast<WizRawPixel *>(buff)), _lifes(nullptr), _xstart(0) {
303  if (hasOwnerShip) {
304 #ifdef WIZ_DEBUG_BUFFERS
305  if (!_allocLocs)
306  _allocLocs = new Common::Array<DbgEntry>();
307  _allocLocs->push_back(DbgEntry(buff, func, line));
308 #endif
309  *(_lifes = new int) = 1;
310  }
311  }
312  WizPxShrdBuffer(const WizPxShrdBuffer &other) : _buff(other._buff), _lifes(other._lifes), _xstart(other._xstart) {
313  if (_lifes)
314  ++*_lifes;
315  }
316  WizPxShrdBuffer(WizPxShrdBuffer &&other) noexcept : _buff(other._buff), _lifes(other._lifes), _xstart(other._xstart) {
317  other._lifes = nullptr;
318  }
319  ~WizPxShrdBuffer() {
320  dcrlifes();
321  }
322  WizRawPixel *operator()() const { return (WizRawPixel*)((byte*)_buff + _xstart); }
323  WizPxShrdBuffer &operator=(const WizPxShrdBuffer &other) {
324  if (this != &other) {
325  dcrlifes();
326  if ((_lifes = other._lifes) != nullptr) ++*_lifes;
327  _buff = other._buff;
328  _xstart = other._xstart;
329  }
330  return *this;
331  }
332  WizPxShrdBuffer &&operator=(WizPxShrdBuffer &&other) {
333  dcrlifes();
334  _lifes = other._lifes;
335  _buff = other._buff;
336  _xstart = other._xstart;
337  other._lifes = nullptr;
338  return Common::move(*this);
339  }
340  WizPxShrdBuffer &operator+(int bytes) {
341  _xstart += bytes;
342  return *this;
343  }
344  WizPxShrdBuffer &operator+=(int bytes) { return operator+(bytes); }
345  bool operator==(WizRawPixel *ptr) const { return _buff == ptr; }
346 private:
347  void dcrlifes() {
348  if (_lifes && !--*_lifes) {
349  free(_buff);
350 #ifdef WIZ_DEBUG_BUFFERS
351  Common::Array<DbgEntry>::iterator i = Common::find(_allocLocs->begin(), _allocLocs->end(), _buff);
352  if (i != _allocLocs->end())
353  _allocLocs->erase(i);
354 #endif
355  }
356  if (_lifes && !*_lifes)
357  delete _lifes;
358  }
359  WizRawPixel *_buff;
360  int *_lifes;
361  int _xstart;
362 };
363 
364 struct WizSimpleBitmap {
365  WizPxShrdBuffer bufferPtr;
366  int32 bitmapWidth;
367  int32 bitmapHeight;
368 
369  WizSimpleBitmap() : bufferPtr(), bitmapWidth(0), bitmapHeight(0) {
370 
371  }
372 };
373 
374 struct WizMultiTypeBitmap {
375  byte *data;
376  int32 width;
377  int32 height;
378  int32 stride;
379  int32 format;
380  int32 bpp;
381 };
382 
383 struct WizRawBitmap {
384  int32 width;
385  int32 height;
386  int32 dataSize;
387  WizRawPixel16 *data;
388 };
389 
390 struct WizImage {
391  int dataSize;
392  byte *data;
393 };
394 
395 struct WizFloodSegment {
396  int y, xl, xr, dy;
397 };
398 
399 struct WizFloodState {
400  WizFloodSegment *stack;
401  WizFloodSegment *top;
402  WizFloodSegment *sp;
403  Common::Rect updateRect;
404  Common::Rect clipping;
405  WizSimpleBitmap *bitmapPtr;
406  int writeOverColor;
407  int colorToWrite;
408  int boundryColor;
409  int numStackElements;
410 };
411 
412 struct WizCompressedImage {
413  const byte *data;
414  int width;
415  int height;
416 };
417 
418 struct WizMoonbaseCompressedImage {
419  int type, size, width, height;
420  WizRawPixel16 transparentColor;
421  byte *data;
422 };
423 
424 struct MoonbaseDistortionInfo {
425  byte *srcData;
426  int baseX;
427  int baseY;
428  int srcPitch;
429  Common::Rect *clipRect;
430 };
431 
432 // Our Common::Point has int16 coordinates.
433 // This is not enough for polygon warping...
434 struct WarpWizPoint {
435  int32 x;
436  int32 y;
437 
438  WarpWizPoint(Common::Point pt) {
439  x = pt.x;
440  y = pt.y;
441  }
442 
443  WarpWizPoint() {
444  x = y = 0;
445  }
446 };
447 
448 struct WarpWizOneSpan {
449  int dstLeft;
450  int dstRight;
451  WarpWizPoint srcLeft;
452  WarpWizPoint srcRight;
453 };
454 
455 struct WarpWizOneDrawSpan {
456  int dstOffset;
457  int xSrcStep;
458  int ySrcStep;
459  int xSrcOffset;
460  int ySrcOffset;
461  int dstWidth;
462 };
463 
464 struct WarpWizOneSpanTable {
465  WarpWizPoint dstMinPt, dstMaxPt;
466  WarpWizPoint srcMinPt, srcMaxPt;
467  WarpWizOneDrawSpan *drawSpans;
468  WarpWizOneSpan *spans;
469  int drawSpanCount;
470  int spanCount;
471 };
472 
473 enum WizRenderingFlags : uint {
474  // Standard rendering flags
475  kWRFUsePalette = 0x00000001,
476  kWRFRemap = 0x00000002,
477  kWRFPrint = 0x00000004,
478  kWRFBackground = 0x00000008,
479  kWRFForeground = 0x00000010,
480  kWRFAlloc = 0x00000020,
481  kWRFPolygon = 0x00000040,
482  kWRFZPlaneOn = 0x00000080,
483  kWRFZPlaneOff = 0x00000100,
484  kWRFUseShadow = 0x00000200,
485  kWRFHFlip = 0x00000400,
486  kWRFVFlip = 0x00000800,
487  kWRFRotate90 = 0x00001000,
488 
489  // Special rendering flags
490  kWRFSpecialRenderBitMask = 0xFFF00000,
491  kWRFAdditiveBlend = 0x00100000,
492  kWRFSubtractiveBlend = 0x00200000,
493  kWRF5050Blend = 0x00400000,
494  kWRFAreaSampleDuringWarp = 0x00800000,
495  kWRFUseSourceImageAsAlphaChannel = 0x01000000,
496  kWRFBooleanAlpha = 0x02000000,
497  kWRFInverseAlpha = 0x04000000,
498  kWRFUseImageAsAlphaChannel = 0x08000000,
499  kWRFUseBlendPrimitives = 0x10000000,
500  kWRFFutureExpansionBit1 = 0x20000000,
501  kWRFFutureExpansionBit2 = 0x40000000,
502  kWRFFutureExpansionBit3 = 0x80000000,
503 };
504 
505 enum WizActions {
506  kWAUnknown = 0,
507  kWADraw = 1,
508  kWACapture = 2,
509  kWALoad = 3,
510  kWASave = 4,
511  kWAGlobalState = 5,
512  kWAModify = 6,
513  kWAPolyCapture = 7,
514  kWANew = 8,
515  kWARenderRectangle = 9,
516  kWARenderLine = 10,
517  kWARenderPixel = 11,
518  kWARenderFloodFill = 12,
519  kWAFontStart = 13,
520  kWAFontEnd = 14,
521  kWAFontCreate = 15,
522  kWAFontRender = 16,
523  kWARenderEllipse = 17,
524 };
525 
526 enum WizActionFlags {
527  kWAFSpot = 0x00000001,
528  kWAFPolygon = 0x00000002,
529  kWAFShadow = 0x00000004,
530  kWAFScale = 0x00000008,
531  kWAFAngle = 0x00000010,
532  kWAFFlags = 0x00000020,
533  kWAFRemapList = 0x00000040,
534  kWAFFileType = 0x00000080,
535  kWAFCompressionType = 0x00000100,
536  kWAFRect = 0x00000200,
537  kWAFState = 0x00000400,
538  kWAFFilename = 0x00000800,
539  kWAFPolygon2 = 0x00001000,
540  kWAFWidth = 0x00002000,
541  kWAFHeight = 0x00004000,
542  kWAFPalette = 0x00008000,
543  kWAFDestImage = 0x00010000,
544  kWAFColor = 0x00020000,
545  kWAFRenderCoords = 0x00040000,
546  kWAFSourceImage = 0x00080000,
547  kWAFProperty = 0x00100000,
548  kWAFZBufferImage = 0x00200000
549 };
550 
551 enum WizCompositeFlags {
552  kWCFConditionBits = 0x00000001,
553  kWCFSubState = 0x00000002,
554  kWCFXDelta = 0x00000004,
555  kWCFYDelta = 0x00000008,
556  kWCFDrawFlags = 0x00000010,
557  kWCFSubConditionBits = 0x00000020
558 };
559 
560 enum WizCompressionTypes {
561  kWCTNone = 0x00000000,
562  kWCTTRLE = 0x00000001,
563  kWCTNone16Bpp = 0x00000002,
564  // kWCTNone32Bpp = 0x00000003,
565  kWCTComposite = 0x00000004,
566  kWCTTRLE16Bpp = 0x00000005,
567  // kWCTTRLE32Bpp = 0x00000006,
568  kWCTMRLEWithLineSizePrefix = 0x00000007,
569  kWCTMRLEWithoutLineSizePrefix = 0x00000008,
570  kWCTDataBlockDependent = 0x00000009,
571  kWCTNone16BppBigEndian = 0x0000000A,
572  // kWCTNone32BppBigEndian = 0x0000000B,
573  kWCTTRLE16BppBigEndian = 0x0000000C,
574  // kWCTTRLE32BppBigEndian = 0x0000000D
575 };
576 
577 enum CreateWizFlags {
578  kCWFPalette = 0x00000001,
579  kCWFSpot = 0x00000002,
580  kCWFRemapTable = 0x00000008,
581  kCWFDefault = ((kCWFPalette) | (kCWFSpot) | (kCWFRemapTable))
582 };
583 
584 enum WizImgProps {
585  kWIPCompressionType = 0x10000000,
586  kWIPPaletteBlockPresent = 0x10000001,
587  kWIPRemapBlockPresent = 0x10000002,
588  kWIPOpaqueBlockPresent = 0x10000003,
589  kWIPXMAPBlockPresent = 0x10000004
590 };
591 
592 enum WizSpcConditionTypes : uint {
593  kWSPCCTBits = 0xC0000000,
594  kWSPCCTOr = 0x00000000,
595  kWSPCCTAnd = 0x40000000,
596  kWSPCCTNot = 0x80000000
597 };
598 
599 enum WizMoonSystemBits {
600  kWMSBRopMask = 0x000000FF,
601  kWMSBRopParamMask = 0x0000FF00,
602  kWMSBReservedBits = (kWMSBRopMask | kWMSBRopParamMask),
603  kWMSBRopParamRShift = 8
604 };
605 
606 enum WizEllipseConstants {
607  kWECFixedSize = 16,
608  kWECPiOver2 = 102944, // Fixed point PI/2
609  kWECHalf = 32768 // Fixed point 1/2
610 };
611 
612 enum WizZPlaneOps {
613  kWZOIgnore = 0,
614  kWZOClear = 1,
615  kWZOSet = 2
616 };
617 
618 enum DstSurface {
619  kDstScreen = 0,
620  kDstMemory = 1,
621  kDstResource = 2,
622  kDstCursor = 3
623 };
624 
625 class ScummEngine_v71he;
626 
627 class Wiz {
628 public:
629  enum {
630  NUM_POLYGONS = 200,
631  NUM_IMAGES = 255
632  };
633 
634  WizBufferElement _wizBuffer[NUM_IMAGES] = {};
635  uint16 _wizBufferIndex = 0;
636  WizPolygon _polygons[NUM_POLYGONS] = {};
637 
638  // For collision
639  WizRawPixel _compareBufferA[640] = {};
640  WizRawPixel _compareBufferB[640] = {};
641 
642  Wiz(ScummEngine_v71he *vm);
643  ~Wiz() {
644 #ifdef WIZ_DEBUG_BUFFERS
645  WizPxShrdBuffer::dbgLeakRpt();
646 #endif
647  }
648 
649  void clearWizBuffer();
650  Common::Rect _wizClipRect;
651  bool _useWizClipRect = false;
652  bool _uses16BitColor = false;
653  int _wizActiveShadow = 0;
654 
655  void deleteLocalPolygons();
656  void polygonLoad(const uint8 *polData);
657  void set4Polygon(int id, bool flag, int vert1x, int vert1y, int vert2x, int vert2y, int vert3x, int vert3y, int vert4x, int vert4y);
658  void polyBuildBoundingRect(Common::Point *vert, int numVerts, Common::Rect & bound);
659  void deletePolygon(int fromId, int toId);
660  int testForObjectPolygon(int id, int x, int y);
661  int findPolygon(int x, int y);
662  bool doesObjectHavePolygon(int id);
663  bool polyIsPointInsidePoly(Common::Point *listOfPoints, int numverts, Common::Point *checkPoint);
664  void polyRotatePoints(Common::Point *pts, int num, int alpha);
665  void polyMovePolygonPoints(Common::Point *listOfPoints, int numverts, int deltaX, int deltaY);
666  bool polyIsRectangle(const Common::Point *points, int numverts);
667 
668  void dwCreateRawWiz(int imageNum, int w, int h, int flags, int bitsPerPixel, int optionalSpotX, int optionalSpotY);
669  bool dwGetMultiTypeBitmapFromImageState(int imageNum, int imageState, WizMultiTypeBitmap *multiBM);
670  bool dwSetSimpleBitmapStructFromImage(int imageNum, int imageState, WizSimpleBitmap *destBM);
671  int dwTryToLoadWiz(Common::SeekableReadStream *inFile, const WizImageCommand *params);
672  void dwAltSourceDrawWiz(int maskImage, int maskState, int x, int y, int sourceImage, int sourceState, int32 flags, int paletteNumber, const Common::Rect *optionalClipRect, const WizSimpleBitmap *destBitmapPtr);
673  void dwHandleComplexImageDraw(int image, int state, int x, int y, int shadow, int angle, int scale, const Common::Rect *clipRect, int32 flags, WizSimpleBitmap *optionalBitmapOverride, const WizRawPixel *optionalColorConversionTable);
674  bool dwIsMaskCompatibleCompressionType(int compressionType);
675  bool dwIsUncompressedFormatTypeID(int id);
676  int dwGetImageGeneralProperty(int image, int state, int property);
677 
678  void processWizImageCmd(const WizImageCommand *params);
679  void processWizImageCaptureCmd(const WizImageCommand *params);
680  void processWizImagePolyCaptureCmd(const WizImageCommand *params);
681  void processWizImageDrawCmd(const WizImageCommand *params);
682  void processWizImageRenderRectCmd(const WizImageCommand *params);
683  void processWizImageRenderLineCmd(const WizImageCommand *params);
684  void processWizImageRenderPixelCmd(const WizImageCommand *params);
685  void processWizImageRenderFloodFillCmd(const WizImageCommand *params);
686  void processWizImageModifyCmd(const WizImageCommand *params);
687  void processWizImageRenderEllipseCmd(const WizImageCommand *params);
688  void processWizImageFontStartCmd(const WizImageCommand *params);
689  void processWizImageFontEndCmd(const WizImageCommand *params);
690  void processWizImageFontCreateCmd(const WizImageCommand *params);
691  void processWizImageFontRenderCmd(const WizImageCommand *params);
692  void processNewWizImageCmd(const WizImageCommand *params);
693  void processWizImageLoadCmd(const WizImageCommand *params);
694  void processWizImageSaveCmd(const WizImageCommand *params);
695 
696  void getWizImageDim(int resNum, int state, int32 &w, int32 &h);
697  void getWizImageDim(uint8 *dataPtr, int state, int32 &w, int32 &h);
698  int getWizStateCount(int resnum);
699  int getWizImageStates(const uint8 *ptr);
700  byte *getWizStateHeaderPrim(int resNum, int state);
701  byte *getWizStateDataPrim(int resNum, int state);
702  byte *getWizStatePaletteDataPrim(int resNum, int state);
703  byte *getWizStateRemapDataPrim(int resNum, int state);
704  int getWizCompressionType(int resNum, int state);
705  bool doesRawWizStateHaveTransparency(int globNum, int state);
706  bool doesStateContainBlock(int globNum, int state, uint32 blockID);
707  const byte *getColorMixBlockPtrForWiz(int image);
708  void setWizCompressionType(int image, int state, int newType);
709 
710  bool isUncompressedFormatTypeID(int id);
711 
712  void handleRotate0SpecialCase(int image, int state, int x, int y, int shadow, int angle, int scale, const Common::Rect *clipRect, int32 flags, WizSimpleBitmap *optionalBitmapOverride, const WizRawPixel *optionalColorConversionTable);
713  void handleRotate90SpecialCase(int image, int state, int x, int y, int shadow, int angle, int scale, const Common::Rect *clipRect, int32 flags, WizSimpleBitmap *optionalBitmapOverride, const WizRawPixel *optionalColorConversionTable);
714  void handleRotate180SpecialCase(int image, int state, int x, int y, int shadow, int angle, int scale, const Common::Rect *clipRect, int32 flags, WizSimpleBitmap *optionalBitmapOverride, const WizRawPixel *optionalColorConversionTable);
715  void handleRotate270SpecialCase(int image, int state, int x, int y, int shadow, int angle, int scale, const Common::Rect *clipRect, int32 flags, WizSimpleBitmap *optionalBitmapOverride, const WizRawPixel *optionalColorConversionTable);
716 
717  void flushAWizBuffer();
718 
719  void getWizSpot(int resId, int state, int32 &x, int32 &y);
720  void getWizSpot(int resId, int32 &x, int32 &y); // HE80
721  void getWizImageSpot(uint8 *data, int state, int32 &x, int32 &y);
722  void loadWizCursor(int resId, int palette, bool useColor);
723 
724  void takeAWiz(int globnum, int x1, int y1, int x2, int y2, bool back, bool compress);
725  void simpleDrawAWiz(int image, int state, int x, int y, int flags);
726  void bufferAWiz(int image, int state, int x, int y, int z, int flags, int optionalShadowImage, int optionalZBufferImage, int whichPalette);
727  WizPxShrdBuffer drawAWiz(int image, int state, int x, int y, int z, int flags, int optionalShadowImage, int optionalZBufferImage,
728  Common::Rect *optionalClipRect, int whichPalette, WizSimpleBitmap *optionalBitmapOverride);
729  WizPxShrdBuffer drawAWizEx(int image, int state, int x, int y, int z, int flags, int optionalShadowImage, int optionalZBufferImage, Common::Rect *optionalClipRect,
730  int whichPalette, WizSimpleBitmap *optionalBitmapOverride, const WizImageCommand *optionalICmdPtr);
731  WizPxShrdBuffer drawAWizPrim(int globNum, int state, int x, int y, int z, int shadowImage, int zbufferImage, const Common::Rect *optionalClipRect, int flags, WizSimpleBitmap *optionalBitmapOverride, const WizRawPixel *optionalColorConversionTable);
732  WizPxShrdBuffer drawAWizPrimEx(int globNum, int state, int x, int y, int z, int shadowImage, int zbufferImage, const Common::Rect *optionalClipRect, int flags, WizSimpleBitmap *optionalBitmapOverride, const WizRawPixel *optionalColorConversionTable, const WizImageCommand *optionalICmdPtr);
733  void buildAWiz(const WizPxShrdBuffer &bufPtr, int bufWidth, int bufHeight, const byte *palettePtr, const Common::Rect *rectPtr, int compressionType, int globNum, int transparentColor);
734 
735  int pixelHitTestWiz(int image, int state, int x, int y, int32 flags);
736  int pixelHitTestWizPrim(int image, int state, int x, int y, int32 flags);
737  int hitTestWiz(int image, int state, int x, int y, int32 flags);
738  int hitTestWizPrim(int globNum, int state, int x, int y, int32 flags);
739  void remapImagePrim(int image, int state, int tableCount, const uint8 *remapList, const uint8 *remapTable);
740  int createHistogramArrayForImage(int image, int state, const Common::Rect *optionalClipRect);
741  void ensureNativeFormatImageForState(int image, int state);
742 
743  bool compareDoPixelStreamsOverlap(const WizRawPixel *a, const WizRawPixel *b, int width, WizRawPixel transparentColor);
744  bool collisionCompareImageLines(
745  const byte *imageAData, int aType, int aw, int ah, int32 wizAFlags, int ax, int ay,
746  const byte *imageBData, int bType, int bw, int bh, int32 wizBFlags, int bx, int by,
747  int compareWidth, WizRawPixel transparentColor);
748 
749  /*
750  * Moonbase Commander custom Wiz operations
751  *
752  * These are defined in moonbase/moonbase_layered_wiz.cpp
753  * Beware: some of these functions are using both the custom WIZ
754  * Rect functions and our own. This is *by design*, and emulates
755  * what the original code does (using both the WIZ functions and
756  * the Windows Rect primitives). Do not attempt to change this!
757  *
758  */
759 
760  bool drawMoonbaseLayeredWiz(
761  byte *dstBitmapData, int dstWidth, int dstHeight, int dstPitch,
762  int dstFormat, int dstBpp, byte *wizImageData,
763  int x, const int y, int state, int clipX1, int clipY1, int clipX2, int clipY2,
764  uint32 flags, uint32 conditionBits, byte *ptr8BppToXBppClut, byte *altSourceBuffer);
765 
766  void handleCompositeDrawMoonbaseImage(
767  WizRawBitmap *bitmapPtr, WizImage *wizPtr, byte *compositeInfoBlockPtr,
768  int x, int y, Common::Rect *srcRect, Common::Rect *clipRect,
769  int32 flags, uint32 conditionBits, int32 outerSizeX, int32 outerSizeY,
770  WizRawPixel16 *ptr8BppToXBppClut, byte *altSourceBuffer);
771 
772  void drawMoonbaseImageEx(
773  WizRawBitmap *bitmapPtr, WizImage *wizPtr, int x, int y, int state,
774  Common::Rect *clipRectPtr, int32 flags, Common::Rect *optionalSrcRect,
775  uint32 conditionBits, WizRawPixel16 *ptr8BppToXBppClut, byte *altSourceBuffer);
776 
777  bool getRawMoonbaseBitmapInfoForState(WizRawBitmap *bitmapPtr, WizImage *wizPtr, int state);
778  void rawMoonbaseBitmapBlit(WizRawBitmap *dstBitmap, Common::Rect *dstRectPtr, WizRawBitmap *srcBitmap, Common::Rect *srcRectPtr);
779 
780  void trleFLIPDecompressMoonbaseImage(
781  WizRawBitmap *bitmapPtr, WizMoonbaseCompressedImage *imagePtr, int destX, int destY,
782  Common::Rect *sourceCoords, Common::Rect *clipRectPtr, int32 flags);
783  void trleFLIPDecompMoonbaseImageHull(
784  WizRawPixel16 *bufferPtr, int bufferWidth, Common::Rect *destRect, byte *compData, Common::Rect *sourceRect, byte *extraPtr,
785  void (*functionPtr)(Wiz *wiz, WizRawPixel *destPtr, byte *dataStream, int skipAmount, int decompAmount, byte *extraPtr));
786 
787  bool moonbaseLayeredWizHitTest(int32 *outValue, int32 *optionalOutActualValue, byte *globPtr, int state, int x, int y, int32 flags, uint32 conditionBits);
788 
789  void dispatchBlitRGB555(
790  byte *bufferData, int bufferWidth, int bufferHeight, int bufferPitch,
791  Common::Rect *optionalClippingRect, byte *compressedDataStream,
792  int x, int y, int nROP, int nROPParam, byte *altSourceBuffer);
793 
794  void blitT14CodecImage(
795  byte *dst, int dstw, int dsth, int dstPitch, const Common::Rect *clipBox,
796  byte *wizd, int srcx, int srcy, int rawROP, int paramROP);
797 
798  void blitDistortion(
799  byte *bufferData, int bufferWidth, int bufferHeight, int bufferPitch,
800  Common::Rect *optionalClippingRect, byte *compressedDataStream,
801  int x, int y, byte *altSourceBuffer);
802 
803  void blitUncompressedDistortionBitmap(
804  byte *dstBitmapData, int dstWidth, int dstHeight, int dstPitch, int dstFormat, int dstBpp,
805  byte *srcBitmapData, int srcWidth, int srcHeight, int srcPitch, int srcFormat, int srcBpp,
806  byte *distortionBitmapData, int distortionWidth, int distortionHeight, int distortionPitch, int distortionFormat, int distortionBpp,
807  int dstX, int dstY, int srcX, int srcY, int lReach, int rReach, int tReach, int bReach,
808  int srcClipX1, int srcClipY1, int srcClipX2, int srcClipY2,
809  int dstClipX1, int dstClipY1, int dstClipX2, int dstClipY2);
810 
811  void distortionBlitCore(
812  Graphics::Surface *dstBitmap, int x, int y, Graphics::Surface *srcBitmap,
813  Common::Rect *optionalSrcRectPtr, Common::Rect *optionalclipRectPtr, int transferOp, MoonbaseDistortionInfo *mdi);
814 
815 
816 private:
817  ScummEngine_v71he *_vm;
818 
819 
820 public:
821  /* Drawing Primitives
822  *
823  * These primitives are slightly different and less precise
824  * than the ones available in our Graphics subsystem.
825  * But they are more accurate in the context of SCUMM HE graphics.
826  * So leave them be and resist the urge to replace them with our own
827  * primitives, please :-P
828  */
829 
830  // Primitives
831  int pgReadPixel(const WizSimpleBitmap *srcBM, int x, int y, int defaultValue);
832  void pgWritePixel(WizSimpleBitmap *srcBM, int x, int y, WizRawPixel value);
833  void pgClippedWritePixel(WizSimpleBitmap *srcBM, int x, int y, const Common::Rect *clipRectPtr, WizRawPixel value);
834  void pgClippedLineDraw(WizSimpleBitmap *destBM, int asx, int asy, int aex, int aey, const Common::Rect *clipRectPtr, WizRawPixel value);
835  void pgClippedThickLineDraw(WizSimpleBitmap *destBM, int asx, int asy, int aex, int aey, const Common::Rect *clipRectPtr, int iLineThickness, WizRawPixel value);
836  void pgDrawClippedEllipse(WizSimpleBitmap *pDestBitmap, int iPX, int iPY, int iQX, int iQY, int iKX, int iKY, int iLOD, const Common::Rect *pClipRectPtr, int iThickness, WizRawPixel aColor);
837  void pgDrawSolidRect(WizSimpleBitmap *destBM, const Common::Rect *rectPtr, WizRawPixel color);
838  void pgFloodFillCmd(int x, int y, int color, const Common::Rect *optionalClipRect);
839 
840  void pgHistogramBitmapSubRect(int *tablePtr, const WizSimpleBitmap *bitmapPtr, const Common::Rect *sourceRect);
841  void pgSimpleBitmapFromDrawBuffer(WizSimpleBitmap *bitmapPtr, bool background);
842  bool pgGetMultiTypeBitmapFromDrawBuffer(WizMultiTypeBitmap *multiBM, bool background);
843  void pgDrawRawDataFormatImage(WizRawPixel *bufferPtr, const WizRawPixel *rawData, int bufferWidth, int bufferHeight, int x, int y, int width, int height, Common::Rect *clipRectPtr, int32 wizFlags, const byte *extraTable, int transparentColor);
844  void pgSimpleBlit(WizSimpleBitmap *destBM, Common::Rect *destRect, WizSimpleBitmap *sourceBM, Common::Rect *sourceRect);
845  void pgSimpleBlitRemapColors(WizSimpleBitmap *destBM, Common::Rect *destRect, WizSimpleBitmap *sourceBM, Common::Rect *sourceRect, const byte *remapColorTable);
846  void pgSimpleBlitTransparentRemapColors(WizSimpleBitmap *destBM, Common::Rect *destRect, WizSimpleBitmap *sourceBM, Common::Rect *sourceRect, WizRawPixel transparentColor, const byte *remapColorTable);
847  void pgSimpleBlitMixColors(WizSimpleBitmap *destBM, Common::Rect *destRect, WizSimpleBitmap *sourceBM, Common::Rect *sourceRect, const byte *mixColorTable);
848  void pgSimpleBlitTransparentMixColors(WizSimpleBitmap *destBM, Common::Rect *destRect, WizSimpleBitmap *sourceBM, Common::Rect *sourceRect, WizRawPixel transparentColor, const byte *mixColorTable);
849  void pgTransparentSimpleBlit(WizSimpleBitmap *destBM, Common::Rect *destRect, WizSimpleBitmap *sourceBM, Common::Rect *sourceRect, WizRawPixel transparentColor);
850 
851  void pgDrawWarpDrawLetter(WizRawPixel *bitmapBuffer, int bitmapWidth, int bitmapHeight, const byte *charData, int x1, int y1, int width, int height, byte *colorLookupTable);
852  void pgDraw8BppFormatImage(WizRawPixel *bufferPtr, const byte *rawData, int bufferWidth, int bufferHeight, int x, int y, int width, int height, Common::Rect *clipRectPtr, int32 wizFlags, const byte *extraTable, int transparentColor, const WizRawPixel *conversionTable);
853  void pgDraw8BppSimpleBlit(WizSimpleBitmap *destBM, Common::Rect *destRect, WizSimpleBitmap *sourceBM, Common::Rect *sourceRect, const WizRawPixel *conversionTable);
854  void pgDraw8BppTransparentSimpleBlit(WizSimpleBitmap *destBM, Common::Rect *destRect, WizSimpleBitmap *sourceBM, Common::Rect *sourceRect, int transparentColor, const WizRawPixel *conversionTable);
855  void pgDrawImageWith16BitZBuffer(WizSimpleBitmap *psbDst, const WizSimpleBitmap *psbZBuffer, const byte *imgData, int x, int y, int z, int width, int height, Common::Rect *prcClip);
856  void pgForwardRemapPixelCopy(WizRawPixel *dstPtr, const WizRawPixel *srcPtr, int size, const byte *lookupTable);
857  void pgBackwardsRemapPixelCopy(WizRawPixel *dstPtr, const WizRawPixel *srcPtr, int size, const byte *lookupTable);
858  void pgTransparentForwardRemapPixelCopy(WizRawPixel *dstPtr, const WizRawPixel *srcPtr, int size, WizRawPixel transparentColor, const byte *lookupTable);
859  void pgTransparentBackwardsRemapPixelCopy(WizRawPixel *dstPtr, const WizRawPixel *srcPtr, int size, WizRawPixel transparentColor, const byte *lookupTable);
860  void pgForwardMixColorsPixelCopy(WizRawPixel *dstPtr, const WizRawPixel *srcPtr, int size, const byte *lookupTable);
861  void pgBackwardsMixColorsPixelCopy(WizRawPixel *dstPtr, const WizRawPixel *srcPtr, int size, const byte *lookupTable);
862  void pgTransparentForwardMixColorsPixelCopy(WizRawPixel *dstPtr, const WizRawPixel *srcPtr, int size, WizRawPixel transparentColor, const byte *lookupTable);
863  void pgTransparentBackwardsMixColorsPixelCopy(WizRawPixel *dstPtr, const WizRawPixel *srcPtr, int size, WizRawPixel transparentColor, const byte *lookupTable);
864  void pgBlit90DegreeRotate(WizSimpleBitmap *dstBitmap, int x, int y, const WizSimpleBitmap *srcBitmap, const Common::Rect *optionalSrcRect, const Common::Rect *optionalClipRect, bool hFlip, bool vFlip);
865  void pgBlit90DegreeRotateTransparent(WizSimpleBitmap *dstBitmap, int x, int y, const WizSimpleBitmap *srcBitmap, const Common::Rect *optionalSrcRect, const Common::Rect *optionalClipRect, bool hFlip, bool vFlip, WizRawPixel transparentColor);
866  void pgBlit90DegreeRotateCore(WizSimpleBitmap *dstBitmap, int x, int y, const WizSimpleBitmap *srcBitmap, const Common::Rect *optionalSrcRect, const Common::Rect *optionalClipRect, bool hFlip, bool vFlip, const void *userParam, const void *userParam2,
867  void (*srcTransferFP)(Wiz *wiz, WizRawPixel *dstPtr, int dstStep, const WizRawPixel *srcPtr, int count, const void *userParam, const void *userParam2));
868 
869  // Rectangles
870  bool findRectOverlap(Common::Rect *destRectPtr, const Common::Rect *sourceRectPtr);
871  bool isPointInRect(Common::Rect *r, Common::Point *pt);
872  bool isRectValid(Common::Rect r);
873  void makeSizedRectAt(Common::Rect *rectPtr, int x, int y, int width, int height);
874  void makeSizedRect(Common::Rect *rectPtr, int width, int height);
875  void combineRects(Common::Rect *destRect, Common::Rect *ra, Common::Rect *rb);
876  void clipRectCoords(Common::Rect *sourceRectPtr, Common::Rect *destRectPtr, Common::Rect *clipRectPtr);
877  int getRectWidth(Common::Rect *rectPtr);
878  int getRectHeight(Common::Rect *rectPtr);
879  void moveRect(Common::Rect *rectPtr, int dx, int dy);
880  void horzFlipAlignWithRect(Common::Rect *rectToAlign, const Common::Rect *baseRect);
881  void vertFlipAlignWithRect(Common::Rect *rectToAlign, const Common::Rect *baseRect);
882  void swapRectX(Common::Rect *rectPtr);
883  void swapRectY(Common::Rect *rectPtr);
884 
885  // Flood fill
886  void floodInitFloodState(WizFloodState *statePtr, WizSimpleBitmap *bitmapPtr, int colorToWrite, const Common::Rect *optionalClippingRect);
887  WizFloodState *floodCreateFloodState(int numStackElements);
888  void floodDestroyFloodState(WizFloodState *state);
889  bool floodBoundryColorFloodCheckPixel(int x, int y, WizFloodState *state);
890  void floodFloodFillPrim(int x, int y, WizFloodState *statePtr, bool (*checkPixelFnPtr)(Wiz *w, int x, int y, WizFloodState *state));
891  void floodPerformOpOnRect(WizFloodState *statePtr, Common::Rect *rectPtr);
892  bool floodSimpleFill(WizSimpleBitmap *bitmapPtr, int x, int y, int colorToWrite, const Common::Rect *optionalClipRect, Common::Rect *updateRectPtr);
893 
894  // Utils
895  int getRawPixel(int color);
896  void memset8BppConversion(void *dstPtr, int value, size_t count, const WizRawPixel *conversionTable);
897  void memcpy8BppConversion(void *dstPtr, const void *srcPtr, size_t count, const WizRawPixel *conversionTable);
898  void rawPixelMemset(void *dstPtr, int value, size_t count);
899  WizRawPixel convert8BppToRawPixel(WizRawPixel value, const WizRawPixel *conversionTable);
900  void rawPixelExtractComponents(WizRawPixel aPixel, int &r, int &g, int &b);
901  void rawPixelPackComponents(WizRawPixel &aPixel, int r, int g, int b);
902 
903  /*
904  * Compression Primitives
905  */
906 
907  // MRLE
908  void mrleFLIPAltSourceDecompressImage(
909  WizRawPixel *destBufferPtr, const byte *compData, int destBufferWidth, int destBufferHeight,
910  const void *altBufferPtr, int altWidth, int altHeight, int altBitsPerPixel,
911  int x, int y, int width, int height, Common::Rect *clipRectPtr,
912  int32 wizFlags, const WizRawPixel *conversionTable);
913  void mrleFLIPAltSourceDecompressPrim(
914  WizRawPixel *destBufferPtr, int destBufferWidth, int destBufferHeight,
915  const void *altBufferPtr, int altBitsPerPixel,
916  const WizCompressedImage *imagePtr, int destX, int destY,
917  const Common::Rect *sourceCoords, const Common::Rect *clipRectPtr,
918  int32 flags, const WizRawPixel *conversionTable,
919  void (*forewordFunctionPtr)(Wiz *wiz,
920  WizRawPixel *destPtr, const void *altSourcePtr, const byte *dataStream,
921  int skipAmount, int decompAmount, const WizRawPixel *conversionTable),
922  void (*backwardFunctionPtr)(Wiz *wiz,
923  WizRawPixel *destPtr, const void *altSourcePtr, const byte *dataStream,
924  int skipAmount, int decompAmount, const WizRawPixel *conversionTable));
925 
926  // Auxiliary compression routines
927  void auxWRLEUncompressPixelStream(WizRawPixel *destStream, const byte *singleColorTable, const byte *streamData, int streamSize, const WizRawPixel *conversionTable);
928  void auxWRLEUncompressAndCopyFromStreamOffset(WizRawPixel *destStream, const byte *singleColorTable, const byte *streamData, int streamSize, byte copyFromColor, int streamOffset, const WizRawPixel *conversionTable);
929 
930  void auxDecompSRLEStream(WizRawPixel *destStream, const WizRawPixel *backgroundStream, const byte *singleColorTable, const byte *streamData, int streamSize, const WizRawPixel *conversionTable);
931 
932  void auxDecompDRLEStream(WizRawPixel *destPtr, const byte *dataStream, WizRawPixel *backgroundPtr, int skipAmount, int decompAmount, const WizRawPixel *conversionTable);
933  void auxDecompDRLEImage(WizRawPixel *foregroundBufferPtr, WizRawPixel *backgroundBufferPtr, const byte *compData, int bufferWidth, int bufferHeight, int x, int y, int width, int height, Common::Rect *clipRectPtr, const WizRawPixel *conversionTable);
934  void auxDecompDRLEPrim(WizRawPixel *foregroundBufferPtr, WizRawPixel *backgroundBufferPtr, int bufferWidth, Common::Rect *destRect, const byte *compData, Common::Rect *sourceRect, const WizRawPixel *conversionTable);
935 
936  void auxDecompTRLEStream(WizRawPixel *destPtr, const byte *dataStream, int skipAmount, int decompAmount, const WizRawPixel *conversionTable);
937  void auxDecompTRLEImage(WizRawPixel *bufferPtr, const byte *compData, int bufferWidth, int bufferHeight, int x, int y, int width, int height, Common::Rect *clipRectPtr, const WizRawPixel *conversionTable);
938  void auxDecompTRLEPrim(WizRawPixel *bufferPtr, int bufferWidth, Common::Rect *destRect, const byte *compData, Common::Rect *sourceRect, const WizRawPixel *conversionTable);
939  void auxDrawZplaneFromTRLEImage(byte *zplanePtr, const byte *compData, int zplanePixelWidth, int zplanePixelHeight, int x, int y, int width, int height, Common::Rect *clipRectPtr, int transOp, int solidOp);
940  void auxDrawZplaneFromTRLEPrim(byte *zplanePtr, int zplanePixelWidth, Common::Rect *destRect, const byte *compData, Common::Rect *sourceRect, int transOp, int solidOp);
941 
942  void auxDecompRemappedTRLEStream(WizRawPixel *destPtr, const byte *dataStream, int skipAmount, int decompAmount, byte *remapTable, const WizRawPixel *conversionTable);
943  void auxDecompRemappedTRLEImage(WizRawPixel *bufferPtr, const byte *compData, int bufferWidth, int bufferHeight, int x, int y, int width, int height, Common::Rect *clipRectPtr, byte *remapTable, const WizRawPixel *conversionTable);
944  void auxDecompRemappedTRLEPrim(WizRawPixel *bufferPtr, int bufferWidth, Common::Rect *destRect, const byte *compData, Common::Rect *sourceRect, byte *remapTable, const WizRawPixel *conversionTable);
945 
946  int auxHitTestTRLEXPos(const byte *dataStream, int skipAmount);
947  int auxHitTestTRLEImageRelPos(const byte *compData, int x, int y, int width, int height);
948  int auxPixelHitTestTRLEXPos(byte *dataStream, int skipAmount, int transparentValue);
949  int auxPixelHitTestTRLEImageRelPos(byte *compData, int x, int y, int width, int height, int transparentValue);
950 
951  void auxDecompMixColorsTRLEImage(WizRawPixel *bufferPtr, byte *compData, int bufferWidth, int bufferHeight, int x, int y, int width, int height, Common::Rect *clipRectPtr, const byte *colorMixTable, const WizRawPixel *conversionTable);
952  void auxDecompMixColorsTRLEPrim(WizRawPixel *bufferPtr, int bufferWidth, Common::Rect *destRect, const byte *compData, Common::Rect *sourceRect, const byte *coloMixTable, const WizRawPixel *conversionTable);
953  void auxColorMixDecompressLine(
954  WizRawPixel *destPtr, const byte *dataStream, int skipAmount,
955  int decompAmount, const byte *colorMixTable,
956  const WizRawPixel *conversionTable);
957 
958  void auxRemappedMemcpy(
959  WizRawPixel *dstPtr, const byte *srcPtr, int count, byte *remapTable,
960  const WizRawPixel *conversionTable);
961 
962  void auxZplaneFromTRLEStream(
963  byte *destPtr, const byte *dataStream, int skipAmount, int decompAmount,
964  int mask, int transOp, int solidOp);
965 
966  void auxHistogramTRLELine(int *tablePtr, const byte *dataStream, int skipAmount, int decompAmount);
967  void auxHistogramTRLEPrim(int *histogramTablePtr, byte *compData, Common::Rect *sourceRect);
968 
969  // TRLE
970  int _trlePutSize = 0;
971  byte _trleBuf[(128 * 2) * sizeof(WizRawPixel)] = {};
972 
973  byte *trlePutDump(byte *dest, int nn);
974  byte *trlePutRun(byte *dest, int nn, int cc, int tcolor);
975  int trleRLECompression(byte *pdest, const WizRawPixel *psource, int rowsize, WizRawPixel tcolor);
976  int trleCompressImageArea(byte *destBuffer, const WizRawPixel *sourceBuffer, int sourceBufferWidth, int x1, int y1, int x2, int y2, WizRawPixel transparentColor);
977 
978  // TRLE FLIP
979  bool _initializeAlphaTable = true;
980  float _alphaTable[256] = {};
981  int _precomputed16bppTable[WIZ_QUANTIZED_ALPHA_COUNT][WIZ_COLOR16_COMPONENT_COUNT][WIZ_COLOR16_COMPONENT_COUNT] = { {}, {}, {} };
982 
983  void trleFLIPDecompressImage(
984  WizRawPixel *bufferPtr, const byte *compData, int bufferWidth, int bufferHeight,
985  int x, int y, int width, int height, Common::Rect *clipRectPtr,
986  int32 wizFlags, const byte *extraTable, const WizRawPixel *conversionTable,
987  const WizImageCommand *optionalICmdPtr);
988 
989  void trleFLIPDecompressPrim(
990  WizSimpleBitmap *bitmapPtr, const WizCompressedImage *imagePtr, int destX, int destY,
991  const Common::Rect *sourceCoords, const Common::Rect *clipRectPtr, const byte *extraPtr,
992  int32 flags, const WizRawPixel *conversionTable,
993  void (*forewordFunctionPtr)(Wiz *wiz,
994  WizRawPixel *destPtr, const byte *dataStream, int skipAmount,
995  int decompAmount, const byte *extraPtr, const WizRawPixel *conversionTable),
996  void (*backwardFunctionPtr)(Wiz *wiz,
997  WizRawPixel *destPtr, const byte *dataStream, int skipAmount,
998  int decompAmount, const byte *extraPtr, const WizRawPixel *conversionTable));
999 
1000  void trleFLIPDecompImageHull(
1001  WizRawPixel *bufferPtr, int bufferWidth, const Common::Rect *destRect,
1002  const byte *compData, const Common::Rect *sourceRect, const byte *extraPtr,
1003  const WizRawPixel *conversionTable,
1004  void (*functionPtr)(Wiz *wiz,
1005  WizRawPixel *destPtr, const byte *dataStream, int skipAmount,
1006  int decompAmount, const byte *extraPtr, const WizRawPixel *conversionTable));
1007 
1008  void trleFLIPAltSourceDecompressImage(
1009  WizRawPixel *destBufferPtr, const byte *compData, int destBufferWidth, int destBufferHeight,
1010  const void *altBufferPtr, int altWidth, int altHeight, int altBitsPerPixel,
1011  int x, int y, int width, int height, Common::Rect *clipRectPtr,
1012  int32 wizFlags, const WizRawPixel *conversionTable,
1013  WizImageCommand *optionalICmdPtr);
1014 
1015  void trleFLIPAltSourceDecompressPrim(
1016  WizRawPixel *destBufferPtr, int destBufferWidth, int destBufferHeight,
1017  const void *altBufferPtr, int altBitsPerPixel,
1018  const WizCompressedImage *imagePtr, int destX, int destY,
1019  const Common::Rect *sourceCoords, const Common::Rect *clipRectPtr,
1020  int32 flags, const WizRawPixel *conversionTable,
1021  void (*forewordFunctionPtr)(Wiz *wiz,
1022  WizRawPixel *destPtr, const void *altSourcePtr, const byte *dataStream,
1023  int skipAmount, int decompAmount, const WizRawPixel *conversionTable),
1024  void (*backwardFunctionPtr)(Wiz *wiz,
1025  WizRawPixel *destPtr, const void *altSourcePtr, const byte *dataStream,
1026  int skipAmount, int decompAmount, const WizRawPixel *conversionTable));
1027 
1028  void trleFLIPAltSourceDecompImageHull(
1029  WizRawPixel *bufferPtr, int bufferWidth, const Common::Rect *destRect,
1030  const byte *altSourceBuffer, int altBytesPerLine,
1031  int altBytesPerPixel, const Common::Rect *altRect,
1032  const byte *compData, const Common::Rect *sourceRect,
1033  const WizRawPixel *conversionTable,
1034  void (*functionPtr)(Wiz *wiz,
1035  WizRawPixel *destPtr, const void *altSourcePtr, const byte *dataStream,
1036  int skipAmount, int decompAmount, const WizRawPixel *conversionTable));
1037 
1038  bool trleFLIPAltSourceSpecialCaseDispatch(
1039  WizRawPixel *destBufferPtr, const byte *compData, int destBufferWidth, int destBufferHeight,
1040  const void *altBufferPtr, int altWidth, int altHeight, int altBitsPerPixel,
1041  int x, int y, int width, int height, Common::Rect *clipRectPtr,
1042  int32 wizFlags, const WizRawPixel *conversionTable,
1043  WizImageCommand *optionalICmdPtr);
1044 
1045  void trleFLIPRotate90DecompressImage(
1046  WizRawPixel *bufferPtr, const byte *compData, int bufferWidth, int bufferHeight,
1047  int x, int y, int width, int height, const Common::Rect *clipRectPtr,
1048  int32 wizFlags, const void *extraTable, const WizRawPixel *conversionTable,
1049  WizImageCommand *optionalICmdPtr);
1050 
1051  void trleFLIP90DegreeRotateCore(
1052  WizSimpleBitmap *dstBitmap, int x, int y, const WizCompressedImage *imagePtr, const Common::Rect *optionalSrcRect,
1053  const Common::Rect *optionalClipRect, bool hFlip, bool vFlip, const void *userParam, const WizRawPixel *conversionTable,
1054  void (*functionPtr)(Wiz *wiz,
1055  WizRawPixel *destPtr, const byte *dataStream, int skipAmount,
1056  int decompAmount, const void *userParam, int destStepValue,
1057  const WizRawPixel *conversionTable));
1058 
1059  void trleFLIPCheckAlphaSetup();
1060  WizRawPixel trleFLIPAlphaMixPrim(WizRawPixel b, WizRawPixel a, int alpha);
1061  void trleFLIPFiftyFiftyMixPixelMemset(WizRawPixel *dstPtr, WizRawPixel mixColor, int size);
1062  void trleFLIPFiftyFiftyMixForwardPixelCopy(WizRawPixel *dstPtr, const byte *srcPtr, int size, const WizRawPixel *conversionTable);
1063  void trleFLIPFiftyFiftyMixBackwardsPixelCopy(WizRawPixel *dstPtr, const byte *srcPtr, int size, const WizRawPixel *conversionTable);
1064  void trleFLIPAdditivePixelMemset(WizRawPixel *dstPtr, WizRawPixel mixColor, int size);
1065  void trleFLIPAdditiveForwardPixelCopy(WizRawPixel *dstPtr, const byte *srcPtr, int size, const WizRawPixel *conversionTable);
1066  void trleFLIPAdditiveBackwardsPixelCopy(WizRawPixel *dstPtr, const byte *srcPtr, int size, const WizRawPixel *conversionTable);
1067  void trleFLIPSubtractivePixelMemset(WizRawPixel *dstPtr, WizRawPixel mixColor, int size);
1068  void trleFLIPSubtractiveForwardPixelCopy(WizRawPixel *dstPtr, const byte *srcPtr, int size, const WizRawPixel *conversionTable);
1069  void trleFLIPSubtractiveBackwardsPixelCopy(WizRawPixel *dstPtr, const byte *srcPtr, int size, const WizRawPixel *conversionTable);
1070  void trleFLIPRemapDestPixels(WizRawPixel *dstPtr, int size, const byte *lookupTable);
1071  void trleFLIPForwardPixelCopy(WizRawPixel *dstPtr, const byte *srcPtr, int size, const WizRawPixel *conversionTable);
1072  void trleFLIPBackwardsPixelCopy(WizRawPixel *dstPtr, const byte *srcPtr, int size, const WizRawPixel *conversionTable);
1073  void trleFLIPForwardLookupPixelCopy(WizRawPixel *dstPtr, const byte *srcPtr, int size, const byte *lookupTable, const WizRawPixel *conversionTable);
1074  void trleFLIPBackwardsLookupPixelCopy(WizRawPixel *dstPtr, const byte *srcPtr, int size, const byte *lookupTable, const WizRawPixel *conversionTable);
1075  void trleFLIPForwardMixColorsPixelCopy(WizRawPixel *dstPtr, const byte *srcPtr, int size, const byte *lookupTable);
1076  void trleFLIPBackwardsMixColorsPixelCopy(WizRawPixel *dstPtr, const byte *srcPtr, int size, const byte *lookupTable);
1077 
1078 
1079  /*
1080  * Image Warping on Polygons Primitives
1081  */
1082 
1083  bool warpDrawWiz(int image, int state, int polygon, int32 flags, int transparentColor, WizSimpleBitmap *optionalDestBitmap, const WizRawPixel *optionalColorConversionTable, int shadowImage);
1084  bool warpDrawWizTo4Points(int image, int state, const WarpWizPoint *dstPoints, int32 flags, int transparentColor, const Common::Rect *optionalClipRect, WizSimpleBitmap *optionalDestBitmap, const WizRawPixel *optionalColorConversionTable, const byte *colorMixTable);
1085  WarpWizOneSpanTable *warpCreateSpanTable(int spanCount);
1086  void warpDestroySpanTable(WarpWizOneSpanTable *spanTable);
1087  WarpWizOneSpanTable *warpBuildSpanTable(WizSimpleBitmap *dstBitmap, const WizSimpleBitmap *srcBitmap, const WarpWizPoint *dstPts, const WarpWizPoint *srcPts, int npoints, const Common::Rect *clipRectPtr);
1088  void warpProcessDrawSpansA(WizSimpleBitmap *dstBitmap, const WizSimpleBitmap *srcBitmap, const WarpWizOneDrawSpan *drawSpans, int count);
1089  void warpProcessDrawSpansTransparent(WizSimpleBitmap *dstBitmap, const WizSimpleBitmap *srcBitmap, const WarpWizOneDrawSpan *drawSpans, int count, WizRawPixel transparentColor);
1090  void warpProcessDrawSpansTransparentFiltered(WizSimpleBitmap *dstBitmap, const WizSimpleBitmap *srcBitmap, const WarpWizOneDrawSpan *drawSpans, int count, WizRawPixel transparentColor, const byte *pXmapColorTable, bool bIsHintColor, WizRawPixel hintColor);
1091  void warpProcessDrawSpansMixColors(WizSimpleBitmap *dstBitmap, const WizSimpleBitmap *srcBitmap, const WarpWizOneDrawSpan *drawSpans, int count, WizRawPixel transparentColor, const byte *tablePtr);
1092  void warpFillSpanWithLine(WarpWizOneSpanTable *st, const WarpWizPoint *dstA, const WarpWizPoint *dstB, const WarpWizPoint *srcA, const WarpWizPoint *srcB);
1093  void warpProcessDrawSpansSampled(WizSimpleBitmap *dstBitmap, const WizSimpleBitmap *srcBitmap, const WarpWizOneDrawSpan *drawSpans, int count);
1094  void warpProcessDrawSpansTransparentSampled(WizSimpleBitmap *dstBitmap, const WizSimpleBitmap *srcBitmap,const WarpWizOneDrawSpan *drawSpans, int count, WizRawPixel transparentColor);
1095  bool warpNPt2NPtWarpCORE(WizSimpleBitmap *dstBitmap, const WarpWizPoint *dstpoints, const WizSimpleBitmap *srcBitmap, const WarpWizPoint *srcpoints, int npoints, int transparentColor, const Common::Rect *optionalClipRect, int32 wizFlags);
1096  bool warpNPt2NPtNonClippedWarp(WizSimpleBitmap *dstBitmap, const WarpWizPoint *dstpoints, const WizSimpleBitmap *srcBitmap, const WarpWizPoint *srcpoints, int npoints, int transparentColor);
1097  bool warpNPt2NPtClippedWarp(WizSimpleBitmap *dstBitmap, const WarpWizPoint *dstpoints, const WizSimpleBitmap *srcBitmap, const WarpWizPoint *srcpoints, int npoints, int transparentColor, const Common::Rect *optionalClipRect);
1098  bool warpNPt2NPtClippedWarpMixColors(WizSimpleBitmap *dstBitmap, const WarpWizPoint *dstpoints, const WizSimpleBitmap *srcBitmap, const WarpWizPoint *srcpoints, int npoints, int transparentColor, const Common::Rect *optionalClipRect, const byte *colorMixTable);
1099  bool warpNPt2NPtNonClippedWarpFiltered(WizSimpleBitmap *dstBitmap, const WarpWizPoint *dstpoints, const WizSimpleBitmap *srcBitmap, const WarpWizPoint *srcpoints, int npoints, int transparentColor, const byte *pXmapColorTable, bool bIsHintColor, WizRawPixel hintColor);
1100  void warpFindMinMaxpoints(WarpWizPoint *minPtr, WarpWizPoint *maxPtr, const WarpWizPoint *points, int npoints);
1101 };
1102 
1103 } // End of namespace Scumm
1104 
1105 #endif
#define ARRAYSIZE(x)
Definition: util.h:93
Definition: str.h:59
Definition: surface.h:67
Definition: array.h:52
int16 right
Definition: rect.h:146
iterator end()
Definition: array.h:379
iterator begin()
Definition: array.h:374
In find(In first, In last, const T &v)
Definition: algorithm.h:225
T * iterator
Definition: array.h:54
Definition: rect.h:144
Definition: stream.h:745
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
void push_back(const T &element)
Definition: array.h:180
void debug(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: algorithm.h:29
Definition: rect.h:45
DBCSString operator+(const DBCSString &x, const DBCSString &y)
int16 left
Definition: rect.h:145
Out move(In first, In last, Out dst)
Definition: algorithm.h:109
int16 x
Definition: rect.h:46
int16 y
Definition: rect.h:47
RivenScriptPtr & operator+=(RivenScriptPtr &lhs, const RivenScriptPtr &rhs)
Definition: actor.h:30
iterator erase(iterator pos)
Definition: array.h:328