MCPcopy Create free account
hub / github.com/KAlO2/PerfectShow / rgb2hsl

Function rgb2hsl

jni/venus/color_space.cpp:124–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

122}
123
124cv::Vec3f rgb2hsl(const cv::Vec3f& rgb)
125{
126 float min, max;
127 minmax(min, max, rgb[0], rgb[1], rgb[2]);
128
129 float h, s, l = (max + min) / 2;
130
131 if(max == min)
132 {
133 s = 0.0f;
134 h = HSL_UNDEFINED;
135 }
136 else
137 {
138 if(l <= 0.5f)
139 s = (max - min) / (max + min);
140 else
141 s = (max - min) / (2.0f - max - min);
142
143 float delta = max - min;
144 if(delta == 0.0f)
145 delta = 1.0f;
146
147 if(rgb[0] == max)
148 h = (rgb[1] - rgb[2]) / delta;
149 else if(rgb[1] == max)
150 h = 2.0f + (rgb[2] - rgb[0]) / delta;
151 else
152 h = 4.0f + (rgb[0] - rgb[1]) / delta;
153
154 h /= 6;
155 if(h < 0.0f)
156 h += 1.0f;
157 }
158
159 return cv::Vec3f(h, s, l);
160}
161
162static inline float hsl_value(float n1, float n2, float hue)
163{

Callers

nothing calls this directly

Calls 1

minmaxFunction · 0.85

Tested by

no test coverage detected