Brixomatic commented on a change in pull request #114:
URL: https://github.com/apache/commons-imaging/pull/114#discussion_r548922568
##########
File path: src/main/java/org/apache/commons/imaging/color/ColorConversions.java
##########
@@ -16,44 +16,46 @@
*/
package org.apache.commons.imaging.color;
+import java.awt.Color;
public final class ColorConversions {
- private static final double REF_X = 95.047; // Observer= 2°, Illuminant=
D65
+
+ // White reference
+ /** see:
https://en.wikipedia.org/wiki/CIELAB_color_space#From_CIEXYZ_to_CIELAB[10] */
+ private static final double REF_X = 95.047; // Observer= 2°, Illuminant=
D65
+
+ /** see:
https://en.wikipedia.org/wiki/CIELAB_color_space#From_CIEXYZ_to_CIELAB[10] */
private static final double REF_Y = 100.000;
+
+ /** see:
https://en.wikipedia.org/wiki/CIELAB_color_space#From_CIEXYZ_to_CIELAB[10] */
private static final double REF_Z = 108.883;
+ /** see:
https://en.wikipedia.org/wiki/CIELAB_color_space#From_CIEXYZ_to_CIELAB[10] */
+ private static final double XYZ_m = 7.787037; // match in slope. Note
commonly seen 7.787 gives worse results
+
+ /** see:
https://en.wikipedia.org/wiki/CIELAB_color_space#From_CIEXYZ_to_CIELAB[10] */
+ private static final double XYZ_t0 = 0.008856;
+
private ColorConversions() {
}
public static ColorCieLab convertXYZtoCIELab(final ColorXyz xyz) {
return convertXYZtoCIELab(xyz.X, xyz.Y, xyz.Z);
}
- public static ColorCieLab convertXYZtoCIELab(final double X, final double
Y,
- final double Z) {
+ public static ColorCieLab convertXYZtoCIELab(final double X, final double
Y, final double Z) {
- double var_X = X / REF_X; // REF_X = 95.047 Observer= 2°, Illuminant=
- // D65
+ double var_X = X / REF_X; // REF_X = 95.047 Observer= 2°, Illuminant=
D65
double var_Y = Y / REF_Y; // REF_Y = 100.000
double var_Z = Z / REF_Z; // REF_Z = 108.883
- if (var_X > 0.008856) {
- var_X = Math.pow(var_X, (1 / 3.0));
- } else {
- var_X = (7.787 * var_X) + (16 / 116.0);
- }
- if (var_Y > 0.008856) {
- var_Y = Math.pow(var_Y, 1 / 3.0);
- } else {
- var_Y = (7.787 * var_Y) + (16 / 116.0);
- }
- if (var_Z > 0.008856) {
- var_Z = Math.pow(var_Z, 1 / 3.0);
- } else {
- var_Z = (7.787 * var_Z) + (16 / 116.0);
- }
+ // Pivot XÝZ:
+ var_X = pivotXYZ(var_X);
+ var_Y = pivotXYZ(var_Y);
+ var_Z = pivotXYZ(var_Z);
Review comment:
avoids some copy/paste errors as well, in case there are changes
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]