Harold Cohen gave a talk last week about how he had moved over to HSB from RGB and it had revolutionised his algorithms for color.
I'm pretty au fait with bitwise grabbing RGB values from an image.
Code:
color myCol = color(244, 40, 55);
int red = myCol>>16&0xFF;
int green = myCol>>8&0xFF;
int blue = myCol&0xFF;
And there's brightness and luminance:
Code:
static int luminance(int c){
return (((c>>16)&0xff)*9 + ((c>>8)&0xff)*19 + ((c&0xff)<<2)) >> 5;
}
static int brightness(int c){
return max((p >> 16) & 0xFF, (p >> 8) & 0xFF, p & 0xFF);
}
(At least I think the brightness one is right)
So for the
Snippet Palace I'd like to post up all the integer color bitwise functions one little 'speed color' page (because they're fast).
I'm a bit stuck figuring out the bitwise functions for hue and saturation from dev.processing.org. Could someone help please
Code:
public final float hue(int what) {
if (what != cacheHsbKey) {
Color.RGBtoHSB((what >> 16) & 0xff, (what >> 8) & 0xff,
what & 0xff, cacheHsbValue);
cacheHsbKey = what;
}
return cacheHsbValue[0] * colorModeX;
}
public final float saturation(int what) {
if (what != cacheHsbKey) {
Color.RGBtoHSB((what >> 16) & 0xff, (what >> 8) & 0xff,
what & 0xff, cacheHsbValue);
cacheHsbKey = what;
}
return cacheHsbValue[1] * colorModeY;
}
public final float brightness(int what) {
if (what != cacheHsbKey) {
Color.RGBtoHSB((what >> 16) & 0xff, (what >> 8) & 0xff,
what & 0xff, cacheHsbValue);
cacheHsbKey = what;
}
return cacheHsbValue[2] * colorModeZ;
}