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