    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 CIELCH color space.
    021 *
    022 * <p>Contains the constant values for black, white, red,
    023 * green, and blue.</p>
    024 *
    025 * @see <a href="https://en.wikipedia.org/wiki/CIELUV#Cylindrical_representation_(CIELCH)">https://en.wikipedia.org/wiki/CIELUV#Cylindrical_representation_(CIELCH)</a>
    026 * @since 1.0-alpha1
    027 */
    028public final class ColorCieLch {
    029
    030    /**
    031     * A constant for color black. Color components are:
    032     * <pre>
    033     *     L: 0
    034     *     c: 0
    035     *     h: 0
    036     * </pre>
    037     */
    038    public static final ColorCieLch BLACK = new ColorCieLch(0, 0, 0);
    039
    040    /**
    041     * A constant for color white. Color components are:
    042     * <pre>
    043     *     L: 100
    044     *     c:   0
    045     *     h: 297
    046     * </pre>
    047     */
    048    public static final ColorCieLch WHITE = new ColorCieLch(100, 0, 297);
    049
    050    /**
    051     * A constant for color red. Color components are:
    052     * <pre>
    053     *     L: 53
    054     *     c: 80
    055     *     h: 67
    056     * </pre>
    057     */
    058    public static final ColorCieLch RED = new ColorCieLch(53, 80, 67);
    059
    060    /**
    061     * A constant for color green. Color components are:
    062     * <pre>
    063     *     L:  88
    064     *     c: -86
    065     *     h:  83
    066     * </pre>
    067     */
    068    public static final ColorCieLch GREEN = new ColorCieLch(88, -86, 83);
    069
    070    /**
    071     * A constant for color blue. Color components are:
    072     * <pre>
    073     *     L:   32
    074     *     c:   79
    075     *     h: -108
    076     * </pre>
    077     */
    078    public static final ColorCieLch BLUE = new ColorCieLch(32, 79, -108);
    079
    080    public final double L;
    081    public final double C;
    082    public final double H;
    083
    084    public ColorCieLch(final double L, final double C, final double H) {
    085        this.L = L;
    086        this.C = C;
    087        this.H = H;
    088    }
    089
    090    @Override
    091    public String toString() {
    092        return "{L: " + L + ", C: " + C + ", H: " + H + "}";
    093    }
    094
    095    @Override
    096    public boolean equals(final Object o) {
    097        if (this == o) {
    098            return true;
    099        }
    100        if (o == null || getClass() != o.getClass()) {
    101            return false;
    102        }
    103
    104        final ColorCieLch that = (ColorCieLch) o;
    105        if (Double.compare(that.C, C) != 0) {
    106            return false;
    107        }
    108        if (Double.compare(that.H, H) != 0) {
    109            return false;
    110        }
    111        if (Double.compare(that.L, L) != 0) {
    112            return false;
    113        }
    114
    115        return true;
    116    }
    117
    118    @Override
    119    public int hashCode() {
    120        int result;
    121        long temp;
    122        temp = Double.doubleToLongBits(L);
    123        result = (int) (temp ^ (temp >>> 32));
    124        temp = Double.doubleToLongBits(C);
    125        result = 31 * result + (int) (temp ^ (temp >>> 32));
    126        temp = Double.doubleToLongBits(H);
    127        result = 31 * result + (int) (temp ^ (temp >>> 32));
    128        return result;
    129    }
    130}