#include #include #include "ivi.h" #include "piestate.h" #include "piepalette.h" #include "rendmode.h" #include "bug.h" #include "fractions.h" #include "screen.h" #define RED_CHROMATICITY 1 #define GREEN_CHROMATICITY 1 #define BLUE_CHROMATICITY 1 uint8 pal_GetNearestColour(uint8 r, uint8 g, uint8 b); void pie_SetColourDefines(void); /* This is how far from the end you want the drawn as the artist intended shades to appear */ #define COLOUR_BALANCE 6 // 3 from the end. (two brighter shades!) /* PC VERSION !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ iColour* psGamePal = NULL; PALETTEENTRY* psWinPal = NULL; uint8 palShades[PALETTE_SIZE * PALETTE_SHADE_LEVEL]; BOOL bPaletteInitialised = FALSE; uint8 colours[16]; /* Look up table for transparency */ /* entry[x][y] tells you what colour to poke in when you're writing x over y */ uint8 transLookup[PALETTE_SIZE][PALETTE_SIZE]; UWORD palette16Bit[PALETTE_SIZE]; //16 bit version of the present palette BOOL pal_Make16BitPalette(void) { iColour* psPal; UDWORD i; UWORD alpha, red,green,blue; BYTE ap = 0, ac = 0, rp = 0, rc = 0, gp = 0, gc = 0, bp = 0, bc = 0; ULONG mask, amask, rmask, gmask, bmask; /* // Cannot convert iof not 16bit mode */ if ( ! screenGetFrontBufferPixelFormatMasks(&amask, &rmask, &gmask, &bmask)) { return FALSE; } // ASSERT((DDPixelFormat->dwRGBBitCount == 16, "make16BitPalette RGB bit count not 16")); psPal = pie_GetGamePal(); /* // Cannot playback if not 16bit mode */ if( screenGetFrontBufferBitDepth() == 16 ) { /* // Find out the RGB type of the surface and tell the codec... */ mask = amask; if(mask!=0) { while(!(mask & 1)) { mask>>=1; ap++; } } while((mask & 1)) { mask>>=1; ac++; } mask = rmask; if(mask!=0) { while(!(mask & 1)) { mask>>=1; rp++; } } while((mask & 1)) { mask>>=1; rc++; } mask = gmask; if(mask!=0) { while(!(mask & 1)) { mask>>=1; gp++; } } while((mask & 1)) { mask>>=1; gc++; } mask = bmask; if(mask!=0) { while(!(mask & 1)) { mask>>=1; bp++; } } while((mask & 1)) { mask>>=1; bc++; } } else { //if not 16 bit use blue 5 only so we know the problem bc = 5; } alpha = 0; for(i=0; i>= (8-ac); red >>= (8-rc); blue >>= (8-bc); green >>= (8-gc); alpha <<= ap; red <<= rp; blue <<= bp; green <<= gp; palette16Bit[i] = alpha + red + green + blue; alpha = 0xff;//alpha = 0xff when i > 0 } return(TRUE); } //************************************************************************* //*** add a new palette //* //* params pal = pointer to palette to add //* //* returns slot number of added palette or -1 if error //* //****** int pal_AddNewPalette(iColour *pal) { // PSX version dos'nt use palettes as such, SetRGBLookup sets up a global palette instead which is generally // just used for colour index to RGB conversions. int i; // int rg; // long entry; // long cardPal[256]; iColour *p; PALETTEENTRY *w; bPaletteInitialised = TRUE; if (psGamePal == NULL) { psGamePal = (iColour*) MALLOC(PALETTE_SIZE * sizeof(iColour)); if (psGamePal == NULL) { DBERROR(("pal_AddNewPalette - Out of memory")); return FALSE; } } if (psWinPal == NULL) { psWinPal = (PALETTEENTRY*) MALLOC(PALETTE_SIZE * sizeof(PALETTEENTRY)); if (psGamePal == NULL) { DBERROR(("pal_AddNewPalette - Out of memory")); return FALSE; } } p = psGamePal; w = psWinPal; for (i=0; i255) seekRed = 255; if(seekGreen >255) seekGreen = 255; if(seekBlue >255) seekBlue = 255; palShades[(numColours * PALETTE_SHADE_LEVEL) + (numShades-COLOUR_BALANCE)] = pal_GetNearestColour((uint8) seekRed, (uint8) seekGreen, (uint8) seekBlue); } } } iColour* pie_GetGamePal(void) { ASSERT((bPaletteInitialised,"pie_GetGamePal, palette not initialised")); return psGamePal; } PALETTEENTRY* pie_GetWinPal(void) { ASSERT((bPaletteInitialised,"pie_GetWinPal, palette not initialised")); return psWinPal; } /* End of PC Version */