SCI32: More work on remapping

applyRemap() has been implemented now, however the end effect is still
not visible
This commit is contained in:
Filippos Karapetis 2016-03-11 07:22:01 +02:00
parent 6b857299a4
commit ea52dc498c
3 changed files with 62 additions and 11 deletions

View File

@ -257,6 +257,7 @@ public:
void cycleAllOff();
void applyAllCycles();
void applyCycles();
const bool *getCyclemap() { return _cycleMap; }
#pragma mark -
#pragma mark Fading

View File

@ -110,7 +110,7 @@ void GfxRemap::updateRemapping() {
#ifdef ENABLE_SCI32
GfxRemap32::GfxRemap32(GfxPalette *palette) {
GfxRemap32::GfxRemap32(GfxPalette32 *palette) : _palette(palette) {
for (int i = 0; i < REMAP_COLOR_COUNT; i++)
_remaps[i] = RemapParams(0, 0, 0, 0, 100, kRemappingNone);
_noMapStart = _noMapCount = 0;
@ -167,20 +167,23 @@ void GfxRemap32::setNoMatchRange(byte from, byte count) {
}
void GfxRemap32::initColorArrays(byte index) {
Palette *curPalette = &g_sci->_gfxPalette32->_sysPalette;
Palette *curPalette = &_palette->_sysPalette;
RemapParams *curRemap = &_remaps[index];
memcpy(curRemap->curColor, curPalette->colors, 236 * sizeof(Color));
memcpy(curRemap->targetColor, curPalette->colors, 236 * sizeof(Color));
}
bool GfxRemap32::updateRemap(byte index) {
bool GfxRemap32::updateRemap(byte index, bool palChanged) {
int result;
RemapParams *curRemap = &_remaps[index];
const Palette *curPalette = &g_sci->_gfxPalette32->_sysPalette;
const Palette *nextPalette = g_sci->_gfxPalette32->getNextPalette();
const Palette *curPalette = &_palette->_sysPalette;
const Palette *nextPalette = _palette->getNextPalette();
bool changed = false;
if (!_update && !palChanged)
return false;
memset(_targetChanged, false, 236);
switch (curRemap->type) {
@ -292,17 +295,63 @@ bool GfxRemap32::updateRemap(byte index) {
}
}
static int colorDistance(Color a, Color b) {
int rDiff = (a.r - b.r) * (a.r - b.r);
int gDiff = (a.g - b.g) * (a.g - b.g);
int bDiff = (a.b - b.b) * (a.b - b.b);
return rDiff + gDiff + bDiff;
}
bool GfxRemap32::applyRemap(byte index) {
// TODO
//warning("applyRemap");
return false;
RemapParams *curRemap = &_remaps[index];
const bool *cycleMap = _palette->getCyclemap();
bool unmappedColors[236];
Color newColors[236];
bool changed = false;
memset(unmappedColors, 236, false);
if (_noMapCount)
memset(unmappedColors + _noMapStart, true, _noMapCount);
for (int i = 0; i < 236; i++) {
if (cycleMap[i])
unmappedColors[i] = true;
}
int curColor = 0;
for (int i = 1; i < 236; i++) {
if (curRemap->colorChanged[i] && !unmappedColors[i])
newColors[curColor++] = curRemap->curColor[i];
}
for (int i = 1; i < 236; i++) {
Color targetColor = curRemap->targetColor[i];
bool colorChanged = curRemap->colorChanged[curRemap->remap[i]];
if (!_targetChanged[i] && !colorChanged)
continue;
if (_targetChanged[i] && colorChanged)
if (curRemap->distance[i] < 100 && colorDistance(targetColor, curRemap->curColor[curRemap->remap[i]]) <= curRemap->distance[i])
continue;
int diff = 0;
int16 result = _palette->matchColor(targetColor.r, targetColor.g, targetColor.b, curRemap->distance[i], diff, unmappedColors);
if (result != -1 && curRemap->remap[i] != result) {
changed = true;
curRemap->remap[i] = result;
curRemap->distance[i] = diff;
}
}
return changed;
}
bool GfxRemap32::remapAllTables(bool palChanged) {
bool changed = false;
for (int i = 0; i < REMAP_COLOR_COUNT; i++) {
changed |= updateRemap(i);
changed |= updateRemap(i, palChanged);
}
_update = false;

View File

@ -108,7 +108,7 @@ struct RemapParams {
class GfxRemap32 {
public:
GfxRemap32(GfxPalette *_palette);
GfxRemap32(GfxPalette32 *palette);
~GfxRemap32() {}
void remapOff(byte color);
@ -120,6 +120,7 @@ public:
bool remapAllTables(bool palChanged);
private:
GfxPalette32 *_palette;
RemapParams _remaps[REMAP_COLOR_COUNT];
bool _update;
byte _noMapStart, _noMapCount;
@ -128,7 +129,7 @@ private:
void initColorArrays(byte index);
bool applyRemap(byte index);
bool updateRemap(byte index);
bool updateRemap(byte index, bool palChanged);
};
#endif