MCPcopy Create free account
hub / github.com/davisking/dlib / HSV2RGB

Function HSV2RGB

dlib/pixel.h:1195–1248  ·  view source on GitHub ↗

Calculate RGB from HSV, reverse of RGB2HSV() Hue is in degrees Saturation is between 0 and 1 Value is between 0 and 1 */

Source from the content-addressed store, hash-verified

1193 Value is between 0 and 1
1194 */
1195 inline COLOUR HSV2RGB(HSV in)
1196 {
1197 COLOUR out;
1198
1199 if (in.s <= 0.0)
1200 {
1201 out.r = in.v;
1202 out.g = in.v;
1203 out.b = in.v;
1204 return out;
1205 }
1206
1207 const double hh = (in.h >= 360 ? 0.0 : in.h) / 60.0;
1208 const long i = static_cast<long>(hh);
1209 const double ff = hh - i;
1210 const double p = in.v * (1.0 - in.s);
1211 const double q = in.v * (1.0 - (in.s * ff));
1212 const double t = in.v * (1.0 - (in.s * (1.0 - ff)));
1213
1214 switch (i)
1215 {
1216 case 0:
1217 out.r = in.v;
1218 out.g = t;
1219 out.b = p;
1220 break;
1221 case 1:
1222 out.r = q;
1223 out.g = in.v;
1224 out.b = p;
1225 break;
1226 case 2:
1227 out.r = p;
1228 out.g = in.v;
1229 out.b = t;
1230 break;
1231 case 3:
1232 out.r = p;
1233 out.g = q;
1234 out.b = in.v;
1235 break;
1236 case 4:
1237 out.r = t;
1238 out.g = p;
1239 out.b = in.v;
1240 break;
1241 default:
1242 out.r = in.v;
1243 out.g = p;
1244 out.b = q;
1245 break;
1246 }
1247 return out;
1248 }
1249
1250 // -----------------------------
1251

Callers 1

assignFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected