src/share/classes/java/awt/color/ColorSpace.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2008, 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 javax.tools.annotation.GenerateNativeHeader;
  39 
  40 import sun.java2d.cmm.PCMM;
  41 import sun.java2d.cmm.CMSManager;
  42 
  43 
  44 /**
  45  * This abstract class is used to serve as a color space tag to identify the
  46  * specific color space of a Color object or, via a ColorModel object,
  47  * of an Image, a BufferedImage, or a GraphicsDevice.  It contains
  48  * methods that transform colors in a specific color space to/from sRGB
  49  * and to/from a well-defined CIEXYZ color space.
  50  * <p>
  51  * For purposes of the methods in this class, colors are represented as
  52  * arrays of color components represented as floats in a normalized range
  53  * defined by each ColorSpace.  For many ColorSpaces (e.g. sRGB), this
  54  * range is 0.0 to 1.0.  However, some ColorSpaces have components whose
  55  * values have a different range.  Methods are provided to inquire per
  56  * component minimum and maximum normalized values.
  57  * <p>
  58  * Several variables are defined for purposes of referring to color


  78 &nbsp;     viewing illuminance: 200 lux
  79 &nbsp;     viewing white point: CIE D50
  80 &nbsp;     media white point: "that of a perfectly reflecting diffuser" -- D50
  81 &nbsp;     media black point: 0 lux or 0 Reflectance
  82 &nbsp;     flare: 1 percent
  83 &nbsp;     surround: 20percent of the media white point
  84 &nbsp;     media description: reflection print (i.e., RLAB, Hunt viewing media)
  85 &nbsp;     note: For developers creating an ICC profile for this conversion
  86 &nbsp;           space, the following is applicable.  Use a simple Von Kries
  87 &nbsp;           white point adaptation folded into the 3X3 matrix parameters
  88 &nbsp;           and fold the flare and surround effects into the three
  89 &nbsp;           one-dimensional lookup tables (assuming one uses the minimal
  90 &nbsp;           model for monitors).
  91 
  92 </pre>
  93  *
  94  * <p>
  95  * @see ICC_ColorSpace
  96  */
  97 
  98 /* No native methods here, but the constants are needed in the supporting JNI code */
  99 @GenerateNativeHeader
 100 public abstract class ColorSpace implements java.io.Serializable {
 101 
 102     static final long serialVersionUID = -409452704308689724L;
 103 
 104     private int type;
 105     private int numComponents;
 106     private transient String [] compName = null;
 107 
 108     // Cache of singletons for the predefined color spaces.
 109     private static ColorSpace sRGBspace;
 110     private static ColorSpace XYZspace;
 111     private static ColorSpace PYCCspace;
 112     private static ColorSpace GRAYspace;
 113     private static ColorSpace LINEAR_RGBspace;
 114 
 115     /**
 116      * Any of the family of XYZ color spaces.
 117      */
 118     public static final int TYPE_XYZ = 0;
 119 
 120     /**
 121      * Any of the family of Lab color spaces.
 122      */
 123     public static final int TYPE_Lab = 1;
 124 
 125     /**
 126      * Any of the family of Luv color spaces.
 127      */
 128     public static final int TYPE_Luv = 2;
 129 
 130     /**
 131      * Any of the family of YCbCr color spaces.
 132      */
 133     public static final int TYPE_YCbCr = 3;
 134 
 135     /**
 136      * Any of the family of Yxy color spaces.
 137      */
 138     public static final int TYPE_Yxy = 4;
 139 
 140     /**
 141      * Any of the family of RGB color spaces.
 142      */
 143     public static final int TYPE_RGB = 5;
 144 
 145     /**
 146      * Any of the family of GRAY color spaces.
 147      */
 148     public static final int TYPE_GRAY = 6;
 149 
 150     /**
 151      * Any of the family of HSV color spaces.
 152      */
 153     public static final int TYPE_HSV = 7;
 154 
 155     /**
 156      * Any of the family of HLS color spaces.
 157      */
 158     public static final int TYPE_HLS = 8;
 159 
 160     /**
 161      * Any of the family of CMYK color spaces.
 162      */
 163     public static final int TYPE_CMYK = 9;
 164 
 165     /**
 166      * Any of the family of CMY color spaces.
 167      */
 168     public static final int TYPE_CMY = 11;
 169 
 170     /**
 171      * Generic 2 component color spaces.
 172      */
 173     public static final int TYPE_2CLR = 12;
 174 
 175     /**
 176      * Generic 3 component color spaces.
 177      */
 178     public static final int TYPE_3CLR = 13;
 179 
 180     /**
 181      * Generic 4 component color spaces.
 182      */
 183     public static final int TYPE_4CLR = 14;
 184 
 185     /**
 186      * Generic 5 component color spaces.
 187      */
 188     public static final int TYPE_5CLR = 15;
 189 
 190     /**
 191      * Generic 6 component color spaces.
 192      */
 193     public static final int TYPE_6CLR = 16;
 194 
 195     /**
 196      * Generic 7 component color spaces.
 197      */
 198     public static final int TYPE_7CLR = 17;
 199 
 200     /**
 201      * Generic 8 component color spaces.
 202      */
 203     public static final int TYPE_8CLR = 18;
 204 
 205     /**
 206      * Generic 9 component color spaces.
 207      */
 208     public static final int TYPE_9CLR = 19;
 209 
 210     /**
 211      * Generic 10 component color spaces.
 212      */
 213     public static final int TYPE_ACLR = 20;
 214 
 215     /**
 216      * Generic 11 component color spaces.
 217      */
 218     public static final int TYPE_BCLR = 21;
 219 
 220     /**
 221      * Generic 12 component color spaces.
 222      */
 223     public static final int TYPE_CCLR = 22;
 224 
 225     /**
 226      * Generic 13 component color spaces.
 227      */
 228     public static final int TYPE_DCLR = 23;
 229 
 230     /**
 231      * Generic 14 component color spaces.
 232      */
 233     public static final int TYPE_ECLR = 24;
 234 
 235     /**
 236      * Generic 15 component color spaces.
 237      */
 238     public static final int TYPE_FCLR = 25;
 239 
 240     /**
 241      * The sRGB color space defined at
 242      * <A href="http://www.w3.org/pub/WWW/Graphics/Color/sRGB.html">
 243      * http://www.w3.org/pub/WWW/Graphics/Color/sRGB.html
 244      * </A>.
 245      */
 246     public static final int CS_sRGB = 1000;
 247 
 248     /**
 249      * A built-in linear RGB color space.  This space is based on the
 250      * same RGB primaries as CS_sRGB, but has a linear tone reproduction curve.
 251      */
 252     public static final int CS_LINEAR_RGB = 1004;
 253 
 254     /**
 255      * The CIEXYZ conversion color space defined above.
 256      */
 257     public static final int CS_CIEXYZ = 1001;
 258 
 259     /**
 260      * The Photo YCC conversion color space.
 261      */
 262     public static final int CS_PYCC = 1002;
 263 
 264     /**
 265      * The built-in linear gray scale color space.
 266      */
 267     public static final int CS_GRAY = 1003;
 268 
 269 
 270     /**
 271      * Constructs a ColorSpace object given a color space type
 272      * and the number of components.
 273      * @param type one of the <CODE>ColorSpace</CODE> type constants
 274      * @param numcomponents the number of components in the color space
 275      */
 276     protected ColorSpace (int type, int numcomponents) {
 277         this.type = type;
 278         this.numComponents = numcomponents;
 279     }
 280 
 281 
 282     /**
 283      * Returns a ColorSpace representing one of the specific
 284      * predefined color spaces.
 285      * @param colorspace a specific color space identified by one of
 286      *        the predefined class constants (e.g. CS_sRGB, CS_LINEAR_RGB,
 287      *        CS_CIEXYZ, CS_GRAY, or CS_PYCC)


   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  *** 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 java.lang.annotation.Native;
  39 
  40 import sun.java2d.cmm.PCMM;
  41 import sun.java2d.cmm.CMSManager;
  42 
  43 
  44 /**
  45  * This abstract class is used to serve as a color space tag to identify the
  46  * specific color space of a Color object or, via a ColorModel object,
  47  * of an Image, a BufferedImage, or a GraphicsDevice.  It contains
  48  * methods that transform colors in a specific color space to/from sRGB
  49  * and to/from a well-defined CIEXYZ color space.
  50  * <p>
  51  * For purposes of the methods in this class, colors are represented as
  52  * arrays of color components represented as floats in a normalized range
  53  * defined by each ColorSpace.  For many ColorSpaces (e.g. sRGB), this
  54  * range is 0.0 to 1.0.  However, some ColorSpaces have components whose
  55  * values have a different range.  Methods are provided to inquire per
  56  * component minimum and maximum normalized values.
  57  * <p>
  58  * Several variables are defined for purposes of referring to color


  78 &nbsp;     viewing illuminance: 200 lux
  79 &nbsp;     viewing white point: CIE D50
  80 &nbsp;     media white point: "that of a perfectly reflecting diffuser" -- D50
  81 &nbsp;     media black point: 0 lux or 0 Reflectance
  82 &nbsp;     flare: 1 percent
  83 &nbsp;     surround: 20percent of the media white point
  84 &nbsp;     media description: reflection print (i.e., RLAB, Hunt viewing media)
  85 &nbsp;     note: For developers creating an ICC profile for this conversion
  86 &nbsp;           space, the following is applicable.  Use a simple Von Kries
  87 &nbsp;           white point adaptation folded into the 3X3 matrix parameters
  88 &nbsp;           and fold the flare and surround effects into the three
  89 &nbsp;           one-dimensional lookup tables (assuming one uses the minimal
  90 &nbsp;           model for monitors).
  91 
  92 </pre>
  93  *
  94  * <p>
  95  * @see ICC_ColorSpace
  96  */
  97 


  98 public abstract class ColorSpace implements java.io.Serializable {
  99 
 100     static final long serialVersionUID = -409452704308689724L;
 101 
 102     private int type;
 103     private int numComponents;
 104     private transient String [] compName = null;
 105 
 106     // Cache of singletons for the predefined color spaces.
 107     private static ColorSpace sRGBspace;
 108     private static ColorSpace XYZspace;
 109     private static ColorSpace PYCCspace;
 110     private static ColorSpace GRAYspace;
 111     private static ColorSpace LINEAR_RGBspace;
 112 
 113     /**
 114      * Any of the family of XYZ color spaces.
 115      */
 116     @Native public static final int TYPE_XYZ = 0;
 117 
 118     /**
 119      * Any of the family of Lab color spaces.
 120      */
 121     @Native public static final int TYPE_Lab = 1;
 122 
 123     /**
 124      * Any of the family of Luv color spaces.
 125      */
 126     @Native public static final int TYPE_Luv = 2;
 127 
 128     /**
 129      * Any of the family of YCbCr color spaces.
 130      */
 131     @Native public static final int TYPE_YCbCr = 3;
 132 
 133     /**
 134      * Any of the family of Yxy color spaces.
 135      */
 136     @Native public static final int TYPE_Yxy = 4;
 137 
 138     /**
 139      * Any of the family of RGB color spaces.
 140      */
 141     @Native public static final int TYPE_RGB = 5;
 142 
 143     /**
 144      * Any of the family of GRAY color spaces.
 145      */
 146     @Native public static final int TYPE_GRAY = 6;
 147 
 148     /**
 149      * Any of the family of HSV color spaces.
 150      */
 151     @Native public static final int TYPE_HSV = 7;
 152 
 153     /**
 154      * Any of the family of HLS color spaces.
 155      */
 156     @Native public static final int TYPE_HLS = 8;
 157 
 158     /**
 159      * Any of the family of CMYK color spaces.
 160      */
 161     @Native public static final int TYPE_CMYK = 9;
 162 
 163     /**
 164      * Any of the family of CMY color spaces.
 165      */
 166     @Native public static final int TYPE_CMY = 11;
 167 
 168     /**
 169      * Generic 2 component color spaces.
 170      */
 171     @Native public static final int TYPE_2CLR = 12;
 172 
 173     /**
 174      * Generic 3 component color spaces.
 175      */
 176     @Native public static final int TYPE_3CLR = 13;
 177 
 178     /**
 179      * Generic 4 component color spaces.
 180      */
 181     @Native public static final int TYPE_4CLR = 14;
 182 
 183     /**
 184      * Generic 5 component color spaces.
 185      */
 186     @Native public static final int TYPE_5CLR = 15;
 187 
 188     /**
 189      * Generic 6 component color spaces.
 190      */
 191     @Native public static final int TYPE_6CLR = 16;
 192 
 193     /**
 194      * Generic 7 component color spaces.
 195      */
 196     @Native public static final int TYPE_7CLR = 17;
 197 
 198     /**
 199      * Generic 8 component color spaces.
 200      */
 201     @Native public static final int TYPE_8CLR = 18;
 202 
 203     /**
 204      * Generic 9 component color spaces.
 205      */
 206     @Native public static final int TYPE_9CLR = 19;
 207 
 208     /**
 209      * Generic 10 component color spaces.
 210      */
 211     @Native public static final int TYPE_ACLR = 20;
 212 
 213     /**
 214      * Generic 11 component color spaces.
 215      */
 216     @Native public static final int TYPE_BCLR = 21;
 217 
 218     /**
 219      * Generic 12 component color spaces.
 220      */
 221     @Native public static final int TYPE_CCLR = 22;
 222 
 223     /**
 224      * Generic 13 component color spaces.
 225      */
 226     @Native public static final int TYPE_DCLR = 23;
 227 
 228     /**
 229      * Generic 14 component color spaces.
 230      */
 231     @Native public static final int TYPE_ECLR = 24;
 232 
 233     /**
 234      * Generic 15 component color spaces.
 235      */
 236     @Native public static final int TYPE_FCLR = 25;
 237 
 238     /**
 239      * The sRGB color space defined at
 240      * <A href="http://www.w3.org/pub/WWW/Graphics/Color/sRGB.html">
 241      * http://www.w3.org/pub/WWW/Graphics/Color/sRGB.html
 242      * </A>.
 243      */
 244     @Native public static final int CS_sRGB = 1000;
 245 
 246     /**
 247      * A built-in linear RGB color space.  This space is based on the
 248      * same RGB primaries as CS_sRGB, but has a linear tone reproduction curve.
 249      */
 250     @Native public static final int CS_LINEAR_RGB = 1004;
 251 
 252     /**
 253      * The CIEXYZ conversion color space defined above.
 254      */
 255     @Native public static final int CS_CIEXYZ = 1001;
 256 
 257     /**
 258      * The Photo YCC conversion color space.
 259      */
 260     @Native public static final int CS_PYCC = 1002;
 261 
 262     /**
 263      * The built-in linear gray scale color space.
 264      */
 265     @Native public static final int CS_GRAY = 1003;
 266 
 267 
 268     /**
 269      * Constructs a ColorSpace object given a color space type
 270      * and the number of components.
 271      * @param type one of the <CODE>ColorSpace</CODE> type constants
 272      * @param numcomponents the number of components in the color space
 273      */
 274     protected ColorSpace (int type, int numcomponents) {
 275         this.type = type;
 276         this.numComponents = numcomponents;
 277     }
 278 
 279 
 280     /**
 281      * Returns a ColorSpace representing one of the specific
 282      * predefined color spaces.
 283      * @param colorspace a specific color space identified by one of
 284      *        the predefined class constants (e.g. CS_sRGB, CS_LINEAR_RGB,
 285      *        CS_CIEXYZ, CS_GRAY, or CS_PYCC)