IHNM used only 248 colors for game graphics. Top part of the palette

was read from resources. Switching to this scheme fixes magenta outlines
in subtitles.

svn-id: r18935
This commit is contained in:
Eugene Sandulenko 2005-10-05 01:31:46 +00:00
parent c7e8af5e5e
commit 579478a586
7 changed files with 99 additions and 53 deletions

View File

@ -114,7 +114,7 @@ void Anim::playCutaway(int cut, bool fade) {
const Rect rect(width, height);
bgSurface->blit(rect, buf);
_vm->_gfx->setPalette(palette);
_vm->_gfx->setPalette(palette, 0, 248);
free(buf);
free(resourceData);

View File

@ -149,11 +149,17 @@ int Events::handleContinuous(Event *event) {
case kPalEvent:
switch (event->op) {
case kEventBlackToPal:
_vm->_gfx->blackToPal((PalEntry *)event->data, event_pc);
if (_vm->getGameType() == GType_IHNM)
_vm->_gfx->blackToPal((PalEntry *)event->data, event_pc, 0, 248);
else
_vm->_gfx->blackToPal((PalEntry *)event->data, event_pc);
break;
case kEventPalToBlack:
_vm->_gfx->palToBlack((PalEntry *)event->data, event_pc);
if (_vm->getGameType() == GType_IHNM)
_vm->_gfx->palToBlack((PalEntry *)event->data, event_pc, 0, 248);
else
_vm->_gfx->palToBlack((PalEntry *)event->data, event_pc);
break;
default:
break;
@ -232,11 +238,17 @@ int Events::handleImmediate(Event *event) {
case kPalEvent:
switch (event->op) {
case kEventBlackToPal:
_vm->_gfx->blackToPal((PalEntry *)event->data, event_pc);
if (_vm->getGameType() == GType_IHNM)
_vm->_gfx->blackToPal((PalEntry *)event->data, event_pc, 0, 248);
else
_vm->_gfx->blackToPal((PalEntry *)event->data, event_pc);
break;
case kEventPalToBlack:
_vm->_gfx->palToBlack((PalEntry *)event->data, event_pc);
if (_vm->getGameType() == GType_IHNM)
_vm->_gfx->palToBlack((PalEntry *)event->data, event_pc, 0, 248);
else
_vm->_gfx->palToBlack((PalEntry *)event->data, event_pc);
break;
default:
break;
@ -332,7 +344,10 @@ int Events::handleOneShot(Event *event) {
if (event->param == kEvPSetPalette) {
PalEntry *palPointer;
_vm->_scene->getBGPal(palPointer);
_vm->_gfx->setPalette(palPointer);
if (_vm->getGameType() == GType_IHNM)
_vm->_gfx->setPalette(palPointer, 0, 248);
else
_vm->_gfx->setPalette(palPointer);
}
}
}

View File

@ -26,7 +26,10 @@
#include "saga/saga.h"
#include "saga/gfx.h"
#include "saga/interface.h"
#include "saga/resnames.h"
#include "saga/rscfile.h"
#include "saga/scene.h"
#include "saga/stream.h"
#include "common/system.h"
@ -163,14 +166,42 @@ void Surface::transitionDissolve(const byte *sourceBuffer, const Common::Rect &s
}
}
void Gfx::setPalette(const PalEntry *pal) {
void Gfx::initPalette() {
if(_vm->getGameType() != GType_IHNM)
return;
ResourceContext *resourceContext = _vm->_resource->getContext(GAME_RESOURCEFILE);
if (resourceContext == NULL) {
error("Resource::loadGlobalResources() resource context not found");
}
byte *resourcePointer;
size_t resourceLength;
_vm->_resource->loadResource(resourceContext, RID_IHNM_DEFAULT_PALETTE,
resourcePointer, resourceLength);
MemoryReadStream metaS(resourcePointer, resourceLength);
for(int i = 0; i < 256; i++) {
_globalPalette[i].red = metaS.readByte();
_globalPalette[i].green = metaS.readByte();
_globalPalette[i].blue = metaS.readByte();
}
free(resourcePointer);
setPalette(_globalPalette, 0, 256);
}
void Gfx::setPalette(const PalEntry *pal, int from, int numcolors) {
int i;
byte *ppal;
for (i = 0, ppal = _currentPal; i < PAL_ENTRIES; i++, ppal += 4) {
ppal[0] = pal[i].red;
ppal[1] = pal[i].green;
ppal[2] = pal[i].blue;
for (i = 0, ppal = &_currentPal[from * 4]; i < numcolors; i++, ppal += 4) {
ppal[0] = _globalPalette[i].red = pal[i].red;
ppal[1] = _globalPalette[i].green = pal[i].green;
ppal[2] = _globalPalette[i].blue = pal[i].blue;
ppal[3] = 0;
}
@ -188,15 +219,15 @@ void Gfx::setPaletteColor(int n, int r, int g, int b) {
// updates, only update the palette if the color actually changes.
if (_currentPal[4 * n + 0] != r) {
_currentPal[4 * n + 0] = r;
_currentPal[4 * n + 0] = _globalPalette[n].red = r;
update = true;
}
if (_currentPal[4 * n + 1] != g) {
_currentPal[4 * n + 1] = g;
_currentPal[4 * n + 1] = _globalPalette[n].green = g;
update = true;
}
if (_currentPal[4 * n + 2] != b) {
_currentPal[4 * n + 2] = b;
_currentPal[4 * n + 2] = _globalPalette[n].blue = b;
update = true;
}
if (_currentPal[4 * n + 3] != 0) {
@ -219,11 +250,12 @@ void Gfx::getCurrentPal(PalEntry *src_pal) {
}
}
void Gfx::palToBlack(PalEntry *src_pal, double percent) {
void Gfx::palToBlack(PalEntry *srcPal, double percent, int from, int numcolors) {
int i;
//int fade_max = 255;
int new_entry;
byte *ppal;
PalEntry *palE;
double fpercent;
@ -238,7 +270,12 @@ void Gfx::palToBlack(PalEntry *src_pal, double percent) {
// Use the correct percentage change per frame for each palette entry
for (i = 0, ppal = _currentPal; i < PAL_ENTRIES; i++, ppal += 4) {
new_entry = (int)(src_pal[i].red * fpercent);
if (i < from || i >= from + numcolors)
palE = &_globalPalette[i];
else
palE = &srcPal[i];
new_entry = (int)(palE->red * fpercent);
if (new_entry < 0) {
ppal[0] = 0;
@ -246,7 +283,7 @@ void Gfx::palToBlack(PalEntry *src_pal, double percent) {
ppal[0] = (byte) new_entry;
}
new_entry = (int)(src_pal[i].green * fpercent);
new_entry = (int)(palE->green * fpercent);
if (new_entry < 0) {
ppal[1] = 0;
@ -254,7 +291,7 @@ void Gfx::palToBlack(PalEntry *src_pal, double percent) {
ppal[1] = (byte) new_entry;
}
new_entry = (int)(src_pal[i].blue * fpercent);
new_entry = (int)(palE->blue * fpercent);
if (new_entry < 0) {
ppal[2] = 0;
@ -271,16 +308,12 @@ void Gfx::palToBlack(PalEntry *src_pal, double percent) {
_system->setPalette(_currentPal, 0, PAL_ENTRIES);
}
void Gfx::blackToPal(PalEntry *src_pal, double percent) {
void Gfx::blackToPal(PalEntry *srcPal, double percent, int from, int numcolors) {
int new_entry;
double fpercent;
int color_delta;
int best_wdelta = 0;
int best_windex = 0;
int best_bindex = 0;
int best_bdelta = 1000;
byte *ppal;
int i;
PalEntry *palE;
if (percent > 1.0) {
percent = 1.0;
@ -293,15 +326,20 @@ void Gfx::blackToPal(PalEntry *src_pal, double percent) {
// Use the correct percentage change per frame for each palette entry
for (i = 0, ppal = _currentPal; i < PAL_ENTRIES; i++, ppal += 4) {
new_entry = (int)(src_pal[i].red - src_pal[i].red * fpercent);
if (i < from || i >= from + numcolors)
palE = &_globalPalette[i];
else
palE = &srcPal[i];
new_entry = (int)(palE->red - palE->red * fpercent);
if (new_entry < 0) {
ppal[0] = 0;
} else {
ppal[0] = (byte) new_entry;
ppal[0] = (byte)new_entry;
}
new_entry = (int)(src_pal[i].green - src_pal[i].green * fpercent);
new_entry = (int)(palE->green - palE->green * fpercent);
if (new_entry < 0) {
ppal[1] = 0;
@ -309,7 +347,7 @@ void Gfx::blackToPal(PalEntry *src_pal, double percent) {
ppal[1] = (byte) new_entry;
}
new_entry = (int)(src_pal[i].blue - src_pal[i].blue * fpercent);
new_entry = (int)(palE->blue - palE->blue * fpercent);
if (new_entry < 0) {
ppal[2] = 0;
@ -319,25 +357,6 @@ void Gfx::blackToPal(PalEntry *src_pal, double percent) {
ppal[3] = 0;
}
// Find the best white and black color indices again
if (percent >= 1.0) {
for (i = 0, ppal = _currentPal; i < PAL_ENTRIES; i++, ppal += 4) {
color_delta = ppal[0];
color_delta += ppal[1];
color_delta += ppal[2];
if (color_delta < best_bdelta) {
best_bindex = i;
best_bdelta = color_delta;
}
if (color_delta > best_wdelta) {
best_windex = i;
best_wdelta = color_delta;
}
}
}
// Make 256th color black. See bug #1256368
if (_vm->getFeatures() & GF_MAC_RESOURCES && !_vm->_scene->isInIntro())
memset(&_currentPal[255 * 4], 0, 4);

View File

@ -134,11 +134,12 @@ public:
return &_backBuffer;
}
void setPalette(const PalEntry *pal);
void initPalette();
void setPalette(const PalEntry *pal, int from = 0, int numcolors = PAL_ENTRIES);
void setPaletteColor(int n, int r, int g, int b);
void getCurrentPal(PalEntry *src_pal);
void palToBlack(PalEntry *src_pal, double percent);
void blackToPal(PalEntry *src_pal, double percent);
void palToBlack(PalEntry *src_pal, double percent, int from = 0, int numcolors = PAL_ENTRIES);
void blackToPal(PalEntry *src_pal, double percent, int from = 0, int numcolors = PAL_ENTRIES);
void updateCursor() { setCursor(); }
void showCursor(bool state);
@ -149,6 +150,8 @@ private:
byte _currentPal[PAL_ENTRIES * 4];
OSystem *_system;
SagaEngine *_vm;
PalEntry _globalPalette[PAL_ENTRIES];
};
} // End of namespace Saga

View File

@ -47,6 +47,8 @@ namespace Saga {
#define IHNM_OBJ_PROFILE 0x4000
#define RID_IHNM_DEFAULT_PALETTE 1
//actor names
#define ITE_ACTOR_PUZZLE 176

View File

@ -253,7 +253,6 @@ int SagaEngine::init(GameDetector &detector) {
debug(1, "Music disabled.");
}
_render = new Render(this, _system);
if (!_render->initialized()) {
return FAILURE;
@ -270,6 +269,8 @@ int SagaEngine::init(GameDetector &detector) {
_music->setVolume(-1, 1);
_gfx->initPalette();
return SUCCESS;
}

View File

@ -447,7 +447,10 @@ void Scene::changeScene(int16 sceneNumber, int actorsEntrance, SceneTransitionTy
cPal[j].blue = *pal++;
}
free(colors);
_vm->_gfx->setPalette(cPal);
if (_vm->getGameType() == GType_IHNM)
_vm->_gfx->setPalette(cPal, 0, 248);
else
_vm->_gfx->setPalette(cPal);
}
@ -1132,7 +1135,10 @@ void Scene::processSceneResources() {
pal[c].green = *palPtr++;
pal[c].blue = *palPtr++;
}
_vm->_gfx->setPalette(pal);
if (_vm->getGameType() == GType_IHNM)
_vm->_gfx->setPalette(pal, 0, 248);
else
_vm->_gfx->setPalette(pal);
}
break;
default: