Methods Summary |
---|
public void | blend(int R, int G, int B, float fPercent)
if (fPercent >= 1) {
initHSLbyRGB(R, G, B);
return;
}
if (fPercent <= 0)
return;
int newR = (int)((R * fPercent) + (pRed * (1.0 - fPercent)));
int newG = (int)((G * fPercent) + (pGreen * (1.0 - fPercent)));
int newB = (int)((B * fPercent) + (pBlue * (1.0 - fPercent)));
initHSLbyRGB(newR, newG, newB);
|
public void | brighten(float fPercent)
int L;
if (fPercent == 0) {
return;
}
L = (int)(pLum * fPercent);
if (L < 0) L = 0;
if (L > HSLMAX) L = HSLMAX;
setLuminence(L);
|
public int | getBlue()
return pBlue;
|
public int | getGreen()
return pGreen;
|
public int | getHue()
return pHue;
|
public int | getLuminence()
return pLum;
|
public int | getRed()
return pRed;
|
public int | getSaturation()
return pSat;
|
public void | greyscale()
initRGBbyHSL(UNDEFINED, 0, pLum);
|
private int | hueToRGB(int mag1, int mag2, int Hue)
// check the range
if (Hue < 0) {
Hue = Hue + HSLMAX;
} else if (Hue > HSLMAX) {
Hue = Hue - HSLMAX;
}
if (Hue < (HSLMAX / 6))
return (mag1 + (((mag2 - mag1) * Hue + (HSLMAX / 12)) / (HSLMAX / 6)));
if (Hue < (HSLMAX / 2))
return mag2;
if (Hue < (HSLMAX * 2 / 3))
return (mag1 + (((mag2 - mag1) * ((HSLMAX * 2 / 3) - Hue) + (HSLMAX / 12)) / (HSLMAX / 6)));
return mag1;
|
private int | iMax(int a, int b)
if (a > b) return a; else return b;
|
private int | iMin(int a, int b)
if (a < b) return a; else return b;
|
public void | initHSLbyRGB(int R, int G, int B)
// sets Hue, Sat, Lum
int cMax;
int cMin;
int RDelta;
int GDelta;
int BDelta;
int cMinus;
int cPlus;
pRed = R;
pGreen = G;
pBlue = B;
//Set Max & MinColor Values
cMax = iMax(iMax(R, G), B);
cMin = iMin(iMin(R, G), B);
cMinus = cMax - cMin;
cPlus = cMax + cMin;
// Calculate luminescence (lightness)
pLum = ((cPlus * HSLMAX) + RGBMAX) / (2 * RGBMAX);
if (cMax == cMin) {
// greyscale
pSat = 0;
pHue = UNDEFINED;
} else {
// Calculate color saturation
if (pLum <= (HSLMAX / 2)) {
pSat = (int)(((cMinus * HSLMAX) + 0.5) / cPlus);
} else {
pSat = (int)(((cMinus * HSLMAX) + 0.5) / (2 * RGBMAX - cPlus));
}
//Calculate hue
RDelta = (int)((((cMax - R) * (HSLMAX / 6)) + 0.5) / cMinus);
GDelta = (int)((((cMax - G) * (HSLMAX / 6)) + 0.5) / cMinus);
BDelta = (int)((((cMax - B) * (HSLMAX / 6)) + 0.5) / cMinus);
if (cMax == R) {
pHue = BDelta - GDelta;
} else if (cMax == G) {
pHue = (HSLMAX / 3) + RDelta - BDelta;
} else if (cMax == B) {
pHue = ((2 * HSLMAX) / 3) + GDelta - RDelta;
}
if (pHue < 0) {
pHue = pHue + HSLMAX;
}
}
|
public void | initRGBbyHSL(int H, int S, int L)
int Magic1;
int Magic2;
pHue = H;
pLum = L;
pSat = S;
if (S == 0) { //Greyscale
pRed = (L * RGBMAX) / HSLMAX; //luminescence: set to range
pGreen = pRed;
pBlue = pRed;
} else {
if (L <= HSLMAX / 2) {
Magic2 = (L * (HSLMAX + S) + (HSLMAX / 2)) / (HSLMAX);
} else {
Magic2 = L + S - ((L * S) + (HSLMAX / 2)) / HSLMAX;
}
Magic1 = 2 * L - Magic2;
//get R, G, B; change units from HSLMAX range to RGBMAX range
pRed = (hueToRGB(Magic1, Magic2, H + (HSLMAX / 3)) * RGBMAX + (HSLMAX / 2)) / HSLMAX;
if (pRed > RGBMAX) {
pRed = RGBMAX;
}
pGreen = (hueToRGB(Magic1, Magic2, H) * RGBMAX + (HSLMAX / 2)) / HSLMAX;
if (pGreen > RGBMAX) {
pGreen = RGBMAX;
}
pBlue = (hueToRGB(Magic1, Magic2, H - (HSLMAX / 3)) * RGBMAX + (HSLMAX / 2)) / HSLMAX;
if (pBlue > RGBMAX) {
pBlue = RGBMAX;
}
}
|
public void | reverseColor()
setHue(pHue + (HSLMAX / 2));
|
public void | reverseLight()
setLuminence(HSLMAX - pLum);
|
public void | setBlue(int iNewValue)
initHSLbyRGB(pRed, pGreen, iNewValue);
|
public void | setGreen(int iNewValue)
initHSLbyRGB(pRed, iNewValue, pBlue);
|
public void | setHue(int iToValue)
while (iToValue < 0) {
iToValue = HSLMAX + iToValue;
}
while (iToValue > HSLMAX) {
iToValue = iToValue - HSLMAX;
}
initRGBbyHSL(iToValue, pSat, pLum);
|
public void | setLuminence(int iToValue)
if (iToValue < 0) {
iToValue = 0;
} else if (iToValue > HSLMAX) {
iToValue = HSLMAX;
}
initRGBbyHSL(pHue, pSat, iToValue);
|
public void | setRed(int iNewValue)
initHSLbyRGB(iNewValue, pGreen, pBlue);
|
public void | setSaturation(int iToValue)
if (iToValue < 0) {
iToValue = 0;
} else if (iToValue > HSLMAX) {
iToValue = HSLMAX;
}
initRGBbyHSL(pHue, iToValue, pLum);
|