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
31namespace Sci {
32typedef 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.
43enum {
44 kLowResX = 320,
45 kLowResY = 200
46};
47
48enum CelType {
49 kCelTypeView = 0,
50 kCelTypePic = 1,
51 kCelTypeMem = 2,
52 kCelTypeColor = 3
53};
54
55enum CelCompressionType {
56 kCelCompressionNone = 0,
57 kCelCompressionRLE = 138,
58 kCelCompressionInvalid = 1000
59};
60
64struct 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
138class CelObj;
144 int id;
146 CelCacheEntry() : id(0) {}
147};
148
149typedef Common::Array<CelCacheEntry> CelCache;
150
151#pragma mark -
152#pragma mark CelScaler
153
154enum {
160
168
173
180
185};
186
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
212public:
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
237class ScreenItem;
242class CelObj {
243protected:
252 static bool _drawBlackLines;
253
261
262public:
263 static CelScaler *_scaler;
264
271
276
282
286 uint16 _width, _height;
287
293
304 uint16 _xResolution, _yResolution;
305
311
317
321 CelCompressionType _compressionType;
322
326 bool _remap;
327
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
416private:
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
452protected:
457 static int _nextCacheId;
458
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
486class CelObjView : public CelObj {
487private:
492 bool analyzeUncompressedForRemap() const;
493
498 bool analyzeForRemap() const;
499
500public:
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
528class CelObjPic : public CelObj {
529private:
534 bool analyzeUncompressedForSkip() const;
535
536public:
541
546
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
571class CelObjMem : public CelObj {
572public:
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
587class CelObjColor : public CelObj {
588public:
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
Definition: display_client.h:113
Definition: array.h:52
Definition: rational.h:40
Definition: ptr.h:572
Definition: str.h:59
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: celobj32.h:587
void draw(Buffer &target, const Common::Rect &targetRect) const
const SciSpan< const byte > getResPointer() const override
CelObjColor * duplicate() const override
void draw(Buffer &target, const ScreenItem &screenItem, const Common::Rect &targetRect, const bool mirrorX) override
void draw(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition, const bool mirrorX) override
Definition: celobj32.h:242
int searchCache(const CelInfo32 &celInfo, int *nextInsertIndex) const
static bool _drawBlackLines
Definition: celobj32.h:252
uint32 _hunkPaletteOffset
Definition: celobj32.h:281
bool _remap
Definition: celobj32.h:326
uint32 _celHeaderOffset
Definition: celobj32.h:275
virtual const SciSpan< const byte > getResPointer() const =0
virtual void draw(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition, const bool mirrorX)
uint16 _width
Definition: celobj32.h:286
bool _drawMirrored
Definition: celobj32.h:260
static void init()
void drawTo(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition, const Ratio &scaleX, const Ratio &scaleY) const
uint16 _xResolution
Definition: celobj32.h:304
virtual void draw(Buffer &target, const ScreenItem &screenItem, const Common::Rect &targetRect, const bool mirrorX)
virtual CelObj * duplicate() const =0
uint8 _skipColor
Definition: celobj32.h:310
bool _mirrorX
Definition: celobj32.h:333
bool _transparent
Definition: celobj32.h:316
void putCopyInCache(int index) const
void submitPalette() const
Common::Point _origin
Definition: celobj32.h:292
CelInfo32 _info
Definition: celobj32.h:270
static void deinit()
bool _isMacSource
Definition: celobj32.h:339
void draw(Buffer &target, const ScreenItem &screenItem, const Common::Rect &targetRect) const
static int _nextCacheId
Definition: celobj32.h:457
CelCompressionType _compressionType
Definition: celobj32.h:321
virtual uint8 readPixel(const uint16 x, const uint16 y, const bool mirrorX) const
static CelCache * _cache
Definition: celobj32.h:463
Definition: celobj32.h:571
const SciSpan< const byte > getResPointer() const override
CelObjMem * duplicate() const override
Definition: celobj32.h:528
void draw(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition, const bool mirrorX) override
Common::Point _relativePosition
Definition: celobj32.h:545
uint8 _celCount
Definition: celobj32.h:540
int16 _priority
Definition: celobj32.h:551
CelObjPic * duplicate() const override
const SciSpan< const byte > getResPointer() const override
Definition: celobj32.h:486
void draw(Buffer &target, const Common::Rect &targetRect, const Common::Point &scaledPosition, bool mirrorX, const Ratio &scaleX, const Ratio &scaleY)
CelObjView * duplicate() const override
const SciSpan< const byte > getResPointer() const override
Definition: celobj32.h:187
const CelScalerTable & getScalerTable(const Ratio &scaleX, const Ratio &scaleY)
Definition: util.h:251
Definition: screen_item32.h:53
#define ARRAYSIZE(x)
Definition: util.h:114
Definition: console.h:28
@ kCelScalerTableSize
Definition: celobj32.h:158
Definition: rect.h:144
Definition: rect.h:536
Definition: celobj32.h:139
int id
Definition: celobj32.h:144
Definition: celobj32.h:64
uint8 color
Definition: celobj32.h:95
CelType type
Definition: celobj32.h:68
int16 loopNo
Definition: celobj32.h:78
reg_t bitmap
Definition: celobj32.h:90
GuiResourceId resourceId
Definition: celobj32.h:73
int16 celNo
Definition: celobj32.h:84
Definition: celobj32.h:161
int valuesX[kCelScalerTableSize]
Definition: celobj32.h:167
Ratio scaleY
Definition: celobj32.h:184
int valuesY[kCelScalerTableSize]
Definition: celobj32.h:179
Ratio scaleX
Definition: celobj32.h:172
Definition: vm_types.h:39