    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 Hunter Lab 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/CIELAB_color_space#Hunter_Lab">https://en.wikipedia.org/wiki/CIELAB_color_space#Hunter_Lab</a>
    026 * @since 1.0-alpha1
    027 */
    028public final class ColorHunterLab {
    029
    030    /**
    031     * A constant for color black. Color components are:
    032     * <pre>
    033     *     L: 0
    034     *     a: 0
    035     *     b: 0
    036     * </pre>
    037     */
    038    public static final ColorHunterLab BLACK = new ColorHunterLab(0, 0, 0);
    039
    040    /**
    041     * A constant for color white. Color components are:
    042     * <pre>
    043     *     L: 100.000
    044     *     a:  -5.336
    045     *     b:   5.433
    046     * </pre>
    047     */
    048    public static final ColorHunterLab WHITE = new ColorHunterLab(100, -5.336, 5.433);
    049
    050    /**
    051     * A constant for color red. Color components are:
    052     * <pre>
    053     *     L: 46.109
    054     *     a: 78.962
    055     *     b: 29.794
    056     * </pre>
    057     */
    058    public static final ColorHunterLab RED = new ColorHunterLab(46.109, 78.962, 29.794);
    059
    060    /**
    061     * A constant for color green. Color components are:
    062     * <pre>
    063     *     L:  84.569
    064     *     a: -72.518
    065     *     b:  50.842
    066     * </pre>
    067     */
    068    public static final ColorHunterLab GREEN = new ColorHunterLab(84.569, -72.518, 50.842);
    069
    070    /**
    071     * A constant for color blue. Color components are:
    072     * <pre>
    073     *     L:   26.870
    074     *     a:   72.885
    075     *     b: -190.923
    076     * </pre>
    077     */
    078    public static final ColorHunterLab BLUE = new ColorHunterLab(26.870, 72.885, -190.923);
    079
    080    public final double L;
    081    public final double a;
    082    public final double b;
    083
    084    public ColorHunterLab(final double L, final double a, final double b) {
    085        this.L = L;
    086        this.a = a;
    087        this.b = b;
    088    }
    089
    090    @Override
    091    public String toString() {
    092        return "{L: " + L + ", a: " + a + ", b: " + b + "}";
    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 ColorHunterLab that = (ColorHunterLab) o;
    105        if (Double.compare(that.L, L) != 0) {
    106            return false;
    107        }
    108        if (Double.compare(that.a, a) != 0) {
    109            return false;
    110        }
    111        if (Double.compare(that.b, b) != 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(a);
    125        result = 31 * result + (int) (temp ^ (temp >>> 32));
    126        temp = Double.doubleToLongBits(b);
    127        result = 31 * result + (int) (temp ^ (temp >>> 32));
    128        return result;
    129    }
    130}