Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-1-2-2013-Decompilation
Path: blob/main/RSDKv4/Palette.cpp
817 views
1
#include "RetroEngine.hpp"
2
3
// Palettes (as RGB888 Colors)
4
PaletteEntry fullPalette32[PALETTE_COUNT][PALETTE_COLOR_COUNT];
5
PaletteEntry *activePalette32 = fullPalette32[0];
6
7
// Palettes (as RGB565 Colors)
8
ushort fullPalette[PALETTE_COUNT][PALETTE_COLOR_COUNT];
9
ushort *activePalette = fullPalette[0]; // Ptr to the 256 color set thats active
10
11
byte gfxLineBuffer[SCREEN_YSIZE]; // Pointers to active palette
12
int GFX_LINESIZE;
13
int GFX_LINESIZE_MINUSONE;
14
int GFX_LINESIZE_DOUBLE;
15
int GFX_FRAMEBUFFERSIZE;
16
int GFX_FBUFFERMINUSONE;
17
18
uint gfxPalette16to32[0x10000];
19
20
int fadeMode = 0;
21
byte fadeA = 0;
22
byte fadeR = 0;
23
byte fadeG = 0;
24
byte fadeB = 0;
25
26
int paletteMode = 1;
27
28
void LoadPalette(const char *filePath, int paletteID, int startPaletteIndex, int startIndex, int endIndex)
29
{
30
FileInfo info;
31
char fullPath[0x80];
32
33
StrCopy(fullPath, "Data/Palettes/");
34
StrAdd(fullPath, filePath);
35
36
if (LoadFile(fullPath, &info)) {
37
SetFilePosition(3 * startIndex);
38
if (paletteID >= PALETTE_COUNT || paletteID < 0)
39
paletteID = 0;
40
41
byte color[3];
42
if (paletteID) {
43
for (int i = startIndex; i < endIndex; ++i) {
44
FileRead(&color, 3);
45
SetPaletteEntry(paletteID, startPaletteIndex++, color[0], color[1], color[2]);
46
}
47
}
48
else {
49
for (int i = startIndex; i < endIndex; ++i) {
50
FileRead(&color, 3);
51
SetPaletteEntry(-1, startPaletteIndex++, color[0], color[1], color[2]);
52
}
53
}
54
CloseFile();
55
}
56
}
57
58
#if RETRO_REV00
59
void SetLimitedFade(byte paletteID, byte R, byte G, byte B, ushort blendAmount, int startIndex, int endIndex)
60
{
61
if (paletteID >= PALETTE_COUNT)
62
return;
63
paletteMode = 1;
64
activePalette = fullPalette[paletteID];
65
activePalette32 = fullPalette32[paletteID];
66
67
if (blendAmount >= 0x100)
68
blendAmount = 0xFF;
69
70
if (startIndex >= endIndex)
71
return;
72
73
uint blendA = 0xFF - blendAmount;
74
for (int i = startIndex; i < endIndex; ++i) {
75
PACK_RGB888(activePalette[i], (byte)((ushort)(R * blendAmount + blendA * activePalette32[i].r) >> 8),
76
(byte)((ushort)(G * blendAmount + blendA * activePalette32[i].g) >> 8),
77
(byte)((ushort)(B * blendAmount + blendA * activePalette32[i].b) >> 8));
78
79
activePalette32[i].r = (byte)((ushort)(R * blendAmount + blendA * activePalette32[i].r) >> 8);
80
activePalette32[i].g = (byte)((ushort)(G * blendAmount + blendA * activePalette32[i].g) >> 8);
81
activePalette32[i].b = (byte)((ushort)(B * blendAmount + blendA * activePalette32[i].b) >> 8);
82
}
83
}
84
#else
85
void SetPaletteFade(byte destPaletteID, byte srcPaletteA, byte srcPaletteB, ushort blendAmount, int startIndex, int endIndex)
86
{
87
if (destPaletteID >= PALETTE_COUNT || srcPaletteA >= PALETTE_COUNT || srcPaletteB >= PALETTE_COUNT)
88
return;
89
90
if (blendAmount >= 0x100)
91
blendAmount = 0xFF;
92
93
if (startIndex >= endIndex)
94
return;
95
96
uint blendA = 0xFF - blendAmount;
97
ushort *dst = &fullPalette[destPaletteID][startIndex];
98
PaletteEntry *dst32 = &fullPalette32[destPaletteID][startIndex];
99
for (int l = startIndex; l <= endIndex; ++l) {
100
*dst = PACK_RGB888((byte)((ushort)(fullPalette32[srcPaletteB][l].r * blendAmount + blendA * fullPalette32[srcPaletteA][l].r) >> 8),
101
(byte)((ushort)(fullPalette32[srcPaletteB][l].g * blendAmount + blendA * fullPalette32[srcPaletteA][l].g) >> 8),
102
(byte)((ushort)(fullPalette32[srcPaletteB][l].b * blendAmount + blendA * fullPalette32[srcPaletteA][l].b) >> 8));
103
dst32->r = (byte)((ushort)(fullPalette32[srcPaletteB][l].r * blendAmount + blendA * fullPalette32[srcPaletteA][l].r) >> 8);
104
dst32->g = (byte)((ushort)(fullPalette32[srcPaletteB][l].g * blendAmount + blendA * fullPalette32[srcPaletteA][l].g) >> 8);
105
dst32->b = (byte)((ushort)(fullPalette32[srcPaletteB][l].b * blendAmount + blendA * fullPalette32[srcPaletteA][l].b) >> 8);
106
107
++dst;
108
++dst32;
109
}
110
}
111
#endif
112