Skip to content

Commit

Permalink
SCI32: Always build scaler tables to the maximum possible size
Browse files Browse the repository at this point in the history
This fixes rendering errors in Torin caused by the scaler table
being cut off early when cels larger than the dimensions of the
screen are scaled.
  • Loading branch information
csnover committed Sep 30, 2016
1 parent 2a27f27 commit 9a64c05
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
19 changes: 7 additions & 12 deletions engines/sci/graphics/celobj32.cpp
Expand Up @@ -35,9 +35,6 @@ namespace Sci {
CelScaler *CelObj::_scaler = nullptr;

void CelScaler::activateScaleTables(const Ratio &scaleX, const Ratio &scaleY) {
const int16 screenWidth = g_sci->_gfxFrameout->getCurrentBuffer().screenWidth;
const int16 screenHeight = g_sci->_gfxFrameout->getCurrentBuffer().screenHeight;

for (int i = 0; i < ARRAYSIZE(_scaleTables); ++i) {
if (_scaleTables[i].scaleX == scaleX && _scaleTables[i].scaleY == scaleY) {
_activeIndex = i;
Expand All @@ -50,14 +47,12 @@ void CelScaler::activateScaleTables(const Ratio &scaleX, const Ratio &scaleY) {
CelScalerTable &table = _scaleTables[i];

if (table.scaleX != scaleX) {
assert(screenWidth <= ARRAYSIZE(table.valuesX));
buildLookupTable(table.valuesX, scaleX, screenWidth);
buildLookupTable(table.valuesX, scaleX, kCelScalerTableSize);
table.scaleX = scaleX;
}

if (table.scaleY != scaleY) {
assert(screenHeight <= ARRAYSIZE(table.valuesY));
buildLookupTable(table.valuesY, scaleY, screenHeight);
buildLookupTable(table.valuesY, scaleY, kCelScalerTableSize);
table.scaleY = scaleY;
}
}
Expand Down Expand Up @@ -164,8 +159,8 @@ struct SCALER_Scale {
const byte *_row;
READER _reader;
int16 _x;
static int16 _valuesX[4096];
static int16 _valuesY[4096];
static int16 _valuesX[kCelScalerTableSize];
static int16 _valuesY[kCelScalerTableSize];

SCALER_Scale(const CelObj &celObj, const Common::Rect &targetRect, const Common::Point &scaledPosition, const Ratio scaleX, const Ratio scaleY) :
_row(nullptr),
Expand Down Expand Up @@ -249,9 +244,9 @@ struct SCALER_Scale {
};

template<bool FLIP, typename READER>
int16 SCALER_Scale<FLIP, READER>::_valuesX[4096];
int16 SCALER_Scale<FLIP, READER>::_valuesX[kCelScalerTableSize];
template<bool FLIP, typename READER>
int16 SCALER_Scale<FLIP, READER>::_valuesY[4096];
int16 SCALER_Scale<FLIP, READER>::_valuesY[kCelScalerTableSize];

#pragma mark -
#pragma mark CelObj - Resource readers
Expand Down Expand Up @@ -283,7 +278,7 @@ struct READER_Uncompressed {
struct READER_Compressed {
private:
const byte *const _resource;
byte _buffer[4096];
byte _buffer[kCelScalerTableSize];
uint32 _controlOffset;
uint32 _dataOffset;
uint32 _uncompressedDataOffset;
Expand Down
11 changes: 9 additions & 2 deletions engines/sci/graphics/celobj32.h
Expand Up @@ -141,13 +141,20 @@ typedef Common::Array<CelCacheEntry> CelCache;
#pragma mark -
#pragma mark CelScaler

enum {
/**
* The maximum size of a row/column of scaled pixel data.
*/
kCelScalerTableSize = 4096
};

struct CelScalerTable {
/**
* A lookup table of indexes that should be used to find
* the correct column to read from the source bitmap
* when drawing a scaled version of the source bitmap.
*/
int valuesX[4096];
int valuesX[kCelScalerTableSize];

/**
* The ratio used to generate the x-values.
Expand All @@ -159,7 +166,7 @@ struct CelScalerTable {
* the correct row to read from a source bitmap when
* drawing a scaled version of the source bitmap.
*/
int valuesY[4096];
int valuesY[kCelScalerTableSize];

/**
* The ratio used to generate the y-values.
Expand Down

0 comments on commit 9a64c05

Please sign in to comment.