aboutsummaryrefslogtreecommitdiff
path: root/engines/tinsel/palette.cpp
diff options
context:
space:
mode:
authorFabio Battaglia2009-05-24 22:10:12 +0000
committerFabio Battaglia2009-05-24 22:10:12 +0000
commiteba025f48f99b1538ebbf71ca5b815e76083b78f (patch)
treec0f11ff5fd2ee8feea5dfe790f02a238d1d205ee /engines/tinsel/palette.cpp
parentc97a1aed74fc54176e0de66fc2b6bbe0767e8de6 (diff)
downloadscummvm-rg350-eba025f48f99b1538ebbf71ca5b815e76083b78f.tar.gz
scummvm-rg350-eba025f48f99b1538ebbf71ca5b815e76083b78f.tar.bz2
scummvm-rg350-eba025f48f99b1538ebbf71ca5b815e76083b78f.zip
tinsel: fix for CLUT palettes in Discworld PSX
svn-id: r40873
Diffstat (limited to 'engines/tinsel/palette.cpp')
-rw-r--r--engines/tinsel/palette.cpp57
1 files changed, 25 insertions, 32 deletions
diff --git a/engines/tinsel/palette.cpp b/engines/tinsel/palette.cpp
index 438624b68c..1c5c69252a 100644
--- a/engines/tinsel/palette.cpp
+++ b/engines/tinsel/palette.cpp
@@ -92,40 +92,33 @@ static int maxDACQ = 0;
#endif
/**
- * Convert Discworld PSX 555 CLUTs to compatible 888 palette
+ * Map PSX palettes to original palette from resource file
*/
-COLORREF* psxClutToRGBPal(uint8 *srcClut, int *colours) {
- uint8 red, green, blue;
- uint16 clutEntry;
- int coloursInPalette = 0;
-
- // Allocate space for the 16 colour destination palette
- COLORREF *dstPal = (COLORREF*)calloc(sizeof(COLORREF), 16);
- memset(dstPal, 0, 16 * sizeof(COLORREF));
-
- for (int idx = 0; idx < 16; idx++) {
- clutEntry = READ_LE_UINT16(srcClut); // Read PSX CLUT entry
- srcClut += sizeof(uint16);
-
- if ((clutEntry == 0) && (coloursInPalette == 0))
- continue;
- else if ((clutEntry == 0) && (coloursInPalette != 0)) {
- *colours = coloursInPalette;
- return dstPal;
- } else
- coloursInPalette++;
-
- // Extract color data
- red = ((clutEntry & 0x1F) * 255) / 31;
- green = (((clutEntry & 0x3E0) >> 5) * 255) / 31;
- blue = (((clutEntry & 0x7C00) >> 10) * 255) / 31;
-
- // Write the palette
- dstPal[idx] = TINSEL_RGB(red, green, blue);
+void psxPaletteMapper(PALQ *originalPal, uint16 *psxClut, byte *mapperTable) {
+ PALETTE *pal = (PALETTE *)LockMem(originalPal->hPal);
+ bool colorFound = false;
+
+ for (int j = 0; j < 16; j++) {
+ if(!(psxClut[j] & 0x8000)) {
+ for (int i = 0; (i < pal->numColours) && !colorFound; i++) {
+ // get R G B values in the same way as psx format converters
+ uint16 psxEquivalent = (uint16)((uint32)(PSXGetRValue(pal->palRGB[i]) >> 3) |
+ ((PSXGetGValue(pal->palRGB[i]) >> 3) << 5) |
+ ((PSXGetBValue(pal->palRGB[i]) >> 3) << 10));
+
+ if (psxEquivalent == psxClut[j]) {
+ mapperTable[j] = i + 1;
+ colorFound = true;
+ }
+ }
+ // FIXME: This is just to hack around a bug that causes some text to appear
+ // black, i still have to find the correct fix for this.
+ if(psxClut[j] == 0x7EC0 && !colorFound) mapperTable[j] = 197;
+ colorFound = false;
+ } else {
+ mapperTable[j] = 0;
+ }
}
-
- *colours = coloursInPalette;
- return dstPal;
}
/**