Path: blob/master/RSDKv5/RSDK/Graphics/Legacy/PaletteLegacy.cpp
1163 views
1// Palettes (as RGB565 Colors)2uint16 RSDK::Legacy::fullPalette[LEGACY_PALETTE_COUNT][LEGACY_PALETTE_COLOR_COUNT];3uint16 *RSDK::Legacy::activePalette = fullPalette[0]; // Ptr to the 256 color set thats active45uint8 RSDK::Legacy::gfxLineBuffer[SCREEN_YSIZE * 2]; // Pointers to active palette6int32 RSDK::Legacy::GFX_LINESIZE = 0;7int32 RSDK::Legacy::GFX_LINESIZE_MINUSONE = 0;8int32 RSDK::Legacy::GFX_LINESIZE_DOUBLE = 0;9int32 RSDK::Legacy::GFX_FRAMEBUFFERSIZE = 0;10int32 RSDK::Legacy::GFX_FBUFFERMINUSONE = 0;1112int32 RSDK::Legacy::fadeMode = 0;13uint8 RSDK::Legacy::fadeA = 0;14uint8 RSDK::Legacy::fadeR = 0;15uint8 RSDK::Legacy::fadeG = 0;16uint8 RSDK::Legacy::fadeB = 0;1718int32 RSDK::Legacy::paletteMode = 1;1920void RSDK::Legacy::LoadPalette(const char *filePath, int32 paletteID, int32 startPaletteIndex, int32 startIndex, int32 endIndex)21{22char fullPath[0x80];2324StrCopy(fullPath, "Data/Palettes/");25StrAdd(fullPath, filePath);2627FileInfo info;28InitFileInfo(&info);2930if (LoadFile(&info, fullPath, FMODE_RB)) {31Seek_Set(&info, 3 * startIndex);3233if (paletteID >= LEGACY_PALETTE_COUNT || paletteID < 0)34paletteID = 0;3536uint8 color[3];37if (paletteID) {38for (int32 i = startIndex; i < endIndex; ++i) {39ReadBytes(&info, &color, 3);40SetPaletteEntry(paletteID, startPaletteIndex++, color[0], color[1], color[2]);41}42}43else {44for (int32 i = startIndex; i < endIndex; ++i) {45ReadBytes(&info, &color, 3);46SetPaletteEntry(-1, startPaletteIndex++, color[0], color[1], color[2]);47}48}4950CloseFile(&info);51}52}5354void RSDK::Legacy::SetPaletteFade(uint8 destPaletteID, uint8 srcPaletteA, uint8 srcPaletteB, uint16 blendAmount, int32 startIndex, int32 endIndex)55{56if (destPaletteID >= LEGACY_PALETTE_COUNT || srcPaletteA >= LEGACY_PALETTE_COUNT || srcPaletteB >= LEGACY_PALETTE_COUNT)57return;5859if (blendAmount >= 0x100)60blendAmount = 0xFF;6162if (startIndex >= endIndex)63return;6465uint32 blendA = 0xFF - blendAmount;66uint16 *paletteColor = &fullPalette[destPaletteID][startIndex];67for (int32 i = startIndex; i <= endIndex; ++i) {68uint32 clrA = GetPaletteEntryPacked(srcPaletteA, i);69uint32 clrB = GetPaletteEntryPacked(srcPaletteB, i);7071int32 r = blendAmount * ((clrB >> 0x10) & 0xFF) + blendA * ((clrA >> 0x10) & 0xFF);72int32 g = blendAmount * ((clrB >> 0x08) & 0xFF) + blendA * ((clrA >> 0x08) & 0xFF);73int32 b = blendAmount * ((clrB >> 0x00) & 0xFF) + blendA * ((clrA >> 0x00) & 0xFF);7475*paletteColor = PACK_RGB888((uint8)(r >> 8), (uint8)(g >> 8), (uint8)(b >> 8));7677++paletteColor;78}79}8081void RSDK::Legacy::v3::SetLimitedFade(uint8 paletteID, uint8 R, uint8 G, uint8 B, uint16 blendAmount, int32 startIndex, int32 endIndex)82{83if (paletteID >= LEGACY_PALETTE_COUNT)84return;8586paletteMode = 1;87activePalette = fullPalette[paletteID];8889if (blendAmount >= 0x100)90blendAmount = 0xFF;9192if (startIndex >= endIndex)93return;9495uint32 blendA = 0xFF - blendAmount;96uint16 *paletteColor = &fullPalette[paletteID][startIndex];97for (int32 i = startIndex; i <= endIndex; ++i) {98uint32 clrA = GetPaletteEntryPacked(paletteID, i);99100int32 r = blendAmount * R + blendA * ((clrA >> 0x10) & 0xFF);101int32 g = blendAmount * G + blendA * ((clrA >> 0x08) & 0xFF);102int32 b = blendAmount * B + blendA * ((clrA >> 0x00) & 0xFF);103104*paletteColor = PACK_RGB888((uint8)(r >> 8), (uint8)(g >> 8), (uint8)(b >> 8));105106++paletteColor;107}108}109110