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>Contains the constant values for black, white, red, 023 * green, and blue.</p> 024 * 025 * @see <a href="https://en.wikipedia.org/wiki/CIELUV">https://en.wikipedia.org/wiki/CIELUV</a> 026 * @since 1.0-alpha1 027 */ 028public final class ColorCieLuv { 029 030 /** 031 * A constant for color black. Color components are: 032 * <pre> 033 * L: 0.000 034 * u: 0.000 035 * v: 0.000 036 * </pre> 037 */ 038 public static final ColorCieLuv BLACK = new ColorCieLuv(0, 0, 0); 039 040 /** 041 * A constant for color white. Color components are: 042 * <pre> 043 * L: 100.000 044 * u: 0.000 045 * v: -0.017 046 * </pre> 047 */ 048 public static final ColorCieLuv WHITE = new ColorCieLuv(100, 0, -0.017); 049 050 /** 051 * A constant for color red. Color components are: 052 * <pre> 053 * L: 53.233 054 * u: 175.053 055 * v: 37.751 056 * </pre> 057 */ 058 public static final ColorCieLuv RED = new ColorCieLuv(53.233, 175.053, 37.751); 059 060 /** 061 * A constant for color green. Color components are: 062 * <pre> 063 * L: 87.737 064 * u: -83.080 065 * v: 107.401 066 * </pre> 067 */ 068 public static final ColorCieLuv GREEN = new ColorCieLuv(87.737, -83.080, 107.401); 069 070 /** 071 * A constant for color blue. Color components are: 072 * <pre> 073 * L: 32.303 074 * u: -9.400 075 * v: -130.358 076 * </pre> 077 */ 078 public static final ColorCieLuv BLUE = new ColorCieLuv(32.303, -9.400, -130.358); 079 080 public final double L; 081 public final double u; 082 public final double v; 083 084 public ColorCieLuv(final double L, final double u, final double v) { 085 this.L = L; 086 this.u = u; 087 this.v = v; 088 } 089 090 @Override 091 public String toString() { 092 return "{L: " + L + ", u: " + u + ", v: " + v + "}"; 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 ColorCieLuv that = (ColorCieLuv) o; 105 if (Double.compare(that.L, L) != 0) { 106 return false; 107 } 108 if (Double.compare(that.u, u) != 0) { 109 return false; 110 } 111 if (Double.compare(that.v, v) != 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(u); 125 result = 31 * result + (int) (temp ^ (temp >>> 32)); 126 temp = Double.doubleToLongBits(v); 127 result = 31 * result + (int) (temp ^ (temp >>> 32)); 128 return result; 129 } 130}