Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Rubberduckycooly
GitHub Repository: Rubberduckycooly/RSDKv5-Decompilation
Path: blob/master/RSDKv5/RSDK/Graphics/Legacy/PaletteLegacy.cpp
1163 views
1
2
// Palettes (as RGB565 Colors)
3
uint16 RSDK::Legacy::fullPalette[LEGACY_PALETTE_COUNT][LEGACY_PALETTE_COLOR_COUNT];
4
uint16 *RSDK::Legacy::activePalette = fullPalette[0]; // Ptr to the 256 color set thats active
5
6
uint8 RSDK::Legacy::gfxLineBuffer[SCREEN_YSIZE * 2]; // Pointers to active palette
7
int32 RSDK::Legacy::GFX_LINESIZE = 0;
8
int32 RSDK::Legacy::GFX_LINESIZE_MINUSONE = 0;
9
int32 RSDK::Legacy::GFX_LINESIZE_DOUBLE = 0;
10
int32 RSDK::Legacy::GFX_FRAMEBUFFERSIZE = 0;
11
int32 RSDK::Legacy::GFX_FBUFFERMINUSONE = 0;
12
13
int32 RSDK::Legacy::fadeMode = 0;
14
uint8 RSDK::Legacy::fadeA = 0;
15
uint8 RSDK::Legacy::fadeR = 0;
16
uint8 RSDK::Legacy::fadeG = 0;
17
uint8 RSDK::Legacy::fadeB = 0;
18
19
int32 RSDK::Legacy::paletteMode = 1;
20
21
void RSDK::Legacy::LoadPalette(const char *filePath, int32 paletteID, int32 startPaletteIndex, int32 startIndex, int32 endIndex)
22
{
23
char fullPath[0x80];
24
25
StrCopy(fullPath, "Data/Palettes/");
26
StrAdd(fullPath, filePath);
27
28
FileInfo info;
29
InitFileInfo(&info);
30
31
if (LoadFile(&info, fullPath, FMODE_RB)) {
32
Seek_Set(&info, 3 * startIndex);
33
34
if (paletteID >= LEGACY_PALETTE_COUNT || paletteID < 0)
35
paletteID = 0;
36
37
uint8 color[3];
38
if (paletteID) {
39
for (int32 i = startIndex; i < endIndex; ++i) {
40
ReadBytes(&info, &color, 3);
41
SetPaletteEntry(paletteID, startPaletteIndex++, color[0], color[1], color[2]);
42
}
43
}
44
else {
45
for (int32 i = startIndex; i < endIndex; ++i) {
46
ReadBytes(&info, &color, 3);
47
SetPaletteEntry(-1, startPaletteIndex++, color[0], color[1], color[2]);
48
}
49
}
50
51
CloseFile(&info);
52
}
53
}
54
55
void RSDK::Legacy::SetPaletteFade(uint8 destPaletteID, uint8 srcPaletteA, uint8 srcPaletteB, uint16 blendAmount, int32 startIndex, int32 endIndex)
56
{
57
if (destPaletteID >= LEGACY_PALETTE_COUNT || srcPaletteA >= LEGACY_PALETTE_COUNT || srcPaletteB >= LEGACY_PALETTE_COUNT)
58
return;
59
60
if (blendAmount >= 0x100)
61
blendAmount = 0xFF;
62
63
if (startIndex >= endIndex)
64
return;
65
66
uint32 blendA = 0xFF - blendAmount;
67
uint16 *paletteColor = &fullPalette[destPaletteID][startIndex];
68
for (int32 i = startIndex; i <= endIndex; ++i) {
69
uint32 clrA = GetPaletteEntryPacked(srcPaletteA, i);
70
uint32 clrB = GetPaletteEntryPacked(srcPaletteB, i);
71
72
int32 r = blendAmount * ((clrB >> 0x10) & 0xFF) + blendA * ((clrA >> 0x10) & 0xFF);
73
int32 g = blendAmount * ((clrB >> 0x08) & 0xFF) + blendA * ((clrA >> 0x08) & 0xFF);
74
int32 b = blendAmount * ((clrB >> 0x00) & 0xFF) + blendA * ((clrA >> 0x00) & 0xFF);
75
76
*paletteColor = PACK_RGB888((uint8)(r >> 8), (uint8)(g >> 8), (uint8)(b >> 8));
77
78
++paletteColor;
79
}
80
}
81
82
void RSDK::Legacy::v3::SetLimitedFade(uint8 paletteID, uint8 R, uint8 G, uint8 B, uint16 blendAmount, int32 startIndex, int32 endIndex)
83
{
84
if (paletteID >= LEGACY_PALETTE_COUNT)
85
return;
86
87
paletteMode = 1;
88
activePalette = fullPalette[paletteID];
89
90
if (blendAmount >= 0x100)
91
blendAmount = 0xFF;
92
93
if (startIndex >= endIndex)
94
return;
95
96
uint32 blendA = 0xFF - blendAmount;
97
uint16 *paletteColor = &fullPalette[paletteID][startIndex];
98
for (int32 i = startIndex; i <= endIndex; ++i) {
99
uint32 clrA = GetPaletteEntryPacked(paletteID, i);
100
101
int32 r = blendAmount * R + blendA * ((clrA >> 0x10) & 0xFF);
102
int32 g = blendAmount * G + blendA * ((clrA >> 0x08) & 0xFF);
103
int32 b = blendAmount * B + blendA * ((clrA >> 0x00) & 0xFF);
104
105
*paletteColor = PACK_RGB888((uint8)(r >> 8), (uint8)(g >> 8), (uint8)(b >> 8));
106
107
++paletteColor;
108
}
109
}
110