View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.imaging.color;
18  
19  /**
20   * Represents a color in the Hunter Lab color space.
21   *
22   * <p>
23   * Contains the constant values for black, white, red, green, and blue.
24   * </p>
25   *
26   * @see <a href="https://en.wikipedia.org/wiki/CIELAB_color_space#Hunter_Lab">https://en.wikipedia.org/wiki/CIELAB_color_space#Hunter_Lab</a>
27   * @since 1.0-alpha1
28   */
29  public final class ColorHunterLab {
30  
31      /**
32       * A constant for color black. Color components are:
33       *
34       * <pre>
35       *     L: 0
36       *     a: 0
37       *     b: 0
38       * </pre>
39       */
40      public static final ColorHunterLab BLACK = new ColorHunterLab(0, 0, 0);
41  
42      /**
43       * A constant for color white. Color components are:
44       *
45       * <pre>
46       *     L: 100.000
47       *     a:  -5.336
48       *     b:   5.433
49       * </pre>
50       */
51      public static final ColorHunterLab WHITE = new ColorHunterLab(100, -5.336, 5.433);
52  
53      /**
54       * A constant for color red. Color components are:
55       *
56       * <pre>
57       *     L: 46.109
58       *     a: 78.962
59       *     b: 29.794
60       * </pre>
61       */
62      public static final ColorHunterLab RED = new ColorHunterLab(46.109, 78.962, 29.794);
63  
64      /**
65       * A constant for color green. Color components are:
66       *
67       * <pre>
68       *     L:  84.569
69       *     a: -72.518
70       *     b:  50.842
71       * </pre>
72       */
73      public static final ColorHunterLab GREEN = new ColorHunterLab(84.569, -72.518, 50.842);
74  
75      /**
76       * A constant for color blue. Color components are:
77       *
78       * <pre>
79       *     L:   26.870
80       *     a:   72.885
81       *     b: -190.923
82       * </pre>
83       */
84      public static final ColorHunterLab BLUE = new ColorHunterLab(26.870, 72.885, -190.923);
85  
86      public final double l;
87      public final double a;
88      public final double b;
89  
90      public ColorHunterLab(final double l, final double a, final double b) {
91          this.l = l;
92          this.a = a;
93          this.b = b;
94      }
95  
96      @Override
97      public boolean equals(final Object o) {
98          if (this == o) {
99              return true;
100         }
101         if (o == null || getClass() != o.getClass()) {
102             return false;
103         }
104 
105         final ColorHunterLab that = (ColorHunterLab) o;
106         if (Double.compare(that.l, l) != 0) {
107             return false;
108         }
109         if (Double.compare(that.a, a) != 0) {
110             return false;
111         }
112         if (Double.compare(that.b, b) != 0) {
113             return false;
114         }
115 
116         return true;
117     }
118 
119     @Override
120     public int hashCode() {
121         int result;
122         long temp;
123         temp = Double.doubleToLongBits(l);
124         result = (int) (temp ^ temp >>> 32);
125         temp = Double.doubleToLongBits(a);
126         result = 31 * result + (int) (temp ^ temp >>> 32);
127         temp = Double.doubleToLongBits(b);
128         return 31 * result + (int) (temp ^ temp >>> 32);
129     }
130 
131     @Override
132     public String toString() {
133         return "{L: " + l + ", a: " + a + ", b: " + b + "}";
134     }
135 }