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