Skip to content

Instantly share code, notes, and snippets.

@tebriel
Created April 3, 2012 15:18
Show Gist options
  • Save tebriel/2292862 to your computer and use it in GitHub Desktop.
Save tebriel/2292862 to your computer and use it in GitHub Desktop.
Darken Color
namespace DevToolWPF.Utils
{
public class RadioColorConverter
{
private static int RsNormalized(int a, int b)
{
return ((a*(((1 << (b)) - 1))/100));
}
private static int RsRgbValue(int r, int g, int b)
{
const int rsRedShift = 11;
const int rsRedBits = 5;
const int rsGreenBits = 6;
const int rsGreenShift = 5;
const int rsBlueBits = 5;
return ((RsNormalized(r, rsRedBits)) << (rsRedShift)) |
((RsNormalized(g, rsGreenBits)) << (rsGreenShift)) |
((RsNormalized(b, rsBlueBits) << (0)));
}
public static int ReverseColor(int color)
{
var red = color & 0xF800;
var green = color & 0x7E0;
var blue = color & 0x1F;
red = red >> 11;
green = green >> 5;
red = 100*red/31;
green = 100*green/63;
blue = 100*blue/31;
red = (red*255/100);
green = (green*255/100);
blue = (blue*255/100);
red = red << 16;
green = green << 8;
return red | green | blue;
}
public static int CreateColor(int color)
{
var red = color & 0xFF0000;
var green = color & 0x00FF00;
var blue = color & 0x0000FF;
red = red >> 16;
green = green >> 8;
red = (red*100)/0xFF;
green = (green*100)/0xFF;
blue = (blue*100)/0xFF;
return RsRgbValue(red, green, blue);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment