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 CIE 1931 color space, also
21   * known as XYZ color space.
22   *
23   * <p>Contains the constant values for black, white, red,
24   * green, and blue.</p>
25   *
26   * @see <a href="https://en.wikipedia.org/wiki/CIE_1931_color_space">https://en.wikipedia.org/wiki/CIE_1931_color_space</a>
27   * @since 1.0-alpha1
28   */
29  public final class ColorXyz {
30  
31      /**
32       * A constant for color black. Color components are:
33       * <pre>
34       *     X: 0
35       *     Y: 0
36       *     Z: 0
37       * </pre>
38       */
39      public static final ColorXyz/color/ColorXyz.html#ColorXyz">ColorXyz BLACK = new ColorXyz(0, 0, 0);
40  
41      /**
42       * A constant for color white. Color components are:
43       * <pre>
44       *     X:  95.05
45       *     Y: 100.00
46       *     Z: 108.90
47       * </pre>
48       */
49      public static final ColorXyz/color/ColorXyz.html#ColorXyz">ColorXyz WHITE = new ColorXyz(95.05, 100, 108.9);
50  
51      /**
52       * A constant for color red. Color components are:
53       * <pre>
54       *     X: 41.24
55       *     Y: 21.26
56       *     Z:  1.93
57       * </pre>
58       */
59      public static final ColorXyzng/color/ColorXyz.html#ColorXyz">ColorXyz RED = new ColorXyz(41.24, 21.26, 1.93);
60  
61      /**
62       * A constant for color green. Color components are:
63       * <pre>
64       *     X: 35.76
65       *     Y: 71.52
66       *     Z: 11.92
67       * </pre>
68       */
69      public static final ColorXyz/color/ColorXyz.html#ColorXyz">ColorXyz GREEN = new ColorXyz(35.76, 71.52, 11.92);
70  
71      /**
72       * A constant for color blue. Color components are:
73       * <pre>
74       *     X: 18.05
75       *     Y:  7.22
76       *     Z: 95.05
77       * </pre>
78       */
79      public static final ColorXyzg/color/ColorXyz.html#ColorXyz">ColorXyz BLUE = new ColorXyz(18.05, 7.22, 95.05);
80  
81      public final double X;
82      public final double Y;
83      public final double Z;
84  
85      public ColorXyz(final double X, final double Y, final double Z) {
86          this.X = X;
87          this.Y = Y;
88          this.Z = Z;
89      }
90  
91      @Override
92      public String toString() {
93          return "{X: " + X + ", Y: " + Y + ", Z: " + Z + "}";
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 ColorXyz./../../../org/apache/commons/imaging/color/ColorXyz.html#ColorXyz">ColorXyz colorXyz = (ColorXyz) o;
106         if (Double.compare(colorXyz.X, X) != 0) {
107             return false;
108         }
109         if (Double.compare(colorXyz.Y, Y) != 0) {
110             return false;
111         }
112         if (Double.compare(colorXyz.Z, Z) != 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(X);
124         result = (int) (temp ^ (temp >>> 32));
125         temp = Double.doubleToLongBits(Y);
126         result = 31 * result + (int) (temp ^ (temp >>> 32));
127         temp = Double.doubleToLongBits(Z);
128         result = 31 * result + (int) (temp ^ (temp >>> 32));
129         return result;
130     }
131 }