-
Notifications
You must be signed in to change notification settings - Fork 1
Color Strategy
Yuri Pourre edited this page Mar 21, 2014
·
1 revision
Color Strategy is a PixelStrategy to validate if a pixel have some color or not.
First of all, color here is represented as an int:
int rgb = 0xFF3322;
r = (rgb >> 16) & 0xFF;
g = (rgb >> 8) & 0xFF;
b = (rgb) & 0xFF;
The ColorStrategy compares the r,g and b values to the desired color with a tolerance.
See the method isColor below:
public static boolean isColor(int rgb, int color, int minTolerance, int maxTolerance) {
int r = getRed(rgb);
int g = getGreen(rgb);
int b = getBlue(rgb);
int cr = getRed(color);
int cg = getGreen(color);
int cb = getBlue(color);
if((r>=cr-minTolerance)&&(r<=cr+maxTolerance)&&
(g>=cg-minTolerance)&&(g<=cg+maxTolerance)&&
(b>=cb-minTolerance)&&(b<=cb+maxTolerance)) {
return true;
}
return false;
}
isColor returns true only if the red channel of rgb is in the interval color.red-minTolerance ~ color.red+maxTolerance, the same is applied to green and blue channels.