Skip to content

Instantly share code, notes, and snippets.

@tebriel
Created May 9, 2012 20:43
Show Gist options
  • Save tebriel/2648652 to your computer and use it in GitHub Desktop.
Save tebriel/2648652 to your computer and use it in GitHub Desktop.
DesaturateColor
int DesaturateColor(int seatColor, int remainingSaturation, int targetColor)
{
int justR = (seatColor & 0xFF0000);
justR -= (targetColor << 16);
int r = ((justR * remainingSaturation) / 100) + (targetColor << 16);
r &= 0xFF0000;
int justG = (seatColor & 0x00FF00);
justG -= (targetColor << 8);
int g = (justG * remainingSaturation) / 100 + (targetColor << 8);
g &= 0x00FF00;
int justB = (seatColor & 0x0000FF);
justB -= targetColor;
int b = (justB * remainingSaturation) / 100 + targetColor;
b &= 0x0000FF;
return r | g | b;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment