    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
    120    /** Cyan. */
    121    public final double c;
    122
    123    /** Magenta. */
    124    public final double m;
    125
    126    /** Yellow. */
    127    public final double y;
    128
    129    /**
    130     * Constructs a new instance.
    131     *
    132     * @param c cyan.
    133     * @param m magenta.
    134     * @param y yellow.
    135     */
    136    public ColorCmy(final double c, final double m, final double y) {
    137        this.c = c;
    138        this.m = m;
    139        this.y = y;
    140    }
    141
    142    @Override
    143    public boolean equals(final Object o) {
    144        if (this == o) {
    145            return true;
    146        }
    147        if (o == null || getClass() != o.getClass()) {
    148            return false;
    149        }
    150
    151        final ColorCmy colorCmy = (ColorCmy) o;
    152        if (Double.compare(colorCmy.c, c) != 0) {
    153            return false;
    154        }
    155        if (Double.compare(colorCmy.m, m) != 0) {
    156            return false;
    157        }
    158        if (Double.compare(colorCmy.y, y) != 0) {
    159            return false;
    160        }
    161
    162        return true;
    163    }
    164
    165    @Override
    166    public int hashCode() {
    167        int result;
    168        long temp;
    169        temp = Double.doubleToLongBits(c);
    170        result = (int) (temp ^ temp >>> 32);
    171        temp = Double.doubleToLongBits(m);
    172        result = 31 * result + (int) (temp ^ temp >>> 32);
    173        temp = Double.doubleToLongBits(y);
    174        return 31 * result + (int) (temp ^ temp >>> 32);
    175    }
    176
    177    @Override
    178    public String toString() {
    179        return "{C: " + c + ", M: " + m + ", Y: " + y + "}";
    180    }
    181}