Skip to content

Instantly share code, notes, and snippets.

@peteristhegreat
Created February 26, 2015 19:58
Show Gist options
  • Save peteristhegreat/0f0870497eda68bc99a4 to your computer and use it in GitHub Desktop.
Save peteristhegreat/0f0870497eda68bc99a4 to your computer and use it in GitHub Desktop.
Convert to and from 32 bit color to the Microsoft Safety Pallete (216) indexed colors.
// Generating a CLUT of the Microsoft Safety Pallete
// https://www.gidforums.com/t-21296.html
// Microsoft Safety Pallete
// https://msdn.microsoft.com/en-us/library/bb250466(VS.85).aspx
// Convert to indexed color
int index = (color.red()/51)*36
+ (color.green()/51)*6
+ color.blue()/51
+ 20;
/////////////////////////////////////
// convert from indexed color
int r, g, b, temp;
temp = index - 20;
g = (temp%6)*51;
b = ((temp/6)%6)*51;
r = ((temp/36)%6)*51;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment