-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
124 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef ICC_CONSTANT_H_ | ||
#define ICC_CONSTANT_H_ | ||
|
||
namespace color { | ||
/* ICC's PCS illuminant */ | ||
const double PCS_X = 31595. / 32768.; | ||
const double PCS_Y = 1; | ||
const double PCS_Z = 27030. / 32768.; | ||
|
||
/* Macbook's LCD color profile for XYZ -> RGB */ | ||
const double A11 = 3.98875596; | ||
const double A12 = -2.41598659; | ||
const double A13 = -0.52021109; | ||
const double A21 = -1.40052984; | ||
const double A22 = 2.37728799; | ||
const double A23 = -0.03294208; | ||
const double A31 = -0.03269638; | ||
const double A32 = -0.18259425; | ||
const double A33 = 1.4716528; | ||
} // namespace color | ||
|
||
#endif /* ICC_CONSTANT_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <color.h> | ||
|
||
std::ostream &operator<<(std::ostream &s, const color::LAB &lab) { | ||
return (s << "LAB(" << lab.l << "," << lab.a << "," << lab.b << ")"); | ||
} | ||
|
||
std::ostream &operator<<(std::ostream &s, const color::XYZ &xyz) { | ||
return (s << "XYZ(" << xyz.x << "," << xyz.y << "," << xyz.z << ")"); | ||
} | ||
|
||
std::ostream &operator<<(std::ostream &s, const color::RGB &rgb) { | ||
return (s << "RGB(" << rgb.r << "," << rgb.g << "," << rgb.b << ")"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#define _USE_MATH_DEFINES | ||
#include <cmath> | ||
#include <color.h> | ||
#include <constant.h> | ||
|
||
namespace color { | ||
double sgn(double val) { return (0. < val) - (val < 0.); } | ||
constexpr inline double pow3(double x) { return x * x * x; } | ||
|
||
RGB XYZtoRGB(const XYZ &xyz) { | ||
double r = xyz.x * A11 + xyz.y * A12 + xyz.z * A13; | ||
double g = xyz.x * A21 + xyz.y * A22 + xyz.z * A23; | ||
double b = xyz.x * A31 + xyz.y * A32 + xyz.z * A33; | ||
|
||
r = ((abs(r) > 0.0031308) ? sgn(r) * (1.055 * pow(abs(r), 1 / 2.4) - 0.055) : (12.92 * r)); | ||
g = ((abs(g) > 0.0031308) ? sgn(g) * (1.055 * pow(abs(g), 1 / 2.4) - 0.055) : (12.92 * g)); | ||
b = ((abs(b) > 0.0031308) ? sgn(b) * (1.055 * pow(abs(b), 1 / 2.4) - 0.055) : (12.92 * b)); | ||
|
||
return RGB{r, g, b}; | ||
} | ||
|
||
XYZ LABtoXYZ(const LAB &lab) { | ||
double y = (lab.l + 16.0) / 116.0; | ||
double x = lab.a / 500.0 + y; | ||
double z = y - lab.b / 200.0; | ||
|
||
double x3 = pow3(x); | ||
double y3 = pow3(y); | ||
double z3 = pow3(z); | ||
|
||
x = ((x3 > 0.008856) ? x3 : ((x - 16.0 / 116.0) / 7.787)) * PCS_X; | ||
y = ((y3 > 0.008856) ? y3 : ((y - 16.0 / 116.0) / 7.787)) * PCS_Y; | ||
z = ((z3 > 0.008856) ? z3 : ((z - 16.0 / 116.0) / 7.787)) * PCS_Z; | ||
|
||
return XYZ{x, y, z}; | ||
} | ||
|
||
RGB LABtoRGB(const LAB &lab) { return XYZtoRGB(LABtoXYZ(lab)); } | ||
|
||
bool offRGB(const LAB &lab) { | ||
const RGB rgb{LABtoRGB(lab)}; | ||
|
||
return rgb.r >= 0 && rgb.r <= 1 && rgb.g >= 0 && rgb.g <= 1 && rgb.b >= 0 && | ||
rgb.b <= 1; | ||
} | ||
|
||
} // namespace color |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters