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 /** L* lightness. */ 088 public final double l; 089 090 /** C* chroma. */ 091 public final double c; 092 093 /** Hue. */ 094 public final double h; 095 096 /** 097 * Constructs a new instance. 098 * 099 * @param l L* lightness. 100 * @param c chroma. 101 * @param h hue. 102 */ 103 public ColorCieLch(final double l, final double c, final double h) { 104 this.l = l; 105 this.c = c; 106 this.h = h; 107 } 108 109 @Override 110 public boolean equals(final Object o) { 111 if (this == o) { 112 return true; 113 } 114 if (o == null || getClass() != o.getClass()) { 115 return false; 116 } 117 118 final ColorCieLch that = (ColorCieLch) o; 119 if (Double.compare(that.c, c) != 0) { 120 return false; 121 } 122 if (Double.compare(that.h, h) != 0) { 123 return false; 124 } 125 if (Double.compare(that.l, l) != 0) { 126 return false; 127 } 128 129 return true; 130 } 131 132 @Override 133 public int hashCode() { 134 int result; 135 long temp; 136 temp = Double.doubleToLongBits(l); 137 result = (int) (temp ^ temp >>> 32); 138 temp = Double.doubleToLongBits(c); 139 result = 31 * result + (int) (temp ^ temp >>> 32); 140 temp = Double.doubleToLongBits(h); 141 return 31 * result + (int) (temp ^ temp >>> 32); 142 } 143 144 @Override 145 public String toString() { 146 return "{L: " + l + ", C: " + c + ", h: " + h + "}"; 147 } 148}