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