Path: blob/master/SonicMania/Objects/Helpers/ColorHelpers.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: ColorHelpers Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectColorHelpers *ColorHelpers = NULL;1011// NOTE:12// I'm not actually sure *what* this object was for13// ColorHelpers_RGBToHSL && ColorHelpers_HSLToRGB were only in PC 1.03, and not in 1.06 so idk what happened14// ColorHelpers_PackRGB is a helper func that allows me to easily pack RGB888 into RGB565 format15// I've never seen definitive proof of any funcs this object may have once had so be it what you will1617void ColorHelpers_Update(void) {}1819void ColorHelpers_LateUpdate(void) {}2021void ColorHelpers_StaticUpdate(void) {}2223void ColorHelpers_Draw(void) {}2425void ColorHelpers_Create(void *data) {}2627void ColorHelpers_StageLoad(void) {}2829uint16 ColorHelpers_PackRGB(uint8 r, uint8 g, uint8 b) { return (b >> 3) | ((g >> 2) << 5) | ((r >> 3) << 11); }3031void ColorHelpers_RGBToHSL(uint32 r, uint32 g, uint32 b, uint32 *hue, uint32 *saturation, uint32 *luminance)32{33if (!r && !g && !b) {34if (hue)35*hue = 0;36if (saturation)37*saturation = 0;38if (luminance)39*luminance = 0;40}4142uint8 min = MIN(MIN(r, g), b);43uint8 max = MAX(MAX(r, g), b);4445int32 chroma = max - min;46if (max) {47if (max == min) {48if (hue)49*hue = 0;5051if (saturation)52*saturation = 0;5354if (luminance)55*luminance = min;56}57else {58if (hue) {59int32 h = 0;6061if (r == max)62h = 60 * (int32)(g - b) / chroma;63else if (g == max)64h = 60 * (int32)(b - r) / chroma + 120;65else66h = 60 * (int32)(r - g) / chroma + 240;6768if (h < 0)69h += 360;7071*hue = h;72}7374if (saturation)75*saturation = 255 * chroma / max;7677if (luminance)78*luminance = max;79}80}81}8283void ColorHelpers_HSLToRGB(uint32 hue, uint32 saturation, uint32 luminance, uint32 *r, uint32 *g, uint32 *b)84{85// Assumes H, S & L are all valid values8687uint32 green = 0, red = 0, blue = 0;8889if (saturation) {90int32 s = luminance * saturation / 255;9192int32 p = luminance - s;93int32 q = luminance - (s * (hue & 60)) / 60;94int32 t = luminance - (s * (60 - hue % 60)) / 60;9596switch (hue / 60) {97case 0:98red = luminance;99green = t;100blue = p;101break;102103case 1:104red = q;105green = luminance;106blue = p;107break;108109case 2:110red = p;111green = luminance;112blue = t;113break;114115case 3:116red = p;117green = q;118blue = luminance;119break;120121case 4:122red = t;123green = p;124blue = luminance;125break;126case 5:127default:128red = luminance;129green = p;130blue = q;131break;132}133}134else {135red = luminance;136green = luminance;137blue = luminance;138}139140if (r)141*r = red;142if (g)143*g = green;144if (b)145*b = blue;146}147148#if GAME_INCLUDE_EDITOR149void ColorHelpers_EditorDraw(void) {}150151void ColorHelpers_EditorLoad(void) {}152#endif153154void ColorHelpers_Serialize(void) {}155156157