001: /*
002: * $Id: CMYKColorSpace.java,v 1.2 2007/12/20 18:33:34 rbair Exp $
003: *
004: * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
005: * Santa Clara, California 95054, U.S.A. All rights reserved.
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
020: */
021:
022: package com.sun.pdfview.colorspace;
023:
024: import java.awt.color.ColorSpace;
025:
026: /**
027: * A ColorSpace for the CMYK color space.
028: *
029: * @author Mike Wessler
030: */
031: public class CMYKColorSpace extends ColorSpace {
032: /**
033: * create a new CMYK color space: a ColorSpace with 4 components
034: */
035: public CMYKColorSpace() {
036: super (TYPE_CMYK, 4);
037: }
038:
039: /**
040: * Convert from CIEXYZ to RGB. NOT IMPLEMENTED
041: */
042: public float[] fromCIEXYZ(float[] colorvalue) {
043: return new float[3];
044: }
045:
046: /**
047: * Convert from RGB to CMYK.
048: * @param rgbvalue the red, green, and blue values (0-1)
049: * @return the CMYK values (0-1)
050: */
051: public float[] fromRGB(float[] rgbvalue) {
052: float color[] = new float[4];
053: float c = 1 - rgbvalue[0];
054: float m = 1 - rgbvalue[1];
055: float y = 1 - rgbvalue[2];
056: float k = Math.min(c, Math.min(m, y));
057: float ik = 1 - k;
058: if (ik == 0) {
059: c = 1;
060: m = 1;
061: y = 1;
062: } else {
063: c = (c - k) / ik;
064: m = (m - k) / ik;
065: y = (y - k) / ik;
066: }
067: color[0] = c;
068: color[1] = m;
069: color[2] = y;
070: color[3] = k;
071: return color;
072: }
073:
074: /**
075: * the number of components
076: */
077: @Override
078: public int getNumComponents() {
079: return 4;
080: }
081:
082: /**
083: * the name of this color space
084: */
085: @Override
086: public String getName(int idx) {
087: return "CMYK";
088: }
089:
090: /**
091: * the type of this color space (TYPE_CMYK)
092: */
093: @Override
094: public int getType() {
095: return TYPE_CMYK;
096: }
097:
098: /**
099: * Convert from CMYK to CIEXYZ. NOT IMPLEMENTED
100: */
101: public float[] toCIEXYZ(float[] colorvalue) {
102: return new float[3];
103: }
104:
105: /**
106: * Convert from CMYK to RGB.
107: * @param colorvalue the CMYK values (0-1)
108: * @return the RGB values (0-1)
109: */
110: public float[] toRGB(float[] colorvalue) {
111: if (colorvalue.length == 4) {
112: float[] color = new float[3];
113: float k = colorvalue[3];
114: float ik = 1 - k;
115: color[0] = (1 - (colorvalue[0] * ik + k));
116: color[1] = (1 - (colorvalue[1] * ik + k));
117: color[2] = (1 - (colorvalue[2] * ik + k));
118: return color;
119: } else {
120: return new float[3];
121: }
122: }
123: }
|