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