CHslFilter::CHslFilter(float hue, float saturation, float lightness) :m_r(0), m_g(0), m_b(0) { if (saturation == 0) { m_r = m_g = m_b = lightness; } else { float temp2 = (lightness < 0.5f) ? lightness * (1.0f + saturation) : lightness + saturation - (lightness*saturation); float temp1 = 2.0f * lightness - temp2; float Hk = hue / 360; float temp3RGB[3] = {Hk + 1/3, Hk, Hk - 1/3}; for (unsigned int i = 0; i != 3; ++i) { if (temp3RGB[i] < 0) { temp3RGB[i] += 1.0f; } else if (temp3RGB[i] > 1) { temp3RGB[i] -= 1.0f; } } for (unsigned int i = 0; i != 3; ++i) { float item = temp3RGB[i]; if (item < 1/6) { item = temp1 + ((temp2 - temp1) * 6.0f * item); } else if (1/6 <= item && item < 1/2) { item = temp2; } else if (1/2 <= item && item < 2/3) { item = temp1 + ((temp2 - temp1) * (2/3 - item) * 6.0f); } else { item = temp1; } temp3RGB[i] = item; } m_r = temp3RGB[0]; m_r = temp3RGB[1]; m_b = temp3RGB[2]; } m_r *= 255; m_g *= 255; m_b *= 255; } void CHslFilter::AdjustColor(float &r, float &g, float &b)const { r += m_r; g += m_g; b += m_b; return; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)