tinsel: endianess fix Discworld PSX palette remapper

svn-id: r40876
This commit is contained in:
Fabio Battaglia 2009-05-25 06:09:48 +00:00
parent 6982ce53c2
commit 910f43ffd8
3 changed files with 11 additions and 9 deletions

View File

@ -770,7 +770,7 @@ void DrawObject(DRAWOBJECT *pObj) {
break;
case 0x44: // PSX 4-bit CLUT
memset(psxMapperTable, 0, 16);
psxPaletteMapper(pObj->pPal, (uint16*)(srcPtr + sizeof(uint16)), psxMapperTable);
psxPaletteMapper(pObj->pPal, srcPtr + sizeof(uint16), psxMapperTable);
psxFourBitClut = true;
psxSkipBytes = READ_LE_UINT32(p + sizeof(uint32) * 5) << 4; // Fetch number of bytes we have to skip

View File

@ -94,26 +94,28 @@ static int maxDACQ = 0;
/**
* Map PSX palettes to original palette from resource file
*/
void psxPaletteMapper(PALQ *originalPal, uint16 *psxClut, byte *mapperTable) {
void psxPaletteMapper(PALQ *originalPal, uint8 *psxClut, byte *mapperTable) {
PALETTE *pal = (PALETTE *)LockMem(originalPal->hPal);
bool colorFound = false;
uint16 clutEntry = 0;
for (int j = 0; j < 16; j++) {
if(!(psxClut[j] & 0x8000)) {
clutEntry = READ_LE_UINT16(psxClut + (sizeof(uint16) * j));
if(clutEntry) {
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]) {
if (psxEquivalent == clutEntry) {
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;
if(clutEntry == 0x7EC0 && !colorFound) mapperTable[j] = 197;
colorFound = false;
} else {
mapperTable[j] = 0;

View File

@ -39,9 +39,9 @@ typedef uint32 COLORREF;
#define TINSEL_GetGValue(rgb) ((uint8)(((uint16)(FROM_LE_32(rgb))) >> 8))
#define TINSEL_GetBValue(rgb) ((uint8)((FROM_LE_32(rgb))>>16))
#define PSXGetRValue(rgb) (FROM_LE_32(rgb) & 0x000000f8)
#define PSXGetGValue(rgb) (FROM_LE_32((rgb) >> 8) & 0x000000f8)
#define PSXGetBValue(rgb) (FROM_LE_32((rgb) >> 16) & 0x000000f8)
#define PSXGetRValue(rgb) ((uint8)(FROM_LE_32(rgb) & 0x000000f8))
#define PSXGetGValue(rgb) ((uint8)(FROM_LE_32((rgb) >> 8) & 0x000000f8))
#define PSXGetBValue(rgb) ((uint8)(FROM_LE_32((rgb) >> 16) & 0x000000f8))
enum {
MAX_COLOURS = 256, //!< maximum number of colours - for VGA 256
@ -111,7 +111,7 @@ void ResetPalAllocator(void); // wipe out all palettes
void PaletteStats(void); // Shows the maximum number of palettes used at once
#endif
void psxPaletteMapper(PALQ *originalPal, uint16 *psxClut, byte *mapperTable); // Maps PSX CLUTs to original palette in resource file
void psxPaletteMapper(PALQ *originalPal, uint8 *psxClut, byte *mapperTable); // Maps PSX CLUTs to original palette in resource file
void PalettesToVideoDAC(void); // Update the video DAC with palettes currently the the DAC queue