    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>Contains the constant values for black, white, red,
    023 * green, blue, cyan, magenta, and yellow.</p>
    024 *
    025 * @see <a href="https://en.wikipedia.org/wiki/CMY_color_model">https://en.wikipedia.org/wiki/CMY_color_model</a>
    026 * @since 1.0-alpha1
    027 */
    028public final class ColorCmy {
    029
    030    /**
    031     * A constant for color cyan. Color components are:
    032     * <pre>
    033     *     cyan:    100
    034     *     magenta: 0
    035     *     yellow:  0
    036     * </pre>
    037     */
    038    public static final ColorCmy CYAN = new ColorCmy(100, 0, 0);
    039
    040    /**
    041     * A constant for color magenta. Color components are:
    042     * <pre>
    043     *     cyan:    0
    044     *     magenta: 100
    045     *     yellow:  0
    046     * </pre>
    047     */
    048    public static final ColorCmy MAGENTA = new ColorCmy(0, 100, 0);
    049
    050    /**
    051     * A constant for color yellow. Color components are:
    052     * <pre>
    053     *     cyan:    0
    054     *     magenta: 0
    055     *     yellow:  100
    056     * </pre>
    057     */
    058    public static final ColorCmy YELLOW = new ColorCmy(0, 0, 100);
    059
    060    /**
    061     * A constant for color black. Color components are:
    062     * <pre>
    063     *     cyan:    100
    064     *     magenta: 100
    065     *     yellow:  100
    066     * </pre>
    067     */
    068    public static final ColorCmy BLACK = new ColorCmy(100, 100, 100);
    069
    070    /**
    071     * A constant for color white. Color components are:
    072     * <pre>
    073     *     cyan:    0
    074     *     magenta: 0
    075     *     yellow:  0
    076     * </pre>
    077     */
    078    public static final ColorCmy WHITE = new ColorCmy(0, 0, 0);
    079
    080    /**
    081     * A constant for color red. Color components are:
    082     * <pre>
    083     *     cyan:    0
    084     *     magenta: 100
    085     *     yellow:  100
    086     * </pre>
    087     */
    088    public static final ColorCmy RED = new ColorCmy(0, 100, 100);
    089
    090    /**
    091     * A constant for color green. Color components are:
    092     * <pre>
    093     *     cyan:    100
    094     *     magenta: 0
    095     *     yellow:  100
    096     * </pre>
    097     */
    098    public static final ColorCmy GREEN = new ColorCmy(100, 0, 100);
    099
    100    /**
    101     * A constant for color blue. Color components are:
    102     * <pre>
    103     *     cyan:    100
    104     *     magenta: 100
    105     *     yellow:  0
    106     * </pre>
    107     */
    108    public static final ColorCmy BLUE = new ColorCmy(100, 100, 0);
    109
    110    public final double C;
    111    public final double M;
    112    public final double Y;
    113
    114    public ColorCmy(final double C, final double M, final double Y) {
    115        this.C = C;
    116        this.M = M;
    117        this.Y = Y;
    118    }
    119
    120    @Override
    121    public String toString() {
    122        return "{C: " + C + ", M: " + M + ", Y: " + Y + "}";
    123    }
    124
    125    @Override
    126    public boolean equals(final Object o) {
    127        if (this == o) {
    128            return true;
    129        }
    130        if (o == null || getClass() != o.getClass()) {
    131            return false;
    132        }
    133
    134        final ColorCmy colorCmy = (ColorCmy) o;
    135        if (Double.compare(colorCmy.C, C) != 0) {
    136            return false;
    137        }
    138        if (Double.compare(colorCmy.M, M) != 0) {
    139            return false;
    140        }
    141        if (Double.compare(colorCmy.Y, Y) != 0) {
    142            return false;
    143        }
    144
    145        return true;
    146    }
    147
    148    @Override
    149    public int hashCode() {
    150        int result;
    151        long temp;
    152        temp = Double.doubleToLongBits(C);
    153        result = (int) (temp ^ (temp >>> 32));
    154        temp = Double.doubleToLongBits(M);
    155        result = 31 * result + (int) (temp ^ (temp >>> 32));
    156        temp = Double.doubleToLongBits(Y);
    157        result = 31 * result + (int) (temp ^ (temp >>> 32));
    158        return result;
    159    }
    160}