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 CIELCH color space.
21   *
22   * <p>
23   * Contains the constant values for black, white, red, green, and blue.
24   * </p>
25   *
26   * @see <a href=
27   *      "https://en.wikipedia.org/wiki/CIELUV#Cylindrical_representation_(CIELCH)">https://en.wikipedia.org/wiki/CIELUV#Cylindrical_representation_(CIELCH)</a>
28   * @since 1.0-alpha1
29   */
30  public final class ColorCieLch {
31  
32      /**
33       * A constant for color black. Color components are:
34       *
35       * <pre>
36       *     L: 0
37       *     c: 0
38       *     h: 0
39       * </pre>
40       */
41      public static final ColorCieLch BLACK = new ColorCieLch(0, 0, 0);
42  
43      /**
44       * A constant for color white. Color components are:
45       *
46       * <pre>
47       *     L: 100
48       *     c:   0
49       *     h: 297
50       * </pre>
51       */
52      public static final ColorCieLch WHITE = new ColorCieLch(100, 0, 297);
53  
54      /**
55       * A constant for color red. Color components are:
56       *
57       * <pre>
58       *     L: 53
59       *     c: 80
60       *     h: 67
61       * </pre>
62       */
63      public static final ColorCieLch RED = new ColorCieLch(53, 80, 67);
64  
65      /**
66       * A constant for color green. Color components are:
67       *
68       * <pre>
69       *     L:  88
70       *     c: -86
71       *     h:  83
72       * </pre>
73       */
74      public static final ColorCieLch GREEN = new ColorCieLch(88, -86, 83);
75  
76      /**
77       * A constant for color blue. Color components are:
78       *
79       * <pre>
80       *     L:   32
81       *     c:   79
82       *     h: -108
83       * </pre>
84       */
85      public static final ColorCieLch BLUE = new ColorCieLch(32, 79, -108);
86  
87      public final double l;
88      public final double c;
89      public final double h;
90  
91      public ColorCieLch(final double l, final double c, final double h) {
92          this.l = l;
93          this.c = c;
94          this.h = h;
95      }
96  
97      @Override
98      public boolean equals(final Object o) {
99          if (this == o) {
100             return true;
101         }
102         if (o == null || getClass() != o.getClass()) {
103             return false;
104         }
105 
106         final ColorCieLch that = (ColorCieLch) o;
107         if (Double.compare(that.c, c) != 0) {
108             return false;
109         }
110         if (Double.compare(that.h, h) != 0) {
111             return false;
112         }
113         if (Double.compare(that.l, l) != 0) {
114             return false;
115         }
116 
117         return true;
118     }
119 
120     @Override
121     public int hashCode() {
122         int result;
123         long temp;
124         temp = Double.doubleToLongBits(l);
125         result = (int) (temp ^ temp >>> 32);
126         temp = Double.doubleToLongBits(c);
127         result = 31 * result + (int) (temp ^ temp >>> 32);
128         temp = Double.doubleToLongBits(h);
129         return 31 * result + (int) (temp ^ temp >>> 32);
130     }
131 
132     @Override
133     public String toString() {
134         return "{L: " + l + ", C: " + c + ", h: " + h + "}";
135     }
136 }