Path: blob/master/RSDKv5/RSDK/Graphics/Palette.cpp
1162 views
#include "RSDK/Core/RetroEngine.hpp"12using namespace RSDK;34#if RETRO_REV0U5#include "Legacy/PaletteLegacy.cpp"6#endif78uint16 RSDK::rgb32To16_R[0x100];9uint16 RSDK::rgb32To16_G[0x100];10uint16 RSDK::rgb32To16_B[0x100];1112uint16 RSDK::globalPalette[PALETTE_BANK_COUNT][PALETTE_BANK_SIZE];13uint16 RSDK::activeGlobalRows[PALETTE_BANK_COUNT];14uint16 RSDK::activeStageRows[PALETTE_BANK_COUNT];15uint16 RSDK::stagePalette[PALETTE_BANK_COUNT][PALETTE_BANK_SIZE];1617uint16 RSDK::fullPalette[PALETTE_BANK_COUNT][PALETTE_BANK_SIZE];1819uint8 RSDK::gfxLineBuffer[SCREEN_YSIZE];2021int32 RSDK::maskColor = 0;22#if RETRO_REV0223uint16 *RSDK::tintLookupTable = NULL;24#else25uint16 RSDK::tintLookupTable[0x10000];26#endif2728#if RETRO_REV0229void RSDK::LoadPalette(uint8 bankID, const char *filename, uint16 disabledRows)30{31char fullFilePath[0x80];32sprintf_s(fullFilePath, sizeof(fullFilePath), "Data/Palettes/%s", filename);3334FileInfo info;35InitFileInfo(&info);36if (LoadFile(&info, fullFilePath, FMODE_RB)) {37for (int32 r = 0; r < 0x10; ++r) {38if (!(disabledRows >> r & 1)) {39for (int32 c = 0; c < 0x10; ++c) {40uint8 red = ReadInt8(&info);41uint8 green = ReadInt8(&info);42uint8 blue = ReadInt8(&info);43fullPalette[bankID][(r << 4) + c] = rgb32To16_B[blue] | rgb32To16_G[green] | rgb32To16_R[red];44}45}46else {47Seek_Cur(&info, 0x10 * (3 * sizeof(uint8)));48}49}5051CloseFile(&info);52}53}5455void RSDK::BlendColors(uint8 destBankID, uint32 *srcColorsA, uint32 *srcColorsB, int32 blendAmount, int32 startIndex, int32 count)56{57if (destBankID >= PALETTE_BANK_COUNT || !srcColorsA || !srcColorsB)58return;5960blendAmount = CLAMP(blendAmount, 0x00, 0xFF);6162uint8 blendA = 0xFF - blendAmount;63uint16 *paletteColor = &fullPalette[destBankID][startIndex];64for (int32 i = startIndex; i < startIndex + count; ++i) {65int32 r = blendAmount * ((*srcColorsB >> 0x10) & 0xFF) + blendA * ((*srcColorsA >> 0x10) & 0xFF);66int32 g = blendAmount * ((*srcColorsB >> 0x08) & 0xFF) + blendA * ((*srcColorsA >> 0x08) & 0xFF);67int32 b = blendAmount * ((*srcColorsB >> 0x00) & 0xFF) + blendA * ((*srcColorsA >> 0x00) & 0xFF);6869*paletteColor = PACK_RGB888((uint8)(r >> 8), (uint8)(g >> 8), (uint8)(b >> 8));7071srcColorsA++;72srcColorsB++;73++paletteColor;74}75}76#endif7778void RSDK::SetPaletteFade(uint8 destBankID, uint8 srcBankA, uint8 srcBankB, int16 blendAmount, int32 startIndex, int32 endIndex)79{80if (destBankID >= PALETTE_BANK_COUNT || srcBankA >= PALETTE_BANK_COUNT || srcBankB >= PALETTE_BANK_COUNT)81return;8283blendAmount = CLAMP(blendAmount, 0x00, 0xFF);84endIndex = MIN(endIndex, 0x100);8586if (startIndex >= endIndex)87return;8889uint32 blendA = 0xFF - blendAmount;90uint16 *paletteColor = &fullPalette[destBankID][startIndex];91for (int32 i = startIndex; i <= endIndex; ++i) {92uint32 clrA = GetPaletteEntry(srcBankA, i);93uint32 clrB = GetPaletteEntry(srcBankB, i);9495int32 r = blendAmount * ((clrB >> 0x10) & 0xFF) + blendA * ((clrA >> 0x10) & 0xFF);96int32 g = blendAmount * ((clrB >> 0x08) & 0xFF) + blendA * ((clrA >> 0x08) & 0xFF);97int32 b = blendAmount * ((clrB >> 0x00) & 0xFF) + blendA * ((clrA >> 0x00) & 0xFF);9899*paletteColor = PACK_RGB888((uint8)(r >> 8), (uint8)(g >> 8), (uint8)(b >> 8));100101++paletteColor;102}103}104105