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_ProfileGray} class is a subclass of the {@code ICC_Profile}
  43  * class that represents profiles which meet the following criteria: the color
  44  * space type of the profile is {@code TYPE_GRAY} and the profile includes the
  45  * {@code grayTRCTag} and {@code mediaWhitePointTag} tags. The
  46  * {@code getInstance} methods in the {@code ICC_Profile} class will return an
  47  * {@code ICC_ProfileGray} object when the above conditions are met. Examples of
  48  * this kind of profile are monochrome input profiles, monochrome display
  49  * profiles, and monochrome output profiles.
  50  * <p>
  51  * The advantage of this class is that it provides a lookup table that Java
  52  * or native methods can use directly to optimize color conversion in some
  53  * cases.
  54  * <p>
  55  * To transform from a GRAY device profile color space to the CIEXYZ Profile
  56  * Connection Space, the device gray component is transformed by a lookup
  57  * through the tone reproduction curve (TRC). The result is treated as the
  58  * achromatic component of the PCS.
  59  * <pre>
  60  *
  61  * &nbsp;               PCSY = grayTRC[deviceGray]
  62  *
  63  * </pre>
  64  * The inverse transform is done by converting the PCS Y components to device
  65  * Gray via the inverse of the grayTRC.
  66  */
  67 public class ICC_ProfileGray
  68 extends ICC_Profile {
  69 
  70     /**
  71      * Use serialVersionUID from JDK 1.2 for interoperability.
  72      */
  73     static final long serialVersionUID = -1124721290732002649L;
  74 
  75     /**
  76      * Constructs a new {@code ICC_ProfileGray} from a CMM ID.
  77      */
  78     ICC_ProfileGray(Profile p) {
  79         super(p);
  80     }
  81 
  82     /**
  83      * Constructs a new {@code ICC_ProfileGray} from a
  84      * {@code ProfileDeferralInfo} object.
  85      */
  86     ICC_ProfileGray(ProfileDeferralInfo pdi) {
  87         super(pdi);
  88     }
  89 
  90     /**
  91      * Returns a float array of length 3 containing the X, Y, and Z components
  92      * of the mediaWhitePointTag in the ICC profile.
  93      *
  94      * @return an array containing the components of the mediaWhitePointTag in
  95      *         the ICC profile
  96      */
  97     public float[] getMediaWhitePoint() {
  98         return super.getMediaWhitePoint();
  99     }
 100 
 101     /**
 102      * Returns a gamma value representing the tone reproduction curve (TRC). If
 103      * the profile represents the TRC as a table rather than a single gamma
 104      * value, then an exception is thrown. In this case the actual table can be
 105      * obtained via {@code getTRC()}. When using a gamma value, the PCS Y
 106      * component is computed as follows:
 107      * <pre>
 108      *
 109      * &nbsp;                         gamma
 110      * &nbsp;        PCSY = deviceGray
 111      *
 112      * </pre>
 113      *
 114      * @return the gamma value as a float
 115      * @throws ProfileDataException if the profile does not specify the TRC as a
 116      *         single gamma value
 117      */
 118     public float getGamma() {
 119     float theGamma;
 120 
 121         theGamma = super.getGamma(ICC_Profile.icSigGrayTRCTag);
 122         return theGamma;
 123     }
 124 
 125     /**
 126      * Returns the TRC as an array of shorts. If the profile has specified the
 127      * TRC as linear (gamma = 1.0) or as a simple gamma value, this method
 128      * throws an exception, and the {@code getGamma()} method should be used to
 129      * get the gamma value. Otherwise the short array returned here represents a
 130      * lookup table where the input Gray value is conceptually in the range
 131      * [0.0, 1.0]. Value 0.0 maps to array index 0 and value 1.0 maps to array
 132      * index {@code length-1}. Interpolation may be used to generate output
 133      * values for input values which do not map exactly to an index in the
 134      * array. Output values also map linearly to the range [0.0, 1.0]. Value 0.0
 135      * is represented by an array value of 0x0000 and value 1.0 by 0xFFFF, i.e.
 136      * the values are really unsigned short values, although they are returned
 137      * in a short array.
 138      *
 139      * @return a short array representing the TRC
 140      * @throws ProfileDataException if the profile does not specify the TRC as a
 141      *         table
 142      */
 143     public short[] getTRC() {
 144     short[]    theTRC;
 145 
 146         theTRC = super.getTRC(ICC_Profile.icSigGrayTRCTag);
 147         return theTRC;
 148     }
 149 
 150 }