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 CMY color space.
21   *
22   * <p>
23   * Contains the constant values for black, white, red, green, blue, cyan, magenta, and yellow.
24   * </p>
25   *
26   * @see <a href="https://en.wikipedia.org/wiki/CMY_color_model">https://en.wikipedia.org/wiki/CMY_color_model</a>
27   * @since 1.0-alpha1
28   */
29  public final class ColorCmy {
30  
31      /**
32       * A constant for color cyan. Color components are:
33       *
34       * <pre>
35       *     cyan:    100
36       *     magenta: 0
37       *     yellow:  0
38       * </pre>
39       */
40      public static final ColorCmy CYAN = new ColorCmy(100, 0, 0);
41  
42      /**
43       * A constant for color magenta. Color components are:
44       *
45       * <pre>
46       *     cyan:    0
47       *     magenta: 100
48       *     yellow:  0
49       * </pre>
50       */
51      public static final ColorCmy MAGENTA = new ColorCmy(0, 100, 0);
52  
53      /**
54       * A constant for color yellow. Color components are:
55       *
56       * <pre>
57       *     cyan:    0
58       *     magenta: 0
59       *     yellow:  100
60       * </pre>
61       */
62      public static final ColorCmy YELLOW = new ColorCmy(0, 0, 100);
63  
64      /**
65       * A constant for color black. Color components are:
66       *
67       * <pre>
68       *     cyan:    100
69       *     magenta: 100
70       *     yellow:  100
71       * </pre>
72       */
73      public static final ColorCmy BLACK = new ColorCmy(100, 100, 100);
74  
75      /**
76       * A constant for color white. Color components are:
77       *
78       * <pre>
79       *     cyan:    0
80       *     magenta: 0
81       *     yellow:  0
82       * </pre>
83       */
84      public static final ColorCmy WHITE = new ColorCmy(0, 0, 0);
85  
86      /**
87       * A constant for color red. Color components are:
88       *
89       * <pre>
90       *     cyan:    0
91       *     magenta: 100
92       *     yellow:  100
93       * </pre>
94       */
95      public static final ColorCmy RED = new ColorCmy(0, 100, 100);
96  
97      /**
98       * A constant for color green. Color components are:
99       *
100      * <pre>
101      *     cyan:    100
102      *     magenta: 0
103      *     yellow:  100
104      * </pre>
105      */
106     public static final ColorCmy GREEN = new ColorCmy(100, 0, 100);
107 
108     /**
109      * A constant for color blue. Color components are:
110      *
111      * <pre>
112      *     cyan:    100
113      *     magenta: 100
114      *     yellow:  0
115      * </pre>
116      */
117     public static final ColorCmy BLUE = new ColorCmy(100, 100, 0);
118 
119     public final double c;
120     public final double m;
121     public final double y;
122 
123     public ColorCmy(final double c, final double m, final double y) {
124         this.c = c;
125         this.m = m;
126         this.y = y;
127     }
128 
129     @Override
130     public boolean equals(final Object o) {
131         if (this == o) {
132             return true;
133         }
134         if (o == null || getClass() != o.getClass()) {
135             return false;
136         }
137 
138         final ColorCmy colorCmy = (ColorCmy) o;
139         if (Double.compare(colorCmy.c, c) != 0) {
140             return false;
141         }
142         if (Double.compare(colorCmy.m, m) != 0) {
143             return false;
144         }
145         if (Double.compare(colorCmy.y, y) != 0) {
146             return false;
147         }
148 
149         return true;
150     }
151 
152     @Override
153     public int hashCode() {
154         int result;
155         long temp;
156         temp = Double.doubleToLongBits(c);
157         result = (int) (temp ^ temp >>> 32);
158         temp = Double.doubleToLongBits(m);
159         result = 31 * result + (int) (temp ^ temp >>> 32);
160         temp = Double.doubleToLongBits(y);
161         return 31 * result + (int) (temp ^ temp >>> 32);
162     }
163 
164     @Override
165     public String toString() {
166         return "{C: " + c + ", M: " + m + ", Y: " + y + "}";
167     }
168 }