290N/A/*
2362N/A * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
290N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
290N/A *
290N/A * This code is free software; you can redistribute it and/or modify it
290N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
290N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
290N/A *
290N/A * This code is distributed in the hope that it will be useful, but WITHOUT
290N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
290N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
290N/A * version 2 for more details (a copy is included in the LICENSE file that
290N/A * accompanied this code).
290N/A *
290N/A * You should have received a copy of the GNU General Public License version
290N/A * 2 along with this work; if not, write to the Free Software Foundation,
290N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
290N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
290N/A */
290N/A
290N/A/**********************************************************************
290N/A **********************************************************************
290N/A **********************************************************************
290N/A *** COPYRIGHT (c) Eastman Kodak Company, 1997 ***
290N/A *** As an unpublished work pursuant to Title 17 of the United ***
290N/A *** States Code. All rights reserved. ***
290N/A **********************************************************************
290N/A **********************************************************************
290N/A **********************************************************************/
290N/A
290N/Apackage java.awt.color;
290N/A
290N/Aimport java.awt.image.LookupTable;
290N/Aimport sun.java2d.cmm.ProfileDeferralInfo;
290N/A
290N/A/**
290N/A *
290N/A * The ICC_ProfileRGB class is a subclass of the ICC_Profile class
290N/A * that represents profiles which meet the following criteria:
290N/A * <ul>
290N/A * <li>The profile's color space type is RGB.</li>
290N/A * <li>The profile includes the <code>redColorantTag</code>,
290N/A * <code>greenColorantTag</code>, <code>blueColorantTag</code>,
290N/A * <code>redTRCTag</code>, <code>greenTRCTag</code>,
290N/A * <code>blueTRCTag</code>, and <code>mediaWhitePointTag</code> tags.</li>
290N/A * </ul>
290N/A * The <code>ICC_Profile</code> <code>getInstance</code> method will
290N/A * return an <code>ICC_ProfileRGB</code> object when these conditions are met.
290N/A * Three-component, matrix-based input profiles and RGB display profiles are
290N/A * examples of this type of profile.
290N/A * <p>
290N/A * This profile class provides color transform matrices and lookup tables
290N/A * that Java or native methods can use directly to
290N/A * optimize color conversion in some cases.
290N/A * <p>
290N/A * To transform from a device profile color space to the CIEXYZ Profile
290N/A * Connection Space, each device color component is first linearized by
290N/A * a lookup through the corresponding tone reproduction curve (TRC).
290N/A * The resulting linear RGB components are converted to the CIEXYZ PCS
290N/A * using a a 3x3 matrix constructed from the RGB colorants.
290N/A * <pre>
290N/A *
290N/A * &nbsp; linearR = redTRC[deviceR]
290N/A *
290N/A * &nbsp; linearG = greenTRC[deviceG]
290N/A *
290N/A * &nbsp; linearB = blueTRC[deviceB]
290N/A *
290N/A * &nbsp; _ _ _ _ _ _
290N/A * &nbsp;[ PCSX ] [ redColorantX greenColorantX blueColorantX ] [ linearR ]
290N/A * &nbsp;[ ] [ ] [ ]
290N/A * &nbsp;[ PCSY ] = [ redColorantY greenColorantY blueColorantY ] [ linearG ]
290N/A * &nbsp;[ ] [ ] [ ]
290N/A * &nbsp;[_ PCSZ _] [_ redColorantZ greenColorantZ blueColorantZ _] [_ linearB _]
290N/A *
290N/A * </pre>
290N/A * The inverse transform is performed by converting PCS XYZ components to linear
290N/A * RGB components through the inverse of the above 3x3 matrix, and then converting
290N/A * linear RGB to device RGB through inverses of the TRCs.
290N/A * <p>
290N/A */
290N/A
290N/A
290N/A
290N/Apublic class ICC_ProfileRGB
290N/Aextends ICC_Profile {
290N/A
290N/A static final long serialVersionUID = 8505067385152579334L;
290N/A
290N/A /**
290N/A * Used to get a gamma value or TRC for the red component.
290N/A */
290N/A public static final int REDCOMPONENT = 0;
290N/A
290N/A /**
290N/A * Used to get a gamma value or TRC for the green component.
290N/A */
290N/A public static final int GREENCOMPONENT = 1;
290N/A
290N/A /**
290N/A * Used to get a gamma value or TRC for the blue component.
290N/A */
290N/A public static final int BLUECOMPONENT = 2;
290N/A
290N/A
290N/A /**
290N/A * Constructs an new <code>ICC_ProfileRGB</code> from a CMM ID.
290N/A *
290N/A * @param ID The CMM ID for the profile.
290N/A *
290N/A */
290N/A ICC_ProfileRGB(long ID) {
290N/A super(ID);
290N/A }
290N/A
290N/A /**
290N/A * Constructs a new <code>ICC_ProfileRGB</code> from a
290N/A * ProfileDeferralInfo object.
290N/A *
290N/A * @param pdi
290N/A */
290N/A ICC_ProfileRGB(ProfileDeferralInfo pdi) {
290N/A super(pdi);
290N/A }
290N/A
290N/A
290N/A /**
290N/A * Returns an array that contains the components of the profile's
290N/A * <CODE>mediaWhitePointTag</CODE>.
290N/A *
290N/A * @return A 3-element <CODE>float</CODE> array containing the x, y,
290N/A * and z components of the profile's <CODE>mediaWhitePointTag</CODE>.
290N/A */
290N/A public float[] getMediaWhitePoint() {
290N/A return super.getMediaWhitePoint();
290N/A }
290N/A
290N/A
290N/A /**
290N/A * Returns a 3x3 <CODE>float</CODE> matrix constructed from the
290N/A * X, Y, and Z components of the profile's <CODE>redColorantTag</CODE>,
290N/A * <CODE>greenColorantTag</CODE>, and <CODE>blueColorantTag</CODE>.
290N/A * <p>
290N/A * This matrix can be used for color transforms in the forward
290N/A * direction of the profile--from the profile color space
290N/A * to the CIEXYZ PCS.
290N/A *
290N/A * @return A 3x3 <CODE>float</CODE> array that contains the x, y, and z
290N/A * components of the profile's <CODE>redColorantTag</CODE>,
290N/A * <CODE>greenColorantTag</CODE>, and <CODE>blueColorantTag</CODE>.
290N/A */
290N/A public float[][] getMatrix() {
290N/A float[][] theMatrix = new float[3][3];
290N/A float[] tmpMatrix;
290N/A
290N/A tmpMatrix = getXYZTag(ICC_Profile.icSigRedColorantTag);
290N/A theMatrix[0][0] = tmpMatrix[0];
290N/A theMatrix[1][0] = tmpMatrix[1];
290N/A theMatrix[2][0] = tmpMatrix[2];
290N/A tmpMatrix = getXYZTag(ICC_Profile.icSigGreenColorantTag);
290N/A theMatrix[0][1] = tmpMatrix[0];
290N/A theMatrix[1][1] = tmpMatrix[1];
290N/A theMatrix[2][1] = tmpMatrix[2];
290N/A tmpMatrix = getXYZTag(ICC_Profile.icSigBlueColorantTag);
290N/A theMatrix[0][2] = tmpMatrix[0];
290N/A theMatrix[1][2] = tmpMatrix[1];
290N/A theMatrix[2][2] = tmpMatrix[2];
290N/A return theMatrix;
290N/A }
290N/A
290N/A /**
290N/A * Returns a gamma value representing the tone reproduction curve
290N/A * (TRC) for a particular component. The component parameter
290N/A * must be one of REDCOMPONENT, GREENCOMPONENT, or BLUECOMPONENT.
290N/A * <p>
290N/A * If the profile
290N/A * represents the TRC for the corresponding component
290N/A * as a table rather than a single gamma value, an
290N/A * exception is thrown. In this case the actual table
290N/A * can be obtained through the {@link #getTRC(int)} method.
290N/A * When using a gamma value,
290N/A * the linear component (R, G, or B) is computed as follows:
290N/A * <pre>
290N/A *
290N/A * &nbsp; gamma
290N/A * &nbsp; linearComponent = deviceComponent
290N/A *
290N/A *</pre>
290N/A * @param component The <CODE>ICC_ProfileRGB</CODE> constant that
290N/A * represents the component whose TRC you want to retrieve
290N/A * @return the gamma value as a float.
290N/A * @exception ProfileDataException if the profile does not specify
290N/A * the corresponding TRC as a single gamma value.
290N/A */
290N/A public float getGamma(int component) {
290N/A float theGamma;
290N/A int theSignature;
290N/A
290N/A switch (component) {
290N/A case REDCOMPONENT:
290N/A theSignature = ICC_Profile.icSigRedTRCTag;
290N/A break;
290N/A
290N/A case GREENCOMPONENT:
290N/A theSignature = ICC_Profile.icSigGreenTRCTag;
290N/A break;
290N/A
290N/A case BLUECOMPONENT:
290N/A theSignature = ICC_Profile.icSigBlueTRCTag;
290N/A break;
290N/A
290N/A default:
290N/A throw new IllegalArgumentException("Must be Red, Green, or Blue");
290N/A }
290N/A
290N/A theGamma = super.getGamma(theSignature);
290N/A
290N/A return theGamma;
290N/A }
290N/A
290N/A /**
290N/A * Returns the TRC for a particular component as an array.
290N/A * Component must be <code>REDCOMPONENT</code>,
290N/A * <code>GREENCOMPONENT</code>, or <code>BLUECOMPONENT</code>.
290N/A * Otherwise the returned array
290N/A * represents a lookup table where the input component value
290N/A * is conceptually in the range [0.0, 1.0]. Value 0.0 maps
290N/A * to array index 0 and value 1.0 maps to array index length-1.
290N/A * Interpolation might be used to generate output values for
290N/A * input values that do not map exactly to an index in the
290N/A * array. Output values also map linearly to the range [0.0, 1.0].
290N/A * Value 0.0 is represented by an array value of 0x0000 and
290N/A * value 1.0 by 0xFFFF. In other words, the values are really unsigned
290N/A * <code>short</code> values even though they are returned in a
290N/A * <code>short</code> array.
290N/A *
290N/A * If the profile has specified the corresponding TRC
290N/A * as linear (gamma = 1.0) or as a simple gamma value, this method
290N/A * throws an exception. In this case, the {@link #getGamma(int)}
290N/A * method should be used to get the gamma value.
290N/A *
290N/A * @param component The <CODE>ICC_ProfileRGB</CODE> constant that
290N/A * represents the component whose TRC you want to retrieve:
290N/A * <CODE>REDCOMPONENT</CODE>, <CODE>GREENCOMPONENT</CODE>, or
290N/A * <CODE>BLUECOMPONENT</CODE>.
290N/A *
290N/A * @return a short array representing the TRC.
290N/A * @exception ProfileDataException if the profile does not specify
290N/A * the corresponding TRC as a table.
290N/A */
290N/A public short[] getTRC(int component) {
290N/A short[] theTRC;
290N/A int theSignature;
290N/A
290N/A switch (component) {
290N/A case REDCOMPONENT:
290N/A theSignature = ICC_Profile.icSigRedTRCTag;
290N/A break;
290N/A
290N/A case GREENCOMPONENT:
290N/A theSignature = ICC_Profile.icSigGreenTRCTag;
290N/A break;
290N/A
290N/A case BLUECOMPONENT:
290N/A theSignature = ICC_Profile.icSigBlueTRCTag;
290N/A break;
290N/A
290N/A default:
290N/A throw new IllegalArgumentException("Must be Red, Green, or Blue");
290N/A }
290N/A
290N/A theTRC = super.getTRC(theSignature);
290N/A
290N/A return theTRC;
290N/A }
290N/A
290N/A}