We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Bitwise Color (Read 555 times)
Bitwise Color
Nov 23rd, 2006, 2:01pm
 
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;
}

Re: Bitwise Color
Reply #1 - Nov 26th, 2006, 1:44am
 
Unfortunately, there's no simple way to get hue from rgb.  I'd suggest searching wikipedia for the desired colorspace conversion formulae.  Once you get the notion of hex-cones and such you'll see why.  Or, for example see: http://www.easyrgb.com/math.php
Page Index Toggle Pages: 1