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