001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.imaging.color;
018
019/**
020 * Represents a color in the CMY color space.
021 *
022 * <p>
023 * Contains the constant values for black, white, red, green, blue, cyan, magenta, and yellow.
024 * </p>
025 *
026 * @see <a href="https://en.wikipedia.org/wiki/CMY_color_model">https://en.wikipedia.org/wiki/CMY_color_model</a>
027 * @since 1.0-alpha1
028 */
029public final class ColorCmy {
030
031    /**
032     * A constant for color cyan. Color components are:
033     *
034     * <pre>
035     *     cyan:    100
036     *     magenta: 0
037     *     yellow:  0
038     * </pre>
039     */
040    public static final ColorCmy CYAN = new ColorCmy(100, 0, 0);
041
042    /**
043     * A constant for color magenta. Color components are:
044     *
045     * <pre>
046     *     cyan:    0
047     *     magenta: 100
048     *     yellow:  0
049     * </pre>
050     */
051    public static final ColorCmy MAGENTA = new ColorCmy(0, 100, 0);
052
053    /**
054     * A constant for color yellow. Color components are:
055     *
056     * <pre>
057     *     cyan:    0
058     *     magenta: 0
059     *     yellow:  100
060     * </pre>
061     */
062    public static final ColorCmy YELLOW = new ColorCmy(0, 0, 100);
063
064    /**
065     * A constant for color black. Color components are:
066     *
067     * <pre>
068     *     cyan:    100
069     *     magenta: 100
070     *     yellow:  100
071     * </pre>
072     */
073    public static final ColorCmy BLACK = new ColorCmy(100, 100, 100);
074
075    /**
076     * A constant for color white. Color components are:
077     *
078     * <pre>
079     *     cyan:    0
080     *     magenta: 0
081     *     yellow:  0
082     * </pre>
083     */
084    public static final ColorCmy WHITE = new ColorCmy(0, 0, 0);
085
086    /**
087     * A constant for color red. Color components are:
088     *
089     * <pre>
090     *     cyan:    0
091     *     magenta: 100
092     *     yellow:  100
093     * </pre>
094     */
095    public static final ColorCmy RED = new ColorCmy(0, 100, 100);
096
097    /**
098     * A constant for color green. Color components are:
099     *
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}