MCPcopy Create free account
hub / github.com/Atarity/Lightpack / toRgb

Function toRgb

Software/math/PrismatikMath.cpp:242–277  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

240 }
241
242 StructRgb toRgb(const StructXyz &xyz) {
243 double x = xyz.x / 100; //X from 0 to 95.047 (Observer = 2°, Illuminant = D65)
244 double y = xyz.y / 100; //Y from 0 to 100.000
245 double z = xyz.z / 100; //Z from 0 to 108.883
246
247 double r = x * 3.2406 + y * -1.5372 + z * -0.4986;
248 double g = x * -0.9689 + y * 1.8758 + z * 0.0415;
249 double b = x * 0.0557 + y * -0.2040 + z * 1.0570;
250
251 if ( r > 0.0031308 )
252 r = 1.055 * pow(r, (1 / 2.4)) - 0.055;
253 else
254 r = 12.92 * r;
255
256 if ( g > 0.0031308 )
257 g = 1.055 * pow(g, (1 / 2.4)) - 0.055;
258 else
259 g = 12.92 * g;
260
261 if ( b > 0.0031308 )
262 b = 1.055 * pow(b, (1 / 2.4)) - 0.055;
263 else
264 b = 12.92 * b;
265
266 r = withinRange<double, double>(r, 0, 1);
267 g = withinRange<double, double>(g, 0, 1);
268 b = withinRange<double, double>(b, 0, 1);
269
270 StructRgb eRgb;
271
272 eRgb.r = round(r*4095);
273 eRgb.g = round(g*4095);
274 eRgb.b = round(b*4095);
275
276 return eRgb;
277 }
278
279 StructRgb toRgb(const StructLab &lab) {
280 return toRgb(toXyz(lab));

Callers 1

Calls 2

roundFunction · 0.85
toXyzFunction · 0.85

Tested by

no test coverage detected