ScummVM API documentation
celobj32.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 SCI_GRAPHICS_CELOBJ32_H
23 #define SCI_GRAPHICS_CELOBJ32_H
24 
25 #include "common/rational.h"
26 #include "common/rect.h"
27 #include "sci/resource/resource.h"
28 #include "sci/engine/vm_types.h"
29 #include "sci/util.h"
30 
31 namespace Sci {
32 typedef Common::Rational Ratio;
33 
34 // SCI32 has four different coordinate systems:
35 // 1. low resolution, 2. game/script resolution, 3. text/bitmap resolution,
36 // 4. screen resolution
37 //
38 // In CelObj, these values are used when there is no baked in resolution of
39 // cels.
40 //
41 // In ScreenItem, it is used when deciding which path to take to calculate
42 // dimensions.
43 enum {
44  kLowResX = 320,
45  kLowResY = 200
46 };
47 
48 enum CelType {
49  kCelTypeView = 0,
50  kCelTypePic = 1,
51  kCelTypeMem = 2,
52  kCelTypeColor = 3
53 };
54 
55 enum CelCompressionType {
56  kCelCompressionNone = 0,
57  kCelCompressionRLE = 138,
58  kCelCompressionInvalid = 1000
59 };
60 
64 struct CelInfo32 {
68  CelType type;
69 
73  GuiResourceId resourceId;
74 
78  int16 loopNo;
79 
84  int16 celNo;
85 
91 
95  uint8 color;
96 
97  CelInfo32() :
98  // In SSCI, color is left uninitialised
99  type(kCelTypeMem),
100  resourceId(0),
101  loopNo(0),
102  celNo(0),
103  bitmap(NULL_REG),
104  color(0) {}
105 
106  // This is the equivalence criteria used by CelObj::searchCache in at least
107  // SSCI SQ6. Notably, it does not check the color field.
108  inline bool operator==(const CelInfo32 &other) {
109  return (
110  type == other.type &&
111  resourceId == other.resourceId &&
112  loopNo == other.loopNo &&
113  celNo == other.celNo &&
114  bitmap == other.bitmap
115  );
116  }
117 
118  inline bool operator!=(const CelInfo32 &other) {
119  return !(*this == other);
120  }
121 
122  inline Common::String toString() const {
123  switch (type) {
124  case kCelTypeView:
125  return Common::String::format("view %u, loop %d, cel %d", resourceId, loopNo, celNo);
126  case kCelTypePic:
127  return Common::String::format("pic %u, cel %d", resourceId, celNo);
128  case kCelTypeColor:
129  return Common::String::format("color %d", color);
130  case kCelTypeMem:
131  return Common::String::format("mem %04x:%04x", PRINT_REG(bitmap));
132  default:
133  return Common::String::format("unknown cel type: %d", type);
134  }
135  }
136 };
137 
138 class CelObj;
144  int id;
146  CelCacheEntry() : id(0) {}
147 };
148 
150 
151 #pragma mark -
152 #pragma mark CelScaler
153 
154 enum {
159 };
160 
167  int valuesX[kCelScalerTableSize];
168 
172  Ratio scaleX;
173 
179  int valuesY[kCelScalerTableSize];
180 
184  Ratio scaleY;
185 };
186 
187 class CelScaler {
191  CelScalerTable _scaleTables[2];
192 
196  int _activeIndex;
197 
203  void activateScaleTables(const Ratio &scaleX, const Ratio &scaleY);
204 
210  void buildLookupTable(int *table, const Ratio &ratio, const int size);
211 
212 public:
213  CelScaler() :
214  _scaleTables(),
215  _activeIndex(0) {
216  CelScalerTable &table = _scaleTables[0];
217  table.scaleX = Ratio();
218  table.scaleY = Ratio();
219  for (int i = 0; i < ARRAYSIZE(table.valuesX); ++i) {
220  table.valuesX[i] = i;
221  table.valuesY[i] = i;
222  }
223  for (int i = 1; i < ARRAYSIZE(_scaleTables); ++i) {
224  _scaleTables[i] = _scaleTables[0];
225  }
226  }
227 
231  const CelScalerTable &getScalerTable(const Ratio &scaleX, const Ratio &scaleY);
232 };
233 
234 #pragma mark -
235 #pragma mark CelObj
236 
237 class ScreenItem;
242 class CelObj {
243 protected:
252  static bool _drawBlackLines;
253 
261 
262 public:
263  static CelScaler *_scaler;
264 
271 
276 
282 
286  uint16 _width, _height;
287 
293 
304  uint16 _xResolution, _yResolution;
305 
310  uint8 _skipColor;
311 
317 
321  CelCompressionType _compressionType;
322 
326  bool _remap;
327 
333  bool _mirrorX;
334 
340 
344  static void init();
345 
349  static void deinit();
350 
351  virtual ~CelObj() {};
352 
358  void draw(Buffer &target, const ScreenItem &screenItem, const Common::Rect &targetRect) const;
359 
369  virtual void draw(Buffer &target, const ScreenItem &screenItem, const Common::Rect &targetRect, const bool mirrorX);
370 
380  virtual void draw(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition, const bool mirrorX);
381 
387  void drawTo(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition, const Ratio &scaleX, const Ratio &scaleY) const;
388 
394  virtual CelObj *duplicate() const = 0;
395 
400  virtual const SciSpan<const byte> getResPointer() const = 0;
401 
406  virtual uint8 readPixel(const uint16 x, const uint16 y, const bool mirrorX) const;
407 
412  void submitPalette() const;
413 
414 #pragma mark -
415 #pragma mark CelObj - Drawing
416 private:
417  template<typename MAPPER, typename SCALER>
418  void render(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition) const;
419 
420  template<typename MAPPER, typename SCALER>
421  void render(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition, const Ratio &scaleX, const Ratio &scaleY) const;
422 
423  void drawHzFlip(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition) const;
424  void drawNoFlip(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition) const;
425  void drawUncompNoFlip(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition) const;
426  void drawUncompHzFlip(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition) const;
427  void scaleDraw(Buffer &target, const Ratio &scaleX, const Ratio &scaleY, const Common::Rect &targetRect, const Common::Point &scaledPosition) const;
428  void scaleDrawUncomp(Buffer &target, const Ratio &scaleX, const Ratio &scaleY, const Common::Rect &targetRect, const Common::Point &scaledPosition) const;
429 
430  void drawHzFlipMap(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition) const;
431  void drawNoFlipMap(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition) const;
432  void drawUncompNoFlipMap(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition) const;
433  void drawUncompHzFlipMap(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition) const;
434  void scaleDrawMap(Buffer &target, const Ratio &scaleX, const Ratio &scaleY, const Common::Rect &targetRect, const Common::Point &scaledPosition) const;
435  void scaleDrawUncompMap(Buffer &target, const Ratio &scaleX, const Ratio &scaleY, const Common::Rect &targetRect, const Common::Point &scaledPosition) const;
436  // SSCI includes versions of the above functions with priority parameters
437  // which are not actually used in SCI32
438 
439  void drawHzFlipNoMD(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition) const;
440  void drawNoFlipNoMD(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition) const;
441  void drawUncompNoFlipNoMD(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition) const;
442  void drawUncompNoFlipNoMDNoSkip(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition) const;
443  void drawUncompHzFlipNoMD(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition) const;
444  void drawUncompHzFlipNoMDNoSkip(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition) const;
445  void scaleDrawNoMD(Buffer &target, const Ratio &scaleX, const Ratio &scaleY, const Common::Rect &targetRect, const Common::Point &scaledPosition) const;
446  void scaleDrawUncompNoMD(Buffer &target, const Ratio &scaleX, const Ratio &scaleY, const Common::Rect &targetRect, const Common::Point &scaledPosition) const;
447  // SSCI includes versions of the above functions with priority parameters
448  // which are not actually used in SCI32
449 
450 #pragma mark -
451 #pragma mark CelObj - Caching
452 protected:
457  static int _nextCacheId;
458 
463  static CelCache *_cache;
464 
471  int searchCache(const CelInfo32 &celInfo, int *nextInsertIndex) const;
472 
476  void putCopyInCache(int index) const;
477 };
478 
479 #pragma mark -
480 #pragma mark CelObjView
481 
486 class CelObjView : public CelObj {
487 private:
492  bool analyzeUncompressedForRemap() const;
493 
498  bool analyzeForRemap() const;
499 
500 public:
501  CelObjView(const GuiResourceId viewId, const int16 loopNo, const int16 celNo);
502  ~CelObjView() override {};
503 
504  using CelObj::draw;
505 
506  static int16 getNumLoops(const GuiResourceId viewId);
507  static int16 getNumCels(const GuiResourceId viewId, const int16 loopNo);
508 
513  void draw(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition, bool mirrorX, const Ratio &scaleX, const Ratio &scaleY);
514 
515  CelObjView *duplicate() const override;
516  const SciSpan<const byte> getResPointer() const override;
517 
518  Common::Point getLinkPosition(const int16 linkId) const;
519 };
520 
521 #pragma mark -
522 #pragma mark CelObjPic
523 
528 class CelObjPic : public CelObj {
529 private:
534  bool analyzeUncompressedForSkip() const;
535 
536 public:
540  uint8 _celCount;
541 
546 
551  int16 _priority;
552 
553  CelObjPic(const GuiResourceId pictureId, const int16 celNo);
554  ~CelObjPic() override {};
555 
556  using CelObj::draw;
557  void draw(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition, const bool mirrorX) override;
558 
559  CelObjPic *duplicate() const override;
560  const SciSpan<const byte> getResPointer() const override;
561 };
562 
563 #pragma mark -
564 #pragma mark CelObjMem
565 
571 class CelObjMem : public CelObj {
572 public:
573  CelObjMem(const reg_t bitmap);
574  ~CelObjMem() override {};
575 
576  CelObjMem *duplicate() const override;
577  const SciSpan<const byte> getResPointer() const override;
578 };
579 
580 #pragma mark -
581 #pragma mark CelObjColor
582 
587 class CelObjColor : public CelObj {
588 public:
589  CelObjColor(const uint8 color, const int16 width, const int16 height);
590  ~CelObjColor() override {};
591 
592  using CelObj::draw;
596  void draw(Buffer &target, const Common::Rect &targetRect) const;
597  void draw(Buffer &target, const ScreenItem &screenItem, const Common::Rect &targetRect, const bool mirrorX) override;
598  void draw(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition, const bool mirrorX) override;
599 
600  CelObjColor *duplicate() const override;
601  const SciSpan<const byte> getResPointer() const override;
602 };
603 
604 } // End of namespace Sci
605 
606 #endif // SCI_GRAPHICS_CELOBJ32_H
#define ARRAYSIZE(x)
Definition: util.h:91
int16 loopNo
Definition: celobj32.h:78
Definition: str.h:59
Definition: celobj32.h:571
bool _transparent
Definition: celobj32.h:316
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
CelInfo32 _info
Definition: celobj32.h:270
static bool _drawBlackLines
Definition: celobj32.h:252
Definition: array.h:52
int valuesX[kCelScalerTableSize]
Definition: celobj32.h:167
bool _mirrorX
Definition: celobj32.h:333
Common::Point _origin
Definition: celobj32.h:292
int valuesY[kCelScalerTableSize]
Definition: celobj32.h:179
Definition: rect.h:144
Ratio scaleY
Definition: celobj32.h:184
uint8 color
Definition: celobj32.h:95
int id
Definition: celobj32.h:144
uint16 _xResolution
Definition: celobj32.h:304
CelType type
Definition: celobj32.h:68
Ratio scaleX
Definition: celobj32.h:172
Definition: celobj32.h:161
Definition: rational.h:40
Definition: ptr.h:572
bool _remap
Definition: celobj32.h:326
Definition: celobj32.h:64
uint32 _hunkPaletteOffset
Definition: celobj32.h:281
static CelCache * _cache
Definition: celobj32.h:463
int16 _priority
Definition: celobj32.h:551
CelCompressionType _compressionType
Definition: celobj32.h:321
Definition: celobj32.h:242
void draw(Buffer &target, const ScreenItem &screenItem, const Common::Rect &targetRect) const
Definition: celobj32.h:187
uint8 _skipColor
Definition: celobj32.h:310
Definition: rect.h:45
int16 celNo
Definition: celobj32.h:84
Definition: console.h:28
Definition: celobj32.h:528
GuiResourceId resourceId
Definition: celobj32.h:73
bool _drawMirrored
Definition: celobj32.h:260
static int _nextCacheId
Definition: celobj32.h:457
Definition: celobj32.h:587
uint32 _celHeaderOffset
Definition: celobj32.h:275
Definition: celobj32.h:139
Definition: display_client.h:113
Definition: screen_item32.h:53
Definition: celobj32.h:158
Common::Point _relativePosition
Definition: celobj32.h:545
reg_t bitmap
Definition: celobj32.h:90
Definition: vm_types.h:39
Definition: celobj32.h:486
uint8 _celCount
Definition: celobj32.h:540
bool _isMacSource
Definition: celobj32.h:339
uint16 _width
Definition: celobj32.h:286