< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 1997, 2014, 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


 169      * at least the number of components in this ColorSpace.
 170      */
 171     public float[]    toRGB (float[] colorvalue) {
 172 
 173         if (this2srgb == null) {
 174             ColorTransform[] transformList = new ColorTransform [2];
 175             ICC_ColorSpace srgbCS =
 176                 (ICC_ColorSpace) ColorSpace.getInstance (CS_sRGB);
 177             PCMM mdl = CMSManager.getModule();
 178             transformList[0] = mdl.createTransform(
 179                 thisProfile, ColorTransform.Any, ColorTransform.In);
 180             transformList[1] = mdl.createTransform(
 181                 srgbCS.getProfile(), ColorTransform.Any, ColorTransform.Out);
 182             this2srgb = mdl.createTransform(transformList);
 183             if (needScaleInit) {
 184                 setComponentScaling();
 185             }
 186         }
 187 
 188         int nc = this.getNumComponents();
 189         short tmp[] = new short[nc];
 190         for (int i = 0; i < nc; i++) {
 191             tmp[i] = (short)
 192                 ((colorvalue[i] - minVal[i]) * invDiffMinMax[i] + 0.5f);
 193         }
 194         tmp = this2srgb.colorConvert(tmp, null);
 195         float[] result = new float [3];
 196         for (int i = 0; i < 3; i++) {
 197             result[i] = ((float) (tmp[i] & 0xffff)) / 65535.0f;
 198         }
 199         return result;
 200     }
 201 
 202     /**
 203      * Transforms a color value assumed to be in the default CS_sRGB
 204      * color space into this ColorSpace.
 205      * <p>
 206      * This method transforms color values using algorithms designed
 207      * to produce the best perceptual match between input and output
 208      * colors.  In order to do colorimetric conversion of color values,
 209      * you should use the {@code toCIEXYZ}


 220      * @throws ArrayIndexOutOfBoundsException if array length is not
 221      * at least 3.
 222      */
 223     public float[]    fromRGB(float[] rgbvalue) {
 224 
 225         if (srgb2this == null) {
 226             ColorTransform[] transformList = new ColorTransform [2];
 227             ICC_ColorSpace srgbCS =
 228                 (ICC_ColorSpace) ColorSpace.getInstance (CS_sRGB);
 229             PCMM mdl = CMSManager.getModule();
 230             transformList[0] = mdl.createTransform(
 231                 srgbCS.getProfile(), ColorTransform.Any, ColorTransform.In);
 232             transformList[1] = mdl.createTransform(
 233                 thisProfile, ColorTransform.Any, ColorTransform.Out);
 234             srgb2this = mdl.createTransform(transformList);
 235             if (needScaleInit) {
 236                 setComponentScaling();
 237             }
 238         }
 239 
 240         short tmp[] = new short[3];
 241         for (int i = 0; i < 3; i++) {
 242             tmp[i] = (short) ((rgbvalue[i] * 65535.0f) + 0.5f);
 243         }
 244         tmp = srgb2this.colorConvert(tmp, null);
 245         int nc = this.getNumComponents();
 246         float[] result = new float [nc];
 247         for (int i = 0; i < nc; i++) {
 248             result[i] = (((float) (tmp[i] & 0xffff)) / 65535.0f) *
 249                         diffMinMax[i] + minVal[i];
 250         }
 251         return result;
 252     }
 253 
 254 
 255     /**
 256      * Transforms a color value assumed to be in this ColorSpace
 257      * into the CS_CIEXYZ conversion color space.
 258      * <p>
 259      * This method transforms color values using relative colorimetry,
 260      * as defined by the ICC Specification.  This


 362             ICC_ColorSpace xyzCS =
 363                 (ICC_ColorSpace) ColorSpace.getInstance (CS_CIEXYZ);
 364             PCMM mdl = CMSManager.getModule();
 365             try {
 366                 transformList[0] = mdl.createTransform(
 367                     thisProfile, ICC_Profile.icRelativeColorimetric,
 368                     ColorTransform.In);
 369             } catch (CMMException e) {
 370                 transformList[0] = mdl.createTransform(
 371                     thisProfile, ColorTransform.Any, ColorTransform.In);
 372             }
 373             transformList[1] = mdl.createTransform(
 374                 xyzCS.getProfile(), ColorTransform.Any, ColorTransform.Out);
 375             this2xyz = mdl.createTransform (transformList);
 376             if (needScaleInit) {
 377                 setComponentScaling();
 378             }
 379         }
 380 
 381         int nc = this.getNumComponents();
 382         short tmp[] = new short[nc];
 383         for (int i = 0; i < nc; i++) {
 384             tmp[i] = (short)
 385                 ((colorvalue[i] - minVal[i]) * invDiffMinMax[i] + 0.5f);
 386         }
 387         tmp = this2xyz.colorConvert(tmp, null);
 388         float ALMOST_TWO = 1.0f + (32767.0f / 32768.0f);
 389         // For CIEXYZ, min = 0.0, max = ALMOST_TWO for all components
 390         float[] result = new float [3];
 391         for (int i = 0; i < 3; i++) {
 392             result[i] = (((float) (tmp[i] & 0xffff)) / 65535.0f) * ALMOST_TWO;
 393         }
 394         return result;
 395     }
 396 
 397 
 398     /**
 399      * Transforms a color value assumed to be in the CS_CIEXYZ conversion
 400      * color space into this ColorSpace.
 401      * <p>
 402      * This method transforms color values using relative colorimetry,


 505             ColorTransform[] transformList = new ColorTransform [2];
 506             ICC_ColorSpace xyzCS =
 507                 (ICC_ColorSpace) ColorSpace.getInstance (CS_CIEXYZ);
 508             PCMM mdl = CMSManager.getModule();
 509             transformList[0] = mdl.createTransform (
 510                 xyzCS.getProfile(), ColorTransform.Any, ColorTransform.In);
 511             try {
 512                 transformList[1] = mdl.createTransform(
 513                     thisProfile, ICC_Profile.icRelativeColorimetric,
 514                     ColorTransform.Out);
 515             } catch (CMMException e) {
 516                 transformList[1] = CMSManager.getModule().createTransform(
 517                 thisProfile, ColorTransform.Any, ColorTransform.Out);
 518             }
 519             xyz2this = mdl.createTransform(transformList);
 520             if (needScaleInit) {
 521                 setComponentScaling();
 522             }
 523         }
 524 
 525         short tmp[] = new short[3];
 526         float ALMOST_TWO = 1.0f + (32767.0f / 32768.0f);
 527         float factor = 65535.0f / ALMOST_TWO;
 528         // For CIEXYZ, min = 0.0, max = ALMOST_TWO for all components
 529         for (int i = 0; i < 3; i++) {
 530             tmp[i] = (short) ((colorvalue[i] * factor) + 0.5f);
 531         }
 532         tmp = xyz2this.colorConvert(tmp, null);
 533         int nc = this.getNumComponents();
 534         float[] result = new float [nc];
 535         for (int i = 0; i < nc; i++) {
 536             result[i] = (((float) (tmp[i] & 0xffff)) / 65535.0f) *
 537                         diffMinMax[i] + minVal[i];
 538         }
 539         return result;
 540     }
 541 
 542     /**
 543      * Returns the minimum normalized color component value for the
 544      * specified component.  For TYPE_XYZ spaces, this method returns
 545      * minimum values of 0.0 for all components.  For TYPE_Lab spaces,


   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


 169      * at least the number of components in this ColorSpace.
 170      */
 171     public float[]    toRGB (float[] colorvalue) {
 172 
 173         if (this2srgb == null) {
 174             ColorTransform[] transformList = new ColorTransform [2];
 175             ICC_ColorSpace srgbCS =
 176                 (ICC_ColorSpace) ColorSpace.getInstance (CS_sRGB);
 177             PCMM mdl = CMSManager.getModule();
 178             transformList[0] = mdl.createTransform(
 179                 thisProfile, ColorTransform.Any, ColorTransform.In);
 180             transformList[1] = mdl.createTransform(
 181                 srgbCS.getProfile(), ColorTransform.Any, ColorTransform.Out);
 182             this2srgb = mdl.createTransform(transformList);
 183             if (needScaleInit) {
 184                 setComponentScaling();
 185             }
 186         }
 187 
 188         int nc = this.getNumComponents();
 189         short[] tmp = new short[nc];
 190         for (int i = 0; i < nc; i++) {
 191             tmp[i] = (short)
 192                 ((colorvalue[i] - minVal[i]) * invDiffMinMax[i] + 0.5f);
 193         }
 194         tmp = this2srgb.colorConvert(tmp, null);
 195         float[] result = new float [3];
 196         for (int i = 0; i < 3; i++) {
 197             result[i] = ((float) (tmp[i] & 0xffff)) / 65535.0f;
 198         }
 199         return result;
 200     }
 201 
 202     /**
 203      * Transforms a color value assumed to be in the default CS_sRGB
 204      * color space into this ColorSpace.
 205      * <p>
 206      * This method transforms color values using algorithms designed
 207      * to produce the best perceptual match between input and output
 208      * colors.  In order to do colorimetric conversion of color values,
 209      * you should use the {@code toCIEXYZ}


 220      * @throws ArrayIndexOutOfBoundsException if array length is not
 221      * at least 3.
 222      */
 223     public float[]    fromRGB(float[] rgbvalue) {
 224 
 225         if (srgb2this == null) {
 226             ColorTransform[] transformList = new ColorTransform [2];
 227             ICC_ColorSpace srgbCS =
 228                 (ICC_ColorSpace) ColorSpace.getInstance (CS_sRGB);
 229             PCMM mdl = CMSManager.getModule();
 230             transformList[0] = mdl.createTransform(
 231                 srgbCS.getProfile(), ColorTransform.Any, ColorTransform.In);
 232             transformList[1] = mdl.createTransform(
 233                 thisProfile, ColorTransform.Any, ColorTransform.Out);
 234             srgb2this = mdl.createTransform(transformList);
 235             if (needScaleInit) {
 236                 setComponentScaling();
 237             }
 238         }
 239 
 240         short[] tmp = new short[3];
 241         for (int i = 0; i < 3; i++) {
 242             tmp[i] = (short) ((rgbvalue[i] * 65535.0f) + 0.5f);
 243         }
 244         tmp = srgb2this.colorConvert(tmp, null);
 245         int nc = this.getNumComponents();
 246         float[] result = new float [nc];
 247         for (int i = 0; i < nc; i++) {
 248             result[i] = (((float) (tmp[i] & 0xffff)) / 65535.0f) *
 249                         diffMinMax[i] + minVal[i];
 250         }
 251         return result;
 252     }
 253 
 254 
 255     /**
 256      * Transforms a color value assumed to be in this ColorSpace
 257      * into the CS_CIEXYZ conversion color space.
 258      * <p>
 259      * This method transforms color values using relative colorimetry,
 260      * as defined by the ICC Specification.  This


 362             ICC_ColorSpace xyzCS =
 363                 (ICC_ColorSpace) ColorSpace.getInstance (CS_CIEXYZ);
 364             PCMM mdl = CMSManager.getModule();
 365             try {
 366                 transformList[0] = mdl.createTransform(
 367                     thisProfile, ICC_Profile.icRelativeColorimetric,
 368                     ColorTransform.In);
 369             } catch (CMMException e) {
 370                 transformList[0] = mdl.createTransform(
 371                     thisProfile, ColorTransform.Any, ColorTransform.In);
 372             }
 373             transformList[1] = mdl.createTransform(
 374                 xyzCS.getProfile(), ColorTransform.Any, ColorTransform.Out);
 375             this2xyz = mdl.createTransform (transformList);
 376             if (needScaleInit) {
 377                 setComponentScaling();
 378             }
 379         }
 380 
 381         int nc = this.getNumComponents();
 382         short[] tmp = new short[nc];
 383         for (int i = 0; i < nc; i++) {
 384             tmp[i] = (short)
 385                 ((colorvalue[i] - minVal[i]) * invDiffMinMax[i] + 0.5f);
 386         }
 387         tmp = this2xyz.colorConvert(tmp, null);
 388         float ALMOST_TWO = 1.0f + (32767.0f / 32768.0f);
 389         // For CIEXYZ, min = 0.0, max = ALMOST_TWO for all components
 390         float[] result = new float [3];
 391         for (int i = 0; i < 3; i++) {
 392             result[i] = (((float) (tmp[i] & 0xffff)) / 65535.0f) * ALMOST_TWO;
 393         }
 394         return result;
 395     }
 396 
 397 
 398     /**
 399      * Transforms a color value assumed to be in the CS_CIEXYZ conversion
 400      * color space into this ColorSpace.
 401      * <p>
 402      * This method transforms color values using relative colorimetry,


 505             ColorTransform[] transformList = new ColorTransform [2];
 506             ICC_ColorSpace xyzCS =
 507                 (ICC_ColorSpace) ColorSpace.getInstance (CS_CIEXYZ);
 508             PCMM mdl = CMSManager.getModule();
 509             transformList[0] = mdl.createTransform (
 510                 xyzCS.getProfile(), ColorTransform.Any, ColorTransform.In);
 511             try {
 512                 transformList[1] = mdl.createTransform(
 513                     thisProfile, ICC_Profile.icRelativeColorimetric,
 514                     ColorTransform.Out);
 515             } catch (CMMException e) {
 516                 transformList[1] = CMSManager.getModule().createTransform(
 517                 thisProfile, ColorTransform.Any, ColorTransform.Out);
 518             }
 519             xyz2this = mdl.createTransform(transformList);
 520             if (needScaleInit) {
 521                 setComponentScaling();
 522             }
 523         }
 524 
 525         short[] tmp = new short[3];
 526         float ALMOST_TWO = 1.0f + (32767.0f / 32768.0f);
 527         float factor = 65535.0f / ALMOST_TWO;
 528         // For CIEXYZ, min = 0.0, max = ALMOST_TWO for all components
 529         for (int i = 0; i < 3; i++) {
 530             tmp[i] = (short) ((colorvalue[i] * factor) + 0.5f);
 531         }
 532         tmp = xyz2this.colorConvert(tmp, null);
 533         int nc = this.getNumComponents();
 534         float[] result = new float [nc];
 535         for (int i = 0; i < nc; i++) {
 536             result[i] = (((float) (tmp[i] & 0xffff)) / 65535.0f) *
 537                         diffMinMax[i] + minVal[i];
 538         }
 539         return result;
 540     }
 541 
 542     /**
 543      * Returns the minimum normalized color component value for the
 544      * specified component.  For TYPE_XYZ spaces, this method returns
 545      * minimum values of 0.0 for all components.  For TYPE_Lab spaces,


< prev index next >