COLORREF HLS_TRANSFORM (COLORREF rgb, int percent_L, int percent_S) { HLSCOLOR hls = RGB2HLS (rgb); BYTE h = HLS_H(hls); BYTE l = HLS_L(hls); BYTE s = HLS_S(hls); if ( percent_L > 0 ) { l = BYTE(l + ((255 - l) * percent_L) / 100); } else if ( percent_L < 0 ) { l = BYTE((l * (100+percent_L)) / 100); } if ( percent_S > 0 ) { s = BYTE(s + ((255 - s) * percent_S) / 100); } else if ( percent_S < 0 ) { s = BYTE((s * (100+percent_S)) / 100); } return HLS2RGB (HLS(h, l, s)); }
void OperaColors::EnlightenFlood(const COLORREF& clr, COLORREF& a, COLORREF& b) { HLSCOLOR hls_a = ::RGB2HLS(clr); HLSCOLOR hls_b = hls_a; BYTE buf = HLS_L(hls_a); if (buf < 38) buf = 0; else buf -= 38; a = ::HLS2RGB(HLS(HLS_H(hls_a), buf, HLS_S(hls_a))); buf = HLS_L(hls_b); if (buf > 217) buf = 255; else buf += 38; b = ::HLS2RGB(HLS(HLS_H(hls_b), buf, HLS_S(hls_b))); }
COLORREF HLS2RGB (HLSCOLOR hls) { float hue = ((int)HLS_H(hls)*360)/255.0f; float luminance = HLS_L(hls)/255.0f; float saturation = HLS_S(hls)/255.0f; if ( saturation == 0.0f ) { return RGB (HLS_L(hls), HLS_L(hls), HLS_L(hls)); } float rm1, rm2; if ( luminance <= 0.5f ) rm2 = luminance + luminance * saturation; else rm2 = luminance + saturation - luminance * saturation; rm1 = 2.0f * luminance - rm2; BYTE red = _ToRGB (rm1, rm2, hue + 120.0f); BYTE green = _ToRGB (rm1, rm2, hue); BYTE blue = _ToRGB (rm1, rm2, hue - 120.0f); return RGB (red, green, blue); }