< prev index next >

src/java.desktop/share/classes/java/awt/color/ICC_ProfileRGB.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /*
  27  **********************************************************************
  28  **********************************************************************
  29  **********************************************************************
  30  *** COPYRIGHT (c) Eastman Kodak Company, 1997                      ***
  31  *** As  an unpublished  work pursuant to Title 17 of the United    ***
  32  *** States Code.  All rights reserved.                             ***
  33  **********************************************************************
  34  **********************************************************************
  35  **********************************************************************/
  36 
  37 package java.awt.color;
  38 
  39 import sun.java2d.cmm.Profile;
  40 import sun.java2d.cmm.ProfileDeferralInfo;
  41 
  42 /**
  43  *
  44  * The ICC_ProfileRGB class is a subclass of the ICC_Profile class
  45  * that represents profiles which meet the following criteria:
  46  * <ul>
  47  * <li>The profile's color space type is RGB.</li>
  48  * <li>The profile includes the {@code redColorantTag},
  49  * {@code greenColorantTag}, {@code blueColorantTag},
  50  * {@code redTRCTag}, {@code greenTRCTag},
  51  * {@code blueTRCTag}, and {@code mediaWhitePointTag} tags.</li>
  52  * </ul>
  53  * The {@code ICC_Profile getInstance} method will
  54  * return an {@code ICC_ProfileRGB} object when these conditions are met.
  55  * Three-component, matrix-based input profiles and RGB display profiles are
  56  * examples of this type of profile.
  57  * <p>
  58  * This profile class provides color transform matrices and lookup tables
  59  * that Java or native methods can use directly to
  60  * optimize color conversion in some cases.
  61  * <p>
  62  * To transform from a device profile color space to the CIEXYZ Profile
  63  * Connection Space, each device color component is first linearized by
  64  * a lookup through the corresponding tone reproduction curve (TRC).
  65  * The resulting linear RGB components are converted to the CIEXYZ PCS
  66  * using a a 3x3 matrix constructed from the RGB colorants.
  67  * <pre>
  68  *
  69  * &nbsp;               linearR = redTRC[deviceR]
  70  *
  71  * &nbsp;               linearG = greenTRC[deviceG]
  72  *
  73  * &nbsp;               linearB = blueTRC[deviceB]
  74  *
  75  * &nbsp; _      _       _                                             _   _         _
  76  * &nbsp;[  PCSX  ]     [  redColorantX  greenColorantX  blueColorantX  ] [  linearR  ]
  77  * &nbsp;[        ]     [                                               ] [           ]
  78  * &nbsp;[  PCSY  ]  =  [  redColorantY  greenColorantY  blueColorantY  ] [  linearG  ]
  79  * &nbsp;[        ]     [                                               ] [           ]
  80  * &nbsp;[_ PCSZ _]     [_ redColorantZ  greenColorantZ  blueColorantZ _] [_ linearB _]
  81  *
  82  * </pre>
  83  * The inverse transform is performed by converting PCS XYZ components to linear
  84  * RGB components through the inverse of the above 3x3 matrix, and then converting
  85  * linear RGB to device RGB through inverses of the TRCs.
  86  */
  87 
  88 
  89 
  90 public class ICC_ProfileRGB
  91 extends ICC_Profile {
  92 
  93     static final long serialVersionUID = 8505067385152579334L;
  94 
  95     /**
  96      * Used to get a gamma value or TRC for the red component.
  97      */
  98     public static final int REDCOMPONENT = 0;
  99 
 100     /**
 101      * Used to get a gamma value or TRC for the green component.
 102      */
 103     public static final int GREENCOMPONENT = 1;
 104 
 105     /**
 106      * Used to get a gamma value or TRC for the blue component.
 107      */
 108     public static final int BLUECOMPONENT = 2;
 109 
 110 
 111     /**
 112      * Constructs an new {@code ICC_ProfileRGB} from a CMM ID.
 113      *
 114      * @param p The CMM ID for the profile.
 115      *
 116      */
 117     ICC_ProfileRGB(Profile p) {
 118         super(p);
 119     }
 120 
 121     /**
 122      * Constructs a new {@code ICC_ProfileRGB} from a
 123      * ProfileDeferralInfo object.
 124      *
 125      * @param pdi
 126      */
 127     ICC_ProfileRGB(ProfileDeferralInfo pdi) {
 128         super(pdi);
 129     }
 130 
 131 
 132     /**
 133      * Returns an array that contains the components of the profile's
 134      * {@code mediaWhitePointTag}.
 135      *
 136      * @return A 3-element {@code float} array containing the x, y,
 137      * and z components of the profile's {@code mediaWhitePointTag}.
 138      */
 139     public float[] getMediaWhitePoint() {
 140         return super.getMediaWhitePoint();
 141     }
 142 
 143 
 144     /**
 145      * Returns a 3x3 {@code float} matrix constructed from the
 146      * X, Y, and Z components of the profile's {@code redColorantTag},
 147      * {@code greenColorantTag}, and {@code blueColorantTag}.
 148      * <p>
 149      * This matrix can be used for color transforms in the forward
 150      * direction of the profile--from the profile color space
 151      * to the CIEXYZ PCS.
 152      *
 153      * @return A 3x3 {@code float} array that contains the x, y, and z
 154      * components of the profile's {@code redColorantTag},
 155      * {@code greenColorantTag}, and {@code blueColorantTag}.
 156      */
 157     public float[][] getMatrix() {
 158         float[][] theMatrix = new float[3][3];
 159         float[] tmpMatrix;
 160 
 161         tmpMatrix = getXYZTag(ICC_Profile.icSigRedColorantTag);
 162         theMatrix[0][0] = tmpMatrix[0];
 163         theMatrix[1][0] = tmpMatrix[1];
 164         theMatrix[2][0] = tmpMatrix[2];
 165         tmpMatrix = getXYZTag(ICC_Profile.icSigGreenColorantTag);
 166         theMatrix[0][1] = tmpMatrix[0];
 167         theMatrix[1][1] = tmpMatrix[1];
 168         theMatrix[2][1] = tmpMatrix[2];
 169         tmpMatrix = getXYZTag(ICC_Profile.icSigBlueColorantTag);
 170         theMatrix[0][2] = tmpMatrix[0];
 171         theMatrix[1][2] = tmpMatrix[1];
 172         theMatrix[2][2] = tmpMatrix[2];
 173         return theMatrix;
 174     }
 175 
 176     /**
 177      * Returns a gamma value representing the tone reproduction curve
 178      * (TRC) for a particular component.  The component parameter
 179      * must be one of REDCOMPONENT, GREENCOMPONENT, or BLUECOMPONENT.
 180      * <p>
 181      * If the profile
 182      * represents the TRC for the corresponding component
 183      * as a table rather than a single gamma value, an
 184      * exception is thrown.  In this case the actual table
 185      * can be obtained through the {@link #getTRC(int)} method.
 186      * When using a gamma value,
 187      * the linear component (R, G, or B) is computed as follows:
 188      * <pre>
 189      *
 190      * &nbsp;                                         gamma
 191      * &nbsp;        linearComponent = deviceComponent
 192      *
 193      *</pre>
 194      * @param component The {@code ICC_ProfileRGB} constant that
 195      * represents the component whose TRC you want to retrieve
 196      * @return the gamma value as a float.
 197      * @exception ProfileDataException if the profile does not specify
 198      *            the corresponding TRC as a single gamma value.

 199      */
 200     public float getGamma(int component) {
 201     float theGamma;
 202     int theSignature;
 203 
 204         switch (component) {
 205         case REDCOMPONENT:
 206             theSignature = ICC_Profile.icSigRedTRCTag;
 207             break;
 208 
 209         case GREENCOMPONENT:
 210             theSignature = ICC_Profile.icSigGreenTRCTag;
 211             break;
 212 
 213         case BLUECOMPONENT:
 214             theSignature = ICC_Profile.icSigBlueTRCTag;
 215             break;
 216 
 217         default:
 218             throw new IllegalArgumentException("Must be Red, Green, or Blue");
 219         }
 220 
 221         theGamma = super.getGamma(theSignature);
 222 
 223         return theGamma;
 224     }
 225 
 226     /**
 227      * Returns the TRC for a particular component as an array.
 228      * Component must be {@code REDCOMPONENT},
 229      * {@code GREENCOMPONENT}, or {@code BLUECOMPONENT}.
 230      * Otherwise the returned array
 231      * represents a lookup table where the input component value
 232      * is conceptually in the range [0.0, 1.0].  Value 0.0 maps
 233      * to array index 0 and value 1.0 maps to array index length-1.
 234      * Interpolation might be used to generate output values for
 235      * input values that do not map exactly to an index in the
 236      * array.  Output values also map linearly to the range [0.0, 1.0].
 237      * Value 0.0 is represented by an array value of 0x0000 and
 238      * value 1.0 by 0xFFFF.  In other words, the values are really unsigned
 239      * {@code short} values even though they are returned in a
 240      * {@code short} array.
 241      *
 242      * If the profile has specified the corresponding TRC
 243      * as linear (gamma = 1.0) or as a simple gamma value, this method
 244      * throws an exception.  In this case, the {@link #getGamma(int)}
 245      * method should be used to get the gamma value.
 246      *
 247      * @param component The {@code ICC_ProfileRGB} constant that
 248      * represents the component whose TRC you want to retrieve:
 249      * {@code REDCOMPONENT}, {@code GREENCOMPONENT}, or
 250      * {@code BLUECOMPONENT}.
 251      *
 252      * @return a short array representing the TRC.
 253      * @exception ProfileDataException if the profile does not specify
 254      *            the corresponding TRC as a table.
 255      */
 256     public short[] getTRC(int component) {
 257     short[] theTRC;
 258     int theSignature;
 259 
 260         switch (component) {
 261         case REDCOMPONENT:
 262             theSignature = ICC_Profile.icSigRedTRCTag;
 263             break;
 264 
 265         case GREENCOMPONENT:
 266             theSignature = ICC_Profile.icSigGreenTRCTag;
 267             break;
 268 
 269         case BLUECOMPONENT:
 270             theSignature = ICC_Profile.icSigBlueTRCTag;
 271             break;
 272 
 273         default:
 274             throw new IllegalArgumentException("Must be Red, Green, or Blue");
   1 /*
   2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /* ********************************************************************

  27  **********************************************************************
  28  **********************************************************************
  29  *** COPYRIGHT (c) Eastman Kodak Company, 1997                      ***
  30  *** As  an unpublished  work pursuant to Title 17 of the United    ***
  31  *** States Code.  All rights reserved.                             ***
  32  **********************************************************************
  33  **********************************************************************
  34  **********************************************************************/
  35 
  36 package java.awt.color;
  37 
  38 import sun.java2d.cmm.Profile;
  39 import sun.java2d.cmm.ProfileDeferralInfo;
  40 
  41 /**
  42  * The {@code ICC_ProfileRGB} class is a subclass of the {@code ICC_Profile}
  43  * class that represents profiles which meet the following criteria: the
  44  * profile's color space type is RGB, and the profile includes the
  45  * {@code redColorantTag}, {@code greenColorantTag}, {@code blueColorantTag},
  46  * {@code redTRCTag}, {@code greenTRCTag}, {@code blueTRCTag},
  47  * {@code mediaWhitePointTag} tags. The {@code getInstance} methods in the
  48  * {@code ICC_Profile} class will return an {@code ICC_ProfileRGB} object when
  49  * the above conditions are met. Three-component, matrix-based input profiles
  50  * and RGB display profiles are examples of this type of profile.





  51  * <p>
  52  * The advantage of this class is that it provides color transform matrices and
  53  * lookup tables that Java or native methods can use directly to optimize color
  54  * conversion in some cases.
  55  * <p>
  56  * To transform from a device profile color space to the CIEXYZ Profile
  57  * Connection Space, each device color component is first linearized by a lookup
  58  * through the corresponding tone reproduction curve (TRC). The resulting linear
  59  * RGB components are converted to the CIEXYZ PCS using a a 3x3 matrix
  60  * constructed from the RGB colorants.
  61  * <pre>
  62  *
  63  * &nbsp;               linearR = redTRC[deviceR]
  64  *
  65  * &nbsp;               linearG = greenTRC[deviceG]
  66  *
  67  * &nbsp;               linearB = blueTRC[deviceB]
  68  *
  69  * &nbsp; _      _       _                                             _   _         _
  70  * &nbsp;[  PCSX  ]     [  redColorantX  greenColorantX  blueColorantX  ] [  linearR  ]
  71  * &nbsp;[        ]     [                                               ] [           ]
  72  * &nbsp;[  PCSY  ]  =  [  redColorantY  greenColorantY  blueColorantY  ] [  linearG  ]
  73  * &nbsp;[        ]     [                                               ] [           ]
  74  * &nbsp;[_ PCSZ _]     [_ redColorantZ  greenColorantZ  blueColorantZ _] [_ linearB _]
  75  *
  76  * </pre>
  77  * The inverse transform is performed by converting PCS XYZ components to linear
  78  * RGB components through the inverse of the above 3x3 matrix, and then
  79  * converting linear RGB to device RGB through inverses of the TRCs.
  80  */



  81 public class ICC_ProfileRGB
  82 extends ICC_Profile {
  83 
  84     static final long serialVersionUID = 8505067385152579334L;
  85 
  86     /**
  87      * Used to get a gamma value or TRC for the red component.
  88      */
  89     public static final int REDCOMPONENT = 0;
  90 
  91     /**
  92      * Used to get a gamma value or TRC for the green component.
  93      */
  94     public static final int GREENCOMPONENT = 1;
  95 
  96     /**
  97      * Used to get a gamma value or TRC for the blue component.
  98      */
  99     public static final int BLUECOMPONENT = 2;
 100 

 101     /**
 102      * Constructs an new {@code ICC_ProfileRGB} from a CMM ID.
 103      *
 104      * @param p the CMM ID for the profile.

 105      */
 106     ICC_ProfileRGB(Profile p) {
 107         super(p);
 108     }
 109 
 110     /**
 111      * Constructs a new {@code ICC_ProfileRGB} from a
 112      * {@code ProfileDeferralInfo} object.
 113      *
 114      * @param pdi
 115      */
 116     ICC_ProfileRGB(ProfileDeferralInfo pdi) {
 117         super(pdi);
 118     }
 119 

 120     /**
 121      * Returns an array that contains the components of the profile's
 122      * {@code mediaWhitePointTag}.
 123      *
 124      * @return a 3-element {@code float} array containing the x, y, and z
 125      *         components of the profile's {@code mediaWhitePointTag}
 126      */
 127     public float[] getMediaWhitePoint() {
 128         return super.getMediaWhitePoint();
 129     }
 130 

 131     /**
 132      * Returns a 3x3 {@code float} matrix constructed from the X, Y, and Z
 133      * components of the profile's {@code redColorantTag},
 134      * {@code greenColorantTag}, and {@code blueColorantTag}.
 135      * <p>
 136      * This matrix can be used for color transforms in the forward direction of
 137      * the profile--from the profile color space to the CIEXYZ PCS.

 138      *
 139      * @return a 3x3 {@code float} array that contains the x, y, and z
 140      *         components of the profile's {@code redColorantTag},
 141      *         {@code greenColorantTag}, and {@code blueColorantTag}
 142      */
 143     public float[][] getMatrix() {
 144         float[][] theMatrix = new float[3][3];
 145         float[] tmpMatrix;
 146 
 147         tmpMatrix = getXYZTag(ICC_Profile.icSigRedColorantTag);
 148         theMatrix[0][0] = tmpMatrix[0];
 149         theMatrix[1][0] = tmpMatrix[1];
 150         theMatrix[2][0] = tmpMatrix[2];
 151         tmpMatrix = getXYZTag(ICC_Profile.icSigGreenColorantTag);
 152         theMatrix[0][1] = tmpMatrix[0];
 153         theMatrix[1][1] = tmpMatrix[1];
 154         theMatrix[2][1] = tmpMatrix[2];
 155         tmpMatrix = getXYZTag(ICC_Profile.icSigBlueColorantTag);
 156         theMatrix[0][2] = tmpMatrix[0];
 157         theMatrix[1][2] = tmpMatrix[1];
 158         theMatrix[2][2] = tmpMatrix[2];
 159         return theMatrix;
 160     }
 161 
 162     /**
 163      * Returns a gamma value representing the tone reproduction curve (TRC) for
 164      * a particular component. The component parameter must be one of
 165      * {@code REDCOMPONENT}, {@code GREENCOMPONENT}, or {@code BLUECOMPONENT}.
 166      * <p>
 167      * If the profile represents the TRC for the corresponding component as a
 168      * table rather than a single gamma value, an exception is thrown. In this
 169      * case the actual table can be obtained through the {@link #getTRC(int)}
 170      * method. When using a gamma value, the linear component (R, G, or B) is
 171      * computed as follows:


 172      * <pre>
 173      *
 174      * &nbsp;                                         gamma
 175      * &nbsp;        linearComponent = deviceComponent
 176      *
 177      * </pre>
 178      *
 179      * @param  component the {@code ICC_ProfileRGB} constant that represents the
 180      *         component whose TRC you want to retrieve
 181      * @return the gamma value as a float
 182      * @throws ProfileDataException if the profile does not specify the
 183      *         corresponding TRC as a single gamma value
 184      */
 185     public float getGamma(int component) {
 186     float theGamma;
 187     int theSignature;
 188 
 189         switch (component) {
 190         case REDCOMPONENT:
 191             theSignature = ICC_Profile.icSigRedTRCTag;
 192             break;
 193 
 194         case GREENCOMPONENT:
 195             theSignature = ICC_Profile.icSigGreenTRCTag;
 196             break;
 197 
 198         case BLUECOMPONENT:
 199             theSignature = ICC_Profile.icSigBlueTRCTag;
 200             break;
 201 
 202         default:
 203             throw new IllegalArgumentException("Must be Red, Green, or Blue");
 204         }
 205 
 206         theGamma = super.getGamma(theSignature);
 207 
 208         return theGamma;
 209     }
 210 
 211     /**
 212      * Returns the TRC for a particular component as an array. Component must be
 213      * {@code REDCOMPONENT}, {@code GREENCOMPONENT}, or {@code BLUECOMPONENT}.
 214      * Otherwise the returned array represents a lookup table where the input
 215      * component value is conceptually in the range [0.0, 1.0]. Value 0.0 maps
 216      * to array index 0 and value 1.0 maps to array index {@code length-1}.
 217      * Interpolation might be used to generate output values for input values
 218      * that do not map exactly to an index in the array. Output values also map
 219      * linearly to the range [0.0, 1.0]. Value 0.0 is represented by an array
 220      * value of 0x0000 and value 1.0 by 0xFFFF. In other words, the values are
 221      * really unsigned {@code short} values even though they are returned in a



 222      * {@code short} array.
 223      * <p>
 224      * If the profile has specified the corresponding TRC as linear (gamma =
 225      * 1.0) or as a simple gamma value, this method throws an exception. In this
 226      * case, the {@link #getGamma(int)} method should be used to get the gamma
 227      * value.
 228      *
 229      * @param  component the {@code ICC_ProfileRGB} constant that represents the
 230      *         component whose TRC you want to retrieve: {@code REDCOMPONENT},
 231      *         {@code GREENCOMPONENT}, or {@code BLUECOMPONENT}
 232      * @return a short array representing the TRC
 233      * @throws ProfileDataException if the profile does not specify the
 234      *         corresponding TRC as a table


 235      */
 236     public short[] getTRC(int component) {
 237     short[] theTRC;
 238     int theSignature;
 239 
 240         switch (component) {
 241         case REDCOMPONENT:
 242             theSignature = ICC_Profile.icSigRedTRCTag;
 243             break;
 244 
 245         case GREENCOMPONENT:
 246             theSignature = ICC_Profile.icSigGreenTRCTag;
 247             break;
 248 
 249         case BLUECOMPONENT:
 250             theSignature = ICC_Profile.icSigBlueTRCTag;
 251             break;
 252 
 253         default:
 254             throw new IllegalArgumentException("Must be Red, Green, or Blue");
< prev index next >