Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Helpers/ColorHelpers.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: ColorHelpers Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectColorHelpers *ColorHelpers = NULL;
11
12
// NOTE:
13
// I'm not actually sure *what* this object was for
14
// ColorHelpers_RGBToHSL && ColorHelpers_HSLToRGB were only in PC 1.03, and not in 1.06 so idk what happened
15
// ColorHelpers_PackRGB is a helper func that allows me to easily pack RGB888 into RGB565 format
16
// I've never seen definitive proof of any funcs this object may have once had so be it what you will
17
18
void ColorHelpers_Update(void) {}
19
20
void ColorHelpers_LateUpdate(void) {}
21
22
void ColorHelpers_StaticUpdate(void) {}
23
24
void ColorHelpers_Draw(void) {}
25
26
void ColorHelpers_Create(void *data) {}
27
28
void ColorHelpers_StageLoad(void) {}
29
30
uint16 ColorHelpers_PackRGB(uint8 r, uint8 g, uint8 b) { return (b >> 3) | ((g >> 2) << 5) | ((r >> 3) << 11); }
31
32
void ColorHelpers_RGBToHSL(uint32 r, uint32 g, uint32 b, uint32 *hue, uint32 *saturation, uint32 *luminance)
33
{
34
if (!r && !g && !b) {
35
if (hue)
36
*hue = 0;
37
if (saturation)
38
*saturation = 0;
39
if (luminance)
40
*luminance = 0;
41
}
42
43
uint8 min = MIN(MIN(r, g), b);
44
uint8 max = MAX(MAX(r, g), b);
45
46
int32 chroma = max - min;
47
if (max) {
48
if (max == min) {
49
if (hue)
50
*hue = 0;
51
52
if (saturation)
53
*saturation = 0;
54
55
if (luminance)
56
*luminance = min;
57
}
58
else {
59
if (hue) {
60
int32 h = 0;
61
62
if (r == max)
63
h = 60 * (int32)(g - b) / chroma;
64
else if (g == max)
65
h = 60 * (int32)(b - r) / chroma + 120;
66
else
67
h = 60 * (int32)(r - g) / chroma + 240;
68
69
if (h < 0)
70
h += 360;
71
72
*hue = h;
73
}
74
75
if (saturation)
76
*saturation = 255 * chroma / max;
77
78
if (luminance)
79
*luminance = max;
80
}
81
}
82
}
83
84
void ColorHelpers_HSLToRGB(uint32 hue, uint32 saturation, uint32 luminance, uint32 *r, uint32 *g, uint32 *b)
85
{
86
// Assumes H, S & L are all valid values
87
88
uint32 green = 0, red = 0, blue = 0;
89
90
if (saturation) {
91
int32 s = luminance * saturation / 255;
92
93
int32 p = luminance - s;
94
int32 q = luminance - (s * (hue & 60)) / 60;
95
int32 t = luminance - (s * (60 - hue % 60)) / 60;
96
97
switch (hue / 60) {
98
case 0:
99
red = luminance;
100
green = t;
101
blue = p;
102
break;
103
104
case 1:
105
red = q;
106
green = luminance;
107
blue = p;
108
break;
109
110
case 2:
111
red = p;
112
green = luminance;
113
blue = t;
114
break;
115
116
case 3:
117
red = p;
118
green = q;
119
blue = luminance;
120
break;
121
122
case 4:
123
red = t;
124
green = p;
125
blue = luminance;
126
break;
127
case 5:
128
default:
129
red = luminance;
130
green = p;
131
blue = q;
132
break;
133
}
134
}
135
else {
136
red = luminance;
137
green = luminance;
138
blue = luminance;
139
}
140
141
if (r)
142
*r = red;
143
if (g)
144
*g = green;
145
if (b)
146
*b = blue;
147
}
148
149
#if GAME_INCLUDE_EDITOR
150
void ColorHelpers_EditorDraw(void) {}
151
152
void ColorHelpers_EditorLoad(void) {}
153
#endif
154
155
void ColorHelpers_Serialize(void) {}
156
157