mirror of
https://github.com/libretro/scummvm.git
synced 2025-03-04 09:18:38 +00:00
TSAGE: Changed palette code back to using a byte array
This commit is contained in:
parent
dd6ab8d306
commit
54e6941ec4
@ -1072,11 +1072,7 @@ void PaletteRotation::synchronise(Serialiser &s) {
|
||||
s.syncAsSint32LE(_end);
|
||||
s.syncAsSint32LE(_rotationMode);
|
||||
s.syncAsSint32LE(_duration);
|
||||
for (int i = 0; i < 256; ++i) {
|
||||
s.syncAsByte(_palette[i].r);
|
||||
s.syncAsByte(_palette[i].g);
|
||||
s.syncAsByte(_palette[i].b);
|
||||
}
|
||||
s.syncBytes(&_palette[0], 256 * 3);
|
||||
}
|
||||
|
||||
void PaletteRotation::signal() {
|
||||
@ -1137,17 +1133,17 @@ void PaletteRotation::signal() {
|
||||
if (flag) {
|
||||
int count2 = _currIndex - _start;
|
||||
int count = _end - _currIndex;
|
||||
g_system->getPaletteManager()->setPalette((const byte *)&_palette[_currIndex], _start, count);
|
||||
g_system->getPaletteManager()->setPalette((const byte *)&_palette[_currIndex * 3], _start, count);
|
||||
|
||||
if (count2) {
|
||||
g_system->getPaletteManager()->setPalette((const byte *)&_palette[_start], _start + count, count2);
|
||||
g_system->getPaletteManager()->setPalette((const byte *)&_palette[_start * 3], _start + count, count2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PaletteRotation::remove() {
|
||||
Action *action = _action;
|
||||
g_system->getPaletteManager()->setPalette((const byte *)&_palette[_start], _start, _end - _start);
|
||||
g_system->getPaletteManager()->setPalette((const byte *)&_palette[_start * 3], _start, _end - _start);
|
||||
|
||||
_scenePalette->_listeners.remove(this);
|
||||
|
||||
@ -1162,7 +1158,7 @@ void PaletteRotation::set(ScenePalette *palette, int start, int end, int rotatio
|
||||
_action = action;
|
||||
_scenePalette = palette;
|
||||
|
||||
Common::copy(&palette->_palette[0], &palette->_palette[256], &_palette[0]);
|
||||
Common::copy(&palette->_palette[0], &palette->_palette[256 * 3], &_palette[0]);
|
||||
|
||||
_start = start;
|
||||
_end = end + 1;
|
||||
@ -1200,11 +1196,7 @@ void PaletteFader::synchronise(Serialiser &s) {
|
||||
|
||||
s.syncAsSint16LE(_step);
|
||||
s.syncAsSint16LE(_percent);
|
||||
for (int i = 0; i < 256; ++i) {
|
||||
s.syncAsByte(_palette[i].r);
|
||||
s.syncAsByte(_palette[i].g);
|
||||
s.syncAsByte(_palette[i].b);
|
||||
}
|
||||
s.syncBytes(&_palette[0], 256 * 3);
|
||||
}
|
||||
|
||||
void PaletteFader::signal() {
|
||||
@ -1220,8 +1212,7 @@ void PaletteFader::remove() {
|
||||
// Save of a copy of the object's action, since it will be used after the object is destroyed
|
||||
Action *action = _action;
|
||||
|
||||
for (int i = 0; i < 256; i++)
|
||||
_scenePalette->_palette[i] = _palette[i];
|
||||
Common::copy(&_palette[0], &_palette[256 * 3], &_scenePalette->_palette[0]);
|
||||
_scenePalette->refresh();
|
||||
_scenePalette->_listeners.remove(this);
|
||||
delete this;
|
||||
@ -1234,8 +1225,12 @@ void PaletteFader::remove() {
|
||||
|
||||
ScenePalette::ScenePalette() {
|
||||
// Set a default gradiant range
|
||||
for (int idx = 0; idx < 256; ++idx)
|
||||
_palette[idx].r = _palette[idx].g = _palette[idx].b = idx;
|
||||
byte *palData = &_palette[0];
|
||||
for (int idx = 0; idx < 256; ++idx) {
|
||||
*palData++ = idx;
|
||||
*palData++ = idx;
|
||||
*palData++ = idx;
|
||||
}
|
||||
|
||||
_field412 = 0;
|
||||
}
|
||||
@ -1253,10 +1248,10 @@ bool ScenePalette::loadPalette(int paletteNum) {
|
||||
int palSize = READ_LE_UINT16(palData + 2);
|
||||
assert(palSize <= 256);
|
||||
|
||||
RGB8 *destP = &_palette[palStart];
|
||||
RGB8 *srcP = (RGB8 *)(palData + 6);
|
||||
byte *destP = &_palette[palStart * 3];
|
||||
byte *srcP = palData + 6;
|
||||
|
||||
Common::copy(&srcP[0], &srcP[palSize], destP);
|
||||
Common::copy(&srcP[0], &srcP[palSize * 3], destP);
|
||||
|
||||
DEALLOCATE(palData);
|
||||
return true;
|
||||
@ -1281,7 +1276,7 @@ void ScenePalette::refresh() {
|
||||
* Loads a section of the palette into the game palette
|
||||
*/
|
||||
void ScenePalette::setPalette(int index, int count) {
|
||||
g_system->getPaletteManager()->setPalette((const byte *)&_palette[index], index, count);
|
||||
g_system->getPaletteManager()->setPalette((const byte *)&_palette[index * 3], index, count);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1294,11 +1289,15 @@ void ScenePalette::setPalette(int index, int count) {
|
||||
*/
|
||||
uint8 ScenePalette::indexOf(uint r, uint g, uint b, int threshold) {
|
||||
int palIndex = -1;
|
||||
byte *palData = &_palette[0];
|
||||
|
||||
for (int i = 0; i < 256; ++i) {
|
||||
int rDiff = abs(_palette[i].r - (int)r);
|
||||
int gDiff = abs(_palette[i].g - (int)g);
|
||||
int bDiff = abs(_palette[i].b - (int)b);
|
||||
byte ir = *palData++;
|
||||
byte ig = *palData++;
|
||||
byte ib = *palData++;
|
||||
int rDiff = abs(ir - (int)r);
|
||||
int gDiff = abs(ig - (int)g);
|
||||
int bDiff = abs(ib - (int)b);
|
||||
|
||||
int idxThreshold = rDiff * rDiff + gDiff * gDiff + bDiff * bDiff;
|
||||
if (idxThreshold <= threshold) {
|
||||
@ -1335,14 +1334,14 @@ void ScenePalette::clearListeners() {
|
||||
}
|
||||
|
||||
void ScenePalette::fade(const byte *adjustData, bool fullAdjust, int percent) {
|
||||
RGB8 tempPalette[256];
|
||||
byte tempPalette[256 * 3];
|
||||
|
||||
// Ensure the percent adjustment is within 0 - 100%
|
||||
percent = CLIP(percent, 0, 100);
|
||||
|
||||
for (int palIndex = 0; palIndex < 256; ++palIndex) {
|
||||
const byte *srcP = (const byte *)&_palette[palIndex];
|
||||
byte *destP = (byte *)&tempPalette[palIndex].r;
|
||||
const byte *srcP = (const byte *)&_palette[palIndex * 3];
|
||||
byte *destP = &tempPalette[palIndex * 3];
|
||||
|
||||
for (int rgbIndex = 0; rgbIndex < 3; ++rgbIndex, ++srcP, ++destP) {
|
||||
*destP = *srcP - ((*srcP - adjustData[rgbIndex]) * (100 - percent)) / 100;
|
||||
@ -1368,14 +1367,16 @@ PaletteRotation *ScenePalette::addRotation(int start, int end, int rotationMode,
|
||||
return obj;
|
||||
}
|
||||
|
||||
PaletteFader *ScenePalette::addFader(RGB8 *arrBufferRGB, int palSize, int percent, Action *action) {
|
||||
PaletteFader *ScenePalette::addFader(const byte *arrBufferRGB, int palSize, int percent, Action *action) {
|
||||
PaletteFader *fader = new PaletteFader();
|
||||
fader->_action = action;
|
||||
for (int i = 0; i < 256; i++) {
|
||||
fader->_palette[i] = *arrBufferRGB;
|
||||
for (int i = 0; i < 256 * 3; i += 3) {
|
||||
fader->_palette[i] = *(arrBufferRGB + 0);
|
||||
fader->_palette[i + 1] = *(arrBufferRGB + 1);
|
||||
fader->_palette[i + 2] = *(arrBufferRGB + 2);
|
||||
|
||||
if (palSize > 1)
|
||||
++arrBufferRGB;
|
||||
arrBufferRGB += 3;
|
||||
}
|
||||
|
||||
fader->setPalette(this, percent);
|
||||
@ -1414,11 +1415,7 @@ void ScenePalette::changeBackground(const Rect &bounds, FadeMode fadeMode) {
|
||||
}
|
||||
|
||||
void ScenePalette::synchronise(Serialiser &s) {
|
||||
for (int i = 0; i < 256; ++i) {
|
||||
s.syncAsByte(_palette[i].r);
|
||||
s.syncAsByte(_palette[i].g);
|
||||
s.syncAsByte(_palette[i].b);
|
||||
}
|
||||
s.syncBytes(_palette, 256 * 3);
|
||||
s.syncAsSint32LE(_colors.foreground);
|
||||
s.syncAsSint32LE(_colors.background);
|
||||
|
||||
|
@ -319,7 +319,7 @@ public:
|
||||
|
||||
class PaletteModifierCached: public PaletteModifier {
|
||||
public:
|
||||
RGB8 _palette[256];
|
||||
byte _palette[256 * 3];
|
||||
int _step;
|
||||
int _percent;
|
||||
|
||||
@ -355,7 +355,7 @@ public:
|
||||
|
||||
class PaletteFader: public PaletteModifierCached {
|
||||
public:
|
||||
RGB8 _palette[256];
|
||||
byte _palette[256 * 3];
|
||||
public:
|
||||
virtual Common::String getClassName() { return "PaletteFader"; }
|
||||
virtual void synchronise(Serialiser &s);
|
||||
@ -369,7 +369,7 @@ enum FadeMode {FADEMODE_NONE = 0, FADEMODE_GRADUAL = 1, FADEMODE_IMMEDIATE = 2};
|
||||
|
||||
class ScenePalette : public SavedObject {
|
||||
public:
|
||||
RGB8 _palette[256];
|
||||
byte _palette[256 * 3];
|
||||
GfxColors _colors;
|
||||
SynchronisedList<PaletteModifier *> _listeners;
|
||||
int _field412;
|
||||
@ -393,7 +393,7 @@ public:
|
||||
void clearListeners();
|
||||
void fade(const byte *adjustData, bool fullAdjust, int percent);
|
||||
PaletteRotation *addRotation(int start, int end, int rotationMode, int duration = 0, Action *action = NULL);
|
||||
PaletteFader *addFader(RGB8 *arrBufferRGB, int palSize, int percent, Action *action);
|
||||
PaletteFader *addFader(const byte *arrBufferRGB, int palSize, int percent, Action *action);
|
||||
|
||||
static void changeBackground(const Rect &bounds, FadeMode fadeMode);
|
||||
|
||||
|
@ -1061,10 +1061,10 @@ void GfxManager::fillRect2(int xs, int ys, int width, int height, int color) {
|
||||
*/
|
||||
void GfxManager::setDialogPalette() {
|
||||
// Get the main palette information
|
||||
RGB8 palData[256];
|
||||
byte palData[256 * 3];
|
||||
uint count, start;
|
||||
_vm->_dataManager->getPalette(0, &palData[0], &start, &count);
|
||||
g_system->getPaletteManager()->setPalette((byte *)&palData[0], start, count);
|
||||
g_system->getPaletteManager()->setPalette(&palData[0], start, count);
|
||||
|
||||
// Miscellaneous
|
||||
uint32 white = 0xffffffff;
|
||||
|
@ -356,18 +356,17 @@ void RlbManager::loadIndex() {
|
||||
*
|
||||
* @paletteNum Specefies the palette number
|
||||
*/
|
||||
void RlbManager::getPalette(int paletteNum, RGB8 *palData, uint *startNum, uint *numEntries) {
|
||||
void RlbManager::getPalette(int paletteNum, byte *palData, uint *startNum, uint *numEntries) {
|
||||
// Get the specified palette
|
||||
byte *dataIn = getResource(RES_PALETTE, 0, paletteNum);
|
||||
assert(dataIn);
|
||||
|
||||
*startNum = READ_LE_UINT16(dataIn);
|
||||
*numEntries = READ_LE_UINT16(dataIn + 2);
|
||||
RGB8 *srcPal = (RGB8 *)(dataIn + 6);
|
||||
assert((*startNum < 256) && ((*startNum + *numEntries) <= 256));
|
||||
|
||||
// Copy over the data
|
||||
Common::copy(&srcPal[0], &srcPal[*numEntries], palData);
|
||||
Common::copy(&dataIn[6], &dataIn[6 + *numEntries * 3], palData);
|
||||
|
||||
_memoryManager.deallocate(dataIn);
|
||||
}
|
||||
|
@ -45,16 +45,6 @@ enum ResourceType { RES_LIBRARY, RES_STRIP, RES_IMAGE, RES_PALETTE, RES_VISAGE,
|
||||
RES_FONT, RES_POINTER, RES_BANK, RES_SND_DRIVER, RES_PRIORITY, RES_CONTROL, RES_WALKRGNS,
|
||||
RES_BITMAP, RES_SAVE, RES_SEQUENCE };
|
||||
|
||||
#include "common/pack-start.h" // START STRUCT PACKING
|
||||
|
||||
struct RGB8 {
|
||||
uint8 r;
|
||||
uint8 g;
|
||||
uint8 b;
|
||||
} PACKED_STRUCT;
|
||||
|
||||
#include "common/pack-end.h" // END STRUCT PACKING
|
||||
|
||||
class MemoryHeader {
|
||||
public:
|
||||
uint32 id;
|
||||
@ -165,7 +155,7 @@ public:
|
||||
|
||||
byte *getResource(uint16 id, bool suppressErrors = false);
|
||||
byte *getResource(ResourceType resType, uint16 resNum, uint16 rlbNum, bool suppressErrors = false);
|
||||
void getPalette(int paletteNum, RGB8 *palData, uint *startNum, uint *numEntries);
|
||||
void getPalette(int paletteNum, byte *palData, uint *startNum, uint *numEntries);
|
||||
byte *getSubResource(int resNum, int rlbNum, int index, uint *size);
|
||||
Common::String getMessage(int resNum, int lineNum);
|
||||
};
|
||||
|
@ -1632,9 +1632,8 @@ void Scene9850::postInit(SceneObjectList *OwnerList) {
|
||||
*
|
||||
*--------------------------------------------------------------------------*/
|
||||
void Scene9900::strAction1::signal() {
|
||||
RGB8 mask1, mask2;
|
||||
mask1.r = mask1.g = mask1.b = 0xff;
|
||||
mask2.r = mask2.g = mask2.b = 0;
|
||||
const byte mask1[3] = {0xff, 0xff, 0xff};
|
||||
const byte mask2[3] = {0, 0, 0};
|
||||
|
||||
Scene9900 *scene = (Scene9900 *)_globals->_sceneManager._scene;
|
||||
|
||||
@ -1652,11 +1651,11 @@ void Scene9900::strAction1::signal() {
|
||||
break;
|
||||
case 1:
|
||||
_palette1.getPalette();
|
||||
_globals->_scenePalette.addFader(&mask1, 1, 10, this);
|
||||
_globals->_scenePalette.addFader(&mask1[0], 1, 10, this);
|
||||
break;
|
||||
case 2:
|
||||
_object9.remove();
|
||||
_globals->_scenePalette.addFader(&mask2, 1, 5, this);
|
||||
_globals->_scenePalette.addFader(&mask2[0], 1, 5, this);
|
||||
break;
|
||||
case 3:
|
||||
_globals->_soundHandler.startSound(377, 0, 127);
|
||||
@ -1769,9 +1768,8 @@ void Scene9900::strAction2::dispatch() {
|
||||
}
|
||||
|
||||
void Scene9900::strAction3::signal() {
|
||||
RGB8 mask3, mask4;
|
||||
mask3.r = 0xff; mask3.g = mask3.b = 0;
|
||||
mask4.r = mask4.g = mask4.b = 0;
|
||||
const byte mask3[3] = {0xff, 0, 0};
|
||||
const byte mask4[3] = {0, 0, 0};
|
||||
|
||||
switch (_actionIndex++) {
|
||||
case 0:
|
||||
@ -1780,10 +1778,10 @@ void Scene9900::strAction3::signal() {
|
||||
_globals->_scenePalette.addFader(_palette3._palette, 256, 5, this);
|
||||
break;
|
||||
case 1:
|
||||
_globals->_scenePalette.addFader(&mask3, 1, 10, this);
|
||||
_globals->_scenePalette.addFader(&mask3[0], 1, 10, this);
|
||||
break;
|
||||
case 2:
|
||||
_globals->_scenePalette.addFader(&mask4, 1, 1, this);
|
||||
_globals->_scenePalette.addFader(&mask4[0], 1, 1, this);
|
||||
break;
|
||||
case 3:
|
||||
_palette2.loadPalette(17);
|
||||
|
Loading…
x
Reference in New Issue
Block a user