Brixomatic commented on a change in pull request #114:
URL: https://github.com/apache/commons-imaging/pull/114#discussion_r548923245



##########
File path: src/main/java/org/apache/commons/imaging/color/ColorConversions.java
##########
@@ -747,4 +700,147 @@ public static ColorXyz convertCIELuvtoXYZ(final double L, 
final double u, final
 
         return new ColorXyz(X, Y, Z);
     }
+
+    public static ColorDIN99Lab convertCIELabToDIN99bLab(final ColorCieLab 
cie) {
+        return convertCIELabToDIN99bLab(cie.L, cie.a, cie.b);
+    }
+
+    public static ColorDIN99Lab convertCIELabToDIN99bLab(final double L, final 
double a, final double b) {
+        final double FAC_1 = 100.0 / Math.log(129.0 / 50.0); // = 105.51
+        final double kE = 1.0; // brightness factor, 1.0 for CIE reference 
conditions
+        final double kCH = 1.0; // chroma and hue factor, 1.0 for CIE 
reference conditions
+        final double ang = Math.toRadians(16.0);
+
+        final double L99 = kE * FAC_1 * Math.log(1. + 0.0158 * L);
+        double a99 = 0.0;
+        double b99 = 0.0;
+        if (a != 0.0 || b != 0.0) {
+            final double e = a * Math.cos(ang) + b * Math.sin(ang);
+            final double f = 0.7 * (b * Math.cos(ang) - a * Math.sin(ang));
+            final double G = Math.sqrt(e * e + f * f);
+            if (G != 0.) {
+                final double k = Math.log(1. + 0.045 * G) / (0.045 * kCH * kE 
* G);
+                a99 = k * e;
+                b99 = k * f;
+            }
+        }
+        return new ColorDIN99Lab(L99, a99, b99);
+    }
+
+    public static ColorCieLab convertDIN99bLabToCIELab(final ColorDIN99Lab 
dinb) {
+        return convertDIN99bLabToCIELab(dinb.L99, dinb.a99, dinb.b99);
+    }
+
+    public static ColorCieLab convertDIN99bLabToCIELab(final double L99b, 
final double a99b, final double b99b) {
+        final double kE = 1.0; // brightness factor, 1.0 for CIE reference 
conditions
+        final double kCH = 1.0; // chroma and hue factor, 1.0 for CIE 
reference conditions
+        final double FAC_1 = 100.0 / Math.log(129.0 / 50.0); // L99 scaling 
factor = 105.50867113783109
+        final double ang = Math.toRadians(16.0);
+
+        final double hef = Math.atan2(b99b, a99b);
+        final double C = Math.sqrt(a99b * a99b + b99b * b99b);
+        final double G = (Math.exp(0.045 * C * kCH * kE) - 1.0) / 0.045;
+        final double e = G * Math.cos(hef);
+        final double f = G * Math.sin(hef) / 0.7;
+
+        final double L = (Math.exp(L99b * kE / FAC_1) - 1.) / 0.0158;
+        final double a = e * Math.cos(ang) - f * Math.sin(ang);
+        final double b = e * Math.sin(ang) + f * Math.cos(ang);
+        return new ColorCieLab(L, a, b);
+    }
+
+    /** DIN99o, see: 
https://de.wikipedia.org/w/index.php?title=Diskussion:DIN99-Farbraum */
+    public static ColorDIN99Lab convertCIELabToDIN99oLab(final ColorCieLab 
cie) {
+        return convertCIELabToDIN99oLab(cie.L, cie.a, cie.b);
+    }
+
+    /** DIN99o, see: 
https://de.wikipedia.org/w/index.php?title=Diskussion:DIN99-Farbraum */
+    public static ColorDIN99Lab convertCIELabToDIN99oLab(final double L, final 
double a, final double b) {
+        final double kE = 1.0; // brightness factor, 1.0 for CIE reference 
conditions
+        final double kCH = 1.0; // chroma and hue factor, 1.0 for CIE 
reference conditions
+        final double FAC_1 = 100.0 / Math.log(139.0 / 100.0); // L99 scaling 
factor = 303.67100547050995
+        final double ang = Math.toRadians(26.0);
+
+        final double L99o = FAC_1 / kE * Math.log(1 + 0.0039 * L); // 
Lightness correction kE
+        double a99o = 0.0;
+        double b99o = 0.0;
+        if (a != 0.0 || b != 0.0) {
+            final double eo = a * Math.cos(ang) + b * Math.sin(ang); // a 
stretching
+            final double fo = 0.83 * (b * Math.cos(ang) - a * Math.sin(ang)); 
// b rotation/stretching
+            final double Go = Math.sqrt(eo * eo + fo * fo); // chroma
+            final double C99o = Math.log(1.0 + 0.075 * Go) / (0.0435 * kCH * 
kE); // factor for chroma compression and viewing conditions
+            final double heofo = Math.atan2(fo, eo); // arctan in four 
quadrants
+            final double h99o = heofo + ang; // hue rotation
+            a99o = C99o * Math.cos(h99o);
+            b99o = C99o * Math.sin(h99o);
+        }
+        return new ColorDIN99Lab(L99o, a99o, b99o);
+    }
+
+    /** DIN99o, see: 
https://de.wikipedia.org/w/index.php?title=Diskussion:DIN99-Farbraum */
+    public static ColorCieLab convertDIN99oLabToCIELab(final ColorDIN99Lab 
dino) {
+        return convertDIN99oLabToCIELab(dino.L99, dino.a99, dino.b99);
+    }
+
+    /** DIN99o, see: 
https://de.wikipedia.org/w/index.php?title=Diskussion:DIN99-Farbraum */
+    public static ColorCieLab convertDIN99oLabToCIELab(final double L99o, 
final double a99o, final double b99o) {
+        final double kE = 1.0; // brightness factor, 1.0 for CIE reference 
conditions
+        final double kCH = 1.0; // chroma and hue factor, 1.0 for CIE 
reference conditions
+        final double FAC_1 = 100.0 / Math.log(139.0 / 100.0); // L99 scaling 
factor = 303.67100547050995
+        final double ang = Math.toRadians(26.0);
+
+        final double L = (Math.exp(L99o * kE / FAC_1) - 1.0) / 0.0039;
+
+        final double h99ef = Math.atan2(b99o, a99o); // arctan in four 
quadrants
+
+        final double heofo = h99ef - ang; // backwards hue rotation
+
+        final double C99 = Math.sqrt(a99o * a99o + b99o * b99o); // DIN99 
chroma
+        final double G = (Math.exp(0.0435 * kE * kCH * C99) - 1.0) / 0.075; // 
factor for chroma decompression and viewing conditions
+        final double e = G * Math.cos(heofo);
+        final double f = G * Math.sin(heofo);
+
+        final double a = e * Math.cos(ang) - f / 0.83 * Math.sin(ang); // 
rotation by 26 degrees
+        final double b = e * Math.sin(ang) + f / 0.83 * Math.cos(ang); // 
rotation by 26 degrees
+
+        return new ColorCieLab(L, a, b);
+    }

Review comment:
       Note that the DIN99 standard has several iterations. These here deal 
with DIN99b (important milestone) and DIN99o (latest to date, AFAIK). Note I'm 
using the new class ColorDIN99Lab for both of these. Not sure we need to have 
separate classes, since both denote a Lab coordinate in the DIN99 color space.




----------------------------------------------------------------
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]


Reply via email to