Changeset 2218
 Timestamp:
 Jan 14, 2013, 9:19:06 AM (7 years ago)
 Location:
 trunk
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/lol/image/color.h
r2217 r2218 105 105 106 106 /* 107 * Convert RGB to HSL 108 */ 109 static vec3 RGBToHSL(vec3 src) 110 { 111 float K = 0.f; 112 113 if (src.g < src.b) 114 src = src.rbg, K = 1.f; 115 116 if (src.r < src.g) 117 src = src.grb, K = 2.f / 6.f  K; 118 119 float chroma = src.r  min(src.g, src.b); 120 float luma = src.r + min(src.g, src.b); 121 return vec3(abs(K + (src.g  src.b) / (6.f * chroma + 1e20f)), 122 chroma / (min(luma, 2.f  luma) + 1e20f), 123 0.5f * luma); 124 } 125 126 static vec4 RGBToHSL(vec4 src) 127 { 128 return vec4(RGBToHSL(src.rgb), src.a); 129 } 130 131 /* 107 132 * Convert linear HSV to linear HSL 108 133 */ 
trunk/test/unit/color.cpp
r2217 r2218 102 102 } 103 103 } 104 105 LOLUNIT_TEST(RGBToHSL) 106 { 107 for (int r = 0; r < 20; r++) 108 for (int g = 0; g < 20; g++) 109 for (int b = 0; b < 20; b++) 110 { 111 vec3 v1 = vec3(r / 20.f, g / 20.f, b / 20.f); 112 vec3 v2 = Color::RGBToHSL(v1); 113 vec3 v3 = Color::HSVToHSL(Color::RGBToHSV(v1)); 114 115 LOLUNIT_ASSERT_DOUBLES_EQUAL(v2.x, v3.x, 0.0001); 116 LOLUNIT_ASSERT_DOUBLES_EQUAL(v2.y, v3.y, 0.0001); 117 LOLUNIT_ASSERT_DOUBLES_EQUAL(v2.z, v3.z, 0.0001); 118 } 119 } 104 120 }; 105 121
Note: See TracChangeset
for help on using the changeset viewer.