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 CMYK color space. 021 * 022 * <p> 023 * Contains the constant values for black, white, red, green, blue, cyan, magenta, and yellow. 024 * </p> 025 * 026 * @see <a href="https://en.wikipedia.org/wiki/CMYK_color_model">https://en.wikipedia.org/wiki/CMYK_color_model</a> 027 * @since 1.0-alpha1 028 */ 029public final class ColorCmyk { 030 031 /** 032 * A constant for color cyan. Color components are: 033 * 034 * <pre> 035 * cyan: 100 036 * magenta: 0 037 * yellow: 0 038 * key: 0 039 * </pre> 040 */ 041 public static final ColorCmyk CYAN = new ColorCmyk(100, 0, 0, 0); 042 043 /** 044 * A constant for color magenta. Color components are: 045 * 046 * <pre> 047 * cyan: 0 048 * magenta: 100 049 * yellow: 0 050 * key: 0 051 * </pre> 052 */ 053 public static final ColorCmyk MAGENTA = new ColorCmyk(0, 100, 0, 0); 054 055 /** 056 * A constant for color yellow. Color components are: 057 * 058 * <pre> 059 * cyan: 0 060 * magenta: 0 061 * yellow: 100 062 * key: 0 063 * </pre> 064 */ 065 public static final ColorCmyk YELLOW = new ColorCmyk(0, 0, 100, 0); 066 067 /** 068 * A constant for color black. Color components are: 069 * 070 * <pre> 071 * cyan: 0 072 * magenta: 0 073 * yellow: 0 074 * key: 100 075 * </pre> 076 */ 077 public static final ColorCmyk BLACK = new ColorCmyk(0, 0, 0, 100); 078 079 /** 080 * A constant for color white. Color components are: 081 * 082 * <pre> 083 * cyan: 0 084 * magenta: 0 085 * yellow: 0 086 * key: 0 087 * </pre> 088 */ 089 public static final ColorCmyk WHITE = new ColorCmyk(0, 0, 0, 0); 090 091 /** 092 * A constant for color red. Color components are: 093 * 094 * <pre> 095 * cyan: 0 096 * magenta: 100 097 * yellow: 100 098 * key: 0 099 * </pre> 100 */ 101 public static final ColorCmyk RED = new ColorCmyk(0, 100, 100, 0); 102 103 /** 104 * A constant for color green. Color components are: 105 * 106 * <pre> 107 * cyan: 100 108 * magenta: 0 109 * yellow: 100 110 * key: 0 111 * </pre> 112 */ 113 public static final ColorCmyk GREEN = new ColorCmyk(100, 0, 100, 0); 114 115 /** 116 * A constant for color blue. Color components are: 117 * 118 * <pre> 119 * cyan: 100 120 * magenta: 100 121 * yellow: 0 122 * key: 0 123 * </pre> 124 */ 125 public static final ColorCmyk BLUE = new ColorCmyk(100, 100, 0, 0); 126 127 public final double c; 128 public final double m; 129 public final double y; 130 public final double k; 131 132 public ColorCmyk(final double c, final double m, final double y, final double k) { 133 this.c = c; 134 this.m = m; 135 this.y = y; 136 this.k = k; 137 } 138 139 @Override 140 public boolean equals(final Object o) { 141 if (this == o) { 142 return true; 143 } 144 if (o == null || getClass() != o.getClass()) { 145 return false; 146 } 147 148 final ColorCmyk colorCmyk = (ColorCmyk) o; 149 if (Double.compare(colorCmyk.c, c) != 0) { 150 return false; 151 } 152 if (Double.compare(colorCmyk.k, k) != 0) { 153 return false; 154 } 155 if (Double.compare(colorCmyk.m, m) != 0) { 156 return false; 157 } 158 if (Double.compare(colorCmyk.y, y) != 0) { 159 return false; 160 } 161 162 return true; 163 } 164 165 @Override 166 public int hashCode() { 167 int result; 168 long temp; 169 temp = Double.doubleToLongBits(c); 170 result = (int) (temp ^ temp >>> 32); 171 temp = Double.doubleToLongBits(m); 172 result = 31 * result + (int) (temp ^ temp >>> 32); 173 temp = Double.doubleToLongBits(y); 174 result = 31 * result + (int) (temp ^ temp >>> 32); 175 temp = Double.doubleToLongBits(k); 176 return 31 * result + (int) (temp ^ temp >>> 32); 177 } 178 179 @Override 180 public String toString() { 181 return "{C: " + c + ", M: " + m + ", Y: " + y + ", K: " + k + "}"; 182 } 183}