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

Function HSL2RGB

dlib/pixel.h:1098–1134  ·  view source on GitHub ↗

Calculate RGB from HSL, reverse of RGB2HSL() Hue is in degrees Lightness is between 0 and 1 Saturation is between 0 and 1 */

Source from the content-addressed store, hash-verified

1096 Saturation is between 0 and 1
1097 */
1098 inline COLOUR HSL2RGB(HSL c1)
1099 {
1100 COLOUR c2,sat,ctmp;
1101
1102 if (c1.h < 120) {
1103 sat.r = (120 - c1.h) / 60.0;
1104 sat.g = c1.h / 60.0;
1105 sat.b = 0;
1106 } else if (c1.h < 240) {
1107 sat.r = 0;
1108 sat.g = (240 - c1.h) / 60.0;
1109 sat.b = (c1.h - 120) / 60.0;
1110 } else {
1111 sat.r = (c1.h - 240) / 60.0;
1112 sat.g = 0;
1113 sat.b = (360 - c1.h) / 60.0;
1114 }
1115 sat.r = std::min(sat.r,1.0);
1116 sat.g = std::min(sat.g,1.0);
1117 sat.b = std::min(sat.b,1.0);
1118
1119 ctmp.r = 2 * c1.s * sat.r + (1 - c1.s);
1120 ctmp.g = 2 * c1.s * sat.g + (1 - c1.s);
1121 ctmp.b = 2 * c1.s * sat.b + (1 - c1.s);
1122
1123 if (c1.l < 0.5) {
1124 c2.r = c1.l * ctmp.r;
1125 c2.g = c1.l * ctmp.g;
1126 c2.b = c1.l * ctmp.b;
1127 } else {
1128 c2.r = (1 - c1.l) * ctmp.r + 2 * c1.l - 1;
1129 c2.g = (1 - c1.l) * ctmp.g + 2 * c1.l - 1;
1130 c2.b = (1 - c1.l) * ctmp.b + 2 * c1.l - 1;
1131 }
1132
1133 return(c2);
1134 }
1135
1136 /*
1137 Calculate HSV from RGB

Callers 1

assignFunction · 0.85

Calls 1

minFunction · 0.50

Tested by

no test coverage detected