FileDocCategorySizeDatePackage
ICC_Profile.javaAPI DocAndroid 1.5 API45811Wed May 06 22:41:54 BST 2009java.awt.color

ICC_Profile

public class ICC_Profile extends Object implements Serializable
The ICC_Profile class represents a color profile data for color spaces based on the International Color Consortium Specification ICC.1:2001-12, File Format for Color Profiles.
since
Android 1.0

Fields Summary
private static final long
serialVersionUID
The Constant serialVersionUID.
public static final int
CLASS_INPUT
The Constant CLASS_INPUT indicates that profile class is input.
public static final int
CLASS_DISPLAY
The Constant CLASS_DISPLAY indicates that profile class is display.
public static final int
CLASS_OUTPUT
The Constant CLASS_OUTPUT indicates that profile class is output.
public static final int
CLASS_DEVICELINK
The Constant CLASS_DEVICELINK indicates that profile class is device link.
public static final int
CLASS_COLORSPACECONVERSION
The Constant CLASS_COLORSPACECONVERSION indicates that profile class is color space conversion.
public static final int
CLASS_ABSTRACT
The Constant CLASS_ABSTRACT indicates that profile class is abstract.
public static final int
CLASS_NAMEDCOLOR
The Constant CLASS_NAMEDCOLOR indicates that profile class is named color.
public static final int
icSigXYZData
The Constant icSigXYZData - ICC Profile Color Space Type Signature.
public static final int
icSigLabData
The Constant icSigLabData - ICC Profile Color Space Type Signature.
public static final int
icSigLuvData
The Constant icSigLuvData - ICC Profile Color Space Type Signature.
public static final int
icSigYCbCrData
The Constant icSigYCbCrData - ICC Profile Color Space Type Signature.
public static final int
icSigYxyData
The Constant icSigYxyData - ICC Profile Color Space Type Signature.
public static final int
icSigRgbData
The Constant icSigRgbData - ICC Profile Color Space Type Signature.
public static final int
icSigGrayData
The Constant icSigGrayData - ICC Profile Color Space Type Signature.
public static final int
icSigHsvData
The Constant icSigHsvData - ICC Profile Color Space Type Signature.
public static final int
icSigHlsData
The Constant icSigHlsData - ICC Profile Color Space Type Signature.
public static final int
icSigCmykData
The Constant icSigCmykData - ICC Profile Color Space Type Signature.
public static final int
icSigCmyData
The Constant icSigCmyData - ICC Profile Color Space Type Signature.
public static final int
icSigSpace2CLR
The Constant icSigSpace2CLR - ICC Profile Color Space Type Signature.
public static final int
icSigSpace3CLR
The Constant icSigSpace3CLR - ICC Profile Color Space Type Signature.
public static final int
icSigSpace4CLR
The Constant icSigSpace4CLR - ICC Profile Color Space Type Signature.
public static final int
icSigSpace5CLR
The Constant icSigSpace5CLR - ICC Profile Color Space Type Signature.
public static final int
icSigSpace6CLR
The Constant icSigSpace6CLR - ICC Profile Color Space Type Signature.
public static final int
icSigSpace7CLR
The Constant icSigSpace7CLR - ICC Profile Color Space Type Signature.
public static final int
icSigSpace8CLR
The Constant icSigSpace8CLR - ICC Profile Color Space Type Signature.
public static final int
icSigSpace9CLR
The Constant icSigSpace9CLR - ICC Profile Color Space Type Signature.
public static final int
icSigSpaceACLR
The Constant icSigSpaceACLR - ICC Profile Color Space Type Signature.
public static final int
icSigSpaceBCLR
The Constant icSigSpaceBCLR - ICC Profile Color Space Type Signature.
public static final int
icSigSpaceCCLR
The Constant icSigSpaceCCLR - ICC Profile Color Space Type Signature.
public static final int
icSigSpaceDCLR
The Constant icSigSpaceDCLR - ICC Profile Color Space Type Signature.
public static final int
icSigSpaceECLR
The Constant icSigSpaceECLR - ICC Profile Color Space Type Signature.
public static final int
icSigSpaceFCLR
The Constant icSigSpaceFCLR - ICC Profile Color Space Type Signature.
public static final int
icSigInputClass
The Constant icSigInputClass - ICC Profile Class Signature.
public static final int
icSigDisplayClass
The Constant icSigDisplayClass - ICC Profile Class Signature.
public static final int
icSigOutputClass
The Constant icSigOutputClass - ICC Profile Class Signature.
public static final int
icSigLinkClass
The Constant icSigLinkClass - ICC Profile Class Signature.
public static final int
icSigAbstractClass
The Constant icSigAbstractClass - ICC Profile Class Signature.
public static final int
icSigColorantOrderTag
The Constant icSigColorantOrderTag - ICC Profile Tag Signature.
public static final int
icSigColorantTableTag
The Constant icSigColorantTableTag - ICC Profile Tag Signature.
public static final int
icSigColorSpaceClass
The Constant icSigColorSpaceClass - ICC Profile Tag Signature.
public static final int
icSigNamedColorClass
The Constant icSigNamedColorClass - ICC Profile Tag Signature.
public static final int
icPerceptual
The Constant icPerceptual - ICC Profile Rendering Intent.
public static final int
icRelativeColorimetric
The Constant icRelativeColorimetric - ICC Profile Rendering Intent.
public static final int
icSaturation
The Constant icSaturation - ICC Profile Rendering Intent.
public static final int
icAbsoluteColorimetric
The Constant icAbsoluteColorimetric - ICC Profile Rendering Intent.
public static final int
icSigHead
The Constant icSigHead - ICC Profile Tag Signature.
public static final int
icSigAToB0Tag
The Constant icSigAToB0Tag - ICC Profile Tag Signature.
public static final int
icSigAToB1Tag
The Constant icSigAToB1Tag - ICC Profile Tag Signature.
public static final int
icSigAToB2Tag
The Constant icSigAToB2Tag - ICC Profile Tag Signature.
public static final int
icSigBlueColorantTag
The Constant icSigBlueColorantTag - ICC Profile Tag Signature.
public static final int
icSigBlueMatrixColumnTag
The Constant icSigBlueMatrixColumnTag - ICC Profile Tag Signature.
public static final int
icSigBlueTRCTag
The Constant icSigBlueTRCTag - ICC Profile Tag Signature.
public static final int
icSigBToA0Tag
The Constant icSigBToA0Tag - ICC Profile Tag Signature.
public static final int
icSigBToA1Tag
The Constant icSigBToA1Tag - ICC Profile Tag Signature.
public static final int
icSigBToA2Tag
The Constant icSigBToA2Tag - ICC Profile Tag Signature.
public static final int
icSigCalibrationDateTimeTag
The Constant icSigCalibrationDateTimeTag - ICC Profile Tag Signature.
public static final int
icSigCharTargetTag
The Constant icSigCharTargetTag - ICC Profile Tag Signature.
public static final int
icSigCopyrightTag
The Constant icSigCopyrightTag - ICC Profile Tag Signature.
public static final int
icSigCrdInfoTag
The Constant icSigCrdInfoTag - ICC Profile Tag Signature.
public static final int
icSigDeviceMfgDescTag
The Constant icSigDeviceMfgDescTag - ICC Profile Tag Signature.
public static final int
icSigDeviceModelDescTag
The Constant icSigDeviceModelDescTag - ICC Profile Tag Signature.
public static final int
icSigDeviceSettingsTag
The Constant icSigDeviceSettingsTag - ICC Profile Tag Signature.
public static final int
icSigGamutTag
The Constant icSigGamutTag - ICC Profile Tag Signature.
public static final int
icSigGrayTRCTag
The Constant icSigGrayTRCTag - ICC Profile Tag Signature.
public static final int
icSigGreenColorantTag
The Constant icSigGreenColorantTag - ICC Profile Tag Signature.
public static final int
icSigGreenMatrixColumnTag
The Constant icSigGreenMatrixColumnTag - ICC Profile Tag Signature.
public static final int
icSigGreenTRCTag
The Constant icSigGreenTRCTag - ICC Profile Tag Signature.
public static final int
icSigLuminanceTag
The Constant icSigLuminanceTag - ICC Profile Tag Signature.
public static final int
icSigMeasurementTag
The Constant icSigMeasurementTag - ICC Profile Tag Signature.
public static final int
icSigMediaBlackPointTag
The Constant icSigMediaBlackPointTag - ICC Profile Tag Signature.
public static final int
icSigMediaWhitePointTag
The Constant icSigMediaWhitePointTag - ICC Profile Tag Signature.
public static final int
icSigNamedColor2Tag
The Constant icSigNamedColor2Tag - ICC Profile Tag Signature.
public static final int
icSigOutputResponseTag
The Constant icSigOutputResponseTag - ICC Profile Tag Signature.
public static final int
icSigPreview0Tag
The Constant icSigPreview0Tag - ICC Profile Tag Signature.
public static final int
icSigPreview1Tag
The Constant icSigPreview1Tag - ICC Profile Tag Signature.
public static final int
icSigPreview2Tag
The Constant icSigPreview2Tag - ICC Profile Tag Signature.
public static final int
icSigProfileDescriptionTag
The Constant icSigProfileDescriptionTag - ICC Profile Tag Signature.
public static final int
icSigProfileSequenceDescTag
The Constant icSigProfileSequenceDescTag - ICC Profile Tag Signature.
public static final int
icSigPs2CRD0Tag
The Constant icSigPs2CRD0Tag - ICC Profile Tag Signature.
public static final int
icSigPs2CRD1Tag
The Constant icSigPs2CRD1Tag - ICC Profile Tag Signature.
public static final int
icSigPs2CRD2Tag
The Constant icSigPs2CRD2Tag - ICC Profile Tag Signature.
public static final int
icSigPs2CRD3Tag
The Constant icSigPs2CRD3Tag - ICC Profile Tag Signature.
public static final int
icSigPs2CSATag
The Constant icSigPs2CSATag - ICC Profile Tag Signature.
public static final int
icSigPs2RenderingIntentTag
The Constant icSigPs2RenderingIntentTag - ICC Profile Tag Signature.
public static final int
icSigRedColorantTag
The Constant icSigRedColorantTag - ICC Profile Tag Signature.
public static final int
icSigRedMatrixColumnTag
The Constant icSigRedMatrixColumnTag - ICC Profile Tag Signature.
public static final int
icSigRedTRCTag
The Constant icSigRedTRCTag - ICC Profile Tag Signature.
public static final int
icSigScreeningDescTag
The Constant icSigScreeningDescTag - ICC Profile Tag Signature.
public static final int
icSigScreeningTag
The Constant icSigScreeningTag - ICC Profile Tag Signature.
public static final int
icSigTechnologyTag
The Constant icSigTechnologyTag - ICC Profile Tag Signature.
public static final int
icSigUcrBgTag
The Constant icSigUcrBgTag - ICC Profile Tag Signature.
public static final int
icSigViewingCondDescTag
The Constant icSigViewingCondDescTag - ICC Profile Tag Signature.
public static final int
icSigViewingConditionsTag
The Constant icSigViewingConditionsTag - ICC Profile Tag Signature.
public static final int
icSigChromaticAdaptationTag
The Constant icSigChromaticAdaptationTag - ICC Profile Tag Signature.
public static final int
icSigChromaticityTag
The Constant icSigChromaticityTag - ICC Profile Tag Signature.
public static final int
icHdrSize
The Constant icHdrSize - ICC Profile Header Location.
public static final int
icHdrCmmId
The Constant icHdrCmmId - ICC Profile Header Location.
public static final int
icHdrVersion
The Constant icHdrVersion - ICC Profile Header Location.
public static final int
icHdrDeviceClass
The Constant icHdrDeviceClass - ICC Profile Header Location.
public static final int
icHdrColorSpace
The Constant icHdrColorSpace - ICC Profile Header Location.
public static final int
icHdrPcs
The Constant icHdrPcs - ICC Profile Header Location.
public static final int
icHdrDate
The Constant icHdrDate - ICC Profile Header Location.
public static final int
icHdrMagic
The Constant icHdrMagic - ICC Profile Header Location.
public static final int
icHdrPlatform
The Constant icHdrPlatform - ICC Profile Header Location.
public static final int
icHdrProfileID
The Constant icHdrProfileID - ICC Profile Header Location.
public static final int
icHdrFlags
The Constant icHdrFlags - ICC Profile Header Location.
public static final int
icHdrManufacturer
The Constant icHdrManufacturer - ICC Profile Header Location.
public static final int
icHdrModel
The Constant icHdrModel - ICC Profile Header Location.
public static final int
icHdrAttributes
The Constant icHdrAttributes - ICC Profile Header Location.
public static final int
icHdrRenderingIntent
The Constant icHdrRenderingIntent - ICC Profile Header Location.
public static final int
icHdrIlluminant
The Constant icHdrIlluminant - ICC Profile Header Location.
public static final int
icHdrCreator
The Constant icHdrCreator - ICC Profile Header Location.
public static final int
icICCAbsoluteColorimetric
The Constant icICCAbsoluteColorimetric - ICC Profile Rendering Intent.
public static final int
icMediaRelativeColorimetric
The Constant icMediaRelativeColorimetric - ICC Profile Rendering Intent.
public static final int
icTagType
The Constant icTagType - ICC Profile Constant.
public static final int
icTagReserved
The Constant icTagReserved - ICC Profile Constant.
public static final int
icCurveCount
The Constant icCurveCount - ICC Profile Constant.
public static final int
icCurveData
The Constant icCurveData - ICC Profile Constant.
public static final int
icXYZNumberX
The Constant icXYZNumberX - ICC Profile Constant.
private static final int
headerSize
Size of a profile header.
private static final int
headerMagicNumber
header magic number.
private static ICC_Profile
sRGBProfile
The s rgb profile.
private static ICC_Profile
xyzProfile
The xyz profile.
private static ICC_Profile
grayProfile
The gray profile.
private static ICC_Profile
pyccProfile
The pycc profile.
private static ICC_Profile
linearRGBProfile
The linear rgb profile.
private transient long
profileHandle
Handle to the current profile.
private transient boolean
handleStolen
If handle is used by another class this object is not responsible for closing profile.
private transient byte[]
headerData
Cached header data.
private transient ICC_Profile
openedProfileObject
Serialization support.
Constructors Summary
private ICC_Profile(byte[] data)
Instantiates a new ICC profile with the given data.

param
data the data.


                                  
       
        profileHandle = NativeCMM.cmmOpenProfile(data);
        NativeCMM.addHandle(this, profileHandle);
    
ICC_Profile()
Used to instantiate dummy ICC_ProfileStub objects.

    
ICC_Profile(long profileHandle)
Used to instantiate subclasses (ICC_ProfileGrey and ICC_ProfileRGB).

param
profileHandle - should be valid handle to opened color profile

        this.profileHandle = profileHandle;
        // A new object reference, need to add it.
        NativeCMM.addHandle(this, profileHandle);
    
Methods Summary
private intcsFromSignature(int signature)
Converts ICC color space signature to the java predefined color space type.

param
signature the signature
return
the int

        switch (signature) {
            case icSigRgbData:
                return ColorSpace.TYPE_RGB;
            case icSigXYZData:
                return ColorSpace.TYPE_XYZ;
            case icSigCmykData:
                return ColorSpace.TYPE_CMYK;
            case icSigLabData:
                return ColorSpace.TYPE_Lab;
            case icSigGrayData:
                return ColorSpace.TYPE_GRAY;
            case icSigHlsData:
                return ColorSpace.TYPE_HLS;
            case icSigLuvData:
                return ColorSpace.TYPE_Luv;
            case icSigYCbCrData:
                return ColorSpace.TYPE_YCbCr;
            case icSigYxyData:
                return ColorSpace.TYPE_Yxy;
            case icSigHsvData:
                return ColorSpace.TYPE_HSV;
            case icSigCmyData:
                return ColorSpace.TYPE_CMY;
            case icSigSpace2CLR:
                return ColorSpace.TYPE_2CLR;
            case icSigSpace3CLR:
                return ColorSpace.TYPE_3CLR;
            case icSigSpace4CLR:
                return ColorSpace.TYPE_4CLR;
            case icSigSpace5CLR:
                return ColorSpace.TYPE_5CLR;
            case icSigSpace6CLR:
                return ColorSpace.TYPE_6CLR;
            case icSigSpace7CLR:
                return ColorSpace.TYPE_7CLR;
            case icSigSpace8CLR:
                return ColorSpace.TYPE_8CLR;
            case icSigSpace9CLR:
                return ColorSpace.TYPE_9CLR;
            case icSigSpaceACLR:
                return ColorSpace.TYPE_ACLR;
            case icSigSpaceBCLR:
                return ColorSpace.TYPE_BCLR;
            case icSigSpaceCCLR:
                return ColorSpace.TYPE_CCLR;
            case icSigSpaceDCLR:
                return ColorSpace.TYPE_DCLR;
            case icSigSpaceECLR:
                return ColorSpace.TYPE_ECLR;
            case icSigSpaceFCLR:
                return ColorSpace.TYPE_FCLR;
            default:
        }

        // awt.165=Color space doesn't comply with ICC specification
        throw new IllegalArgumentException(Messages.getString("awt.165")); //$NON-NLS-1$
    
protected voidfinalize()
Frees the resources associated with an ICC_Profile object.

        if (profileHandle != 0 && !handleStolen) {
            NativeCMM.cmmCloseProfile(profileHandle);
        }

        // Always remove because key no more exist
        // when object is destroyed
        NativeCMM.removeHandle(this);
    
private bytegetByteFromHeader(int idx)
Reads byte from the profile header at the specified position.

param
idx - offset in bytes from the beginning of the header
return
the byte from header

        if (headerData == null) {
            headerData = getData(icSigHead);
        }

        return headerData[idx];
    
public intgetColorSpaceType()
Gets the color space type of this ICC_Profile.

return
the color space type.

        return csFromSignature(getIntFromHeader(icHdrColorSpace));
    
public byte[]getData(int tagSignature)
Gets a tagged data element from the profile as a byte array. Elements are identified by tag signatures as defined in the ICC specification.

param
tagSignature the ICC tag signature for the data element to get.
return
a byte array that contains the tagged data element.

        int tagSize = 0;
        try {
            tagSize = NativeCMM.cmmGetProfileElementSize(profileHandle, tagSignature);
        } catch (CMMException e) {
            // We'll get this exception if there's no element with
            // the specified tag signature
            return null;
        }

        byte[] data = new byte[tagSize];
        NativeCMM.cmmGetProfileElement(profileHandle, tagSignature, data);
        return data;
    
public byte[]getData()
Gets a data byte array of this ICC_Profile.

return
a byte array that contains the ICC Profile data.

        int profileSize = NativeCMM.cmmGetProfileSize(profileHandle);
        byte[] data = new byte[profileSize];
        NativeCMM.cmmGetProfile(profileHandle, data);
        return data;
    
private intgetDataSize(int tagSignature)
Gets the data size.

param
tagSignature the tag signature
return
the data size

        return NativeCMM.cmmGetProfileElementSize(profileHandle, tagSignature);
    
floatgetGamma(int tagSignature)
Gets the gamma.

param
tagSignature the tag signature
return
the gamma

        short[] dataTRC = null;
        float gamma = getGammaOrTRC(tagSignature, dataTRC);

        if (dataTRC == null) {
            return gamma;
        }
        // awt.166=TRC is not a simple gamma value.
        throw new ProfileDataException(Messages.getString("awt.166")); //$NON-NLS-1$
    
private floatgetGammaOrTRC(int tagSignature, short[] dataTRC)
If TRC is not a table returns gamma via return value and sets dataTRC to null. If TRC is a table returns 0 and fills dataTRC with values.

param
tagSignature the tag signature
param
dataTRC the data trc
return
- gamma or zero if TRC is a table

        byte[] data = getData(tagSignature);
        int trcSize = ICC_ProfileHelper.getIntFromByteArray(data, icCurveCount);

        dataTRC = null;

        if (trcSize == 0) {
            return 1.0f;
        }

        if (trcSize == 1) {
            // Cast from ICC u8Fixed8Number to float
            return ICC_ProfileHelper.getShortFromByteArray(data, icCurveData) / 256.f;
        }

        // TRC is a table
        dataTRC = new short[trcSize];
        for (int i = 0, pos = icCurveData; i < trcSize; i++, pos += 2) {
            dataTRC[i] = ICC_ProfileHelper.getShortFromByteArray(data, pos);
        }
        return 0;
    
public static java.awt.color.ICC_ProfilegetInstance(java.lang.String fileName)
Gets the single instance of ICC_Profile from data in the specified file.

param
fileName the specified name of file with ICC profile data.
return
single instance of ICC_Profile.
throws
IOException signals that an I/O error occurred while reading the file or the file does not exist.

        final String fName = fileName; // to use in the privileged block

        FileInputStream fiStream = (FileInputStream)AccessController
                .doPrivileged(new PrivilegedAction<FileInputStream>() {
                    public FileInputStream run() {
                        FileInputStream fiStream = null;

                        // Open absolute path
                        try {
                            fiStream = new FileInputStream(fName);
                            if (fiStream != null) {
                                return fiStream;
                            }
                        } catch (FileNotFoundException e) {
                        }

                        // Check java.iccprofile.path entries
                        fiStream = tryPath(System.getProperty("java.iccprofile.path"), fName); //$NON-NLS-1$
                        if (fiStream != null) {
                            return fiStream;
                        }

                        // Check java.class.path entries
                        fiStream = tryPath(System.getProperty("java.class.path"), fName); //$NON-NLS-1$
                        if (fiStream != null) {
                            return fiStream;
                        }

                        // Check directory with java sample profiles
                        String home = System.getProperty("java.home"); //$NON-NLS-1$
                        if (home != null) {
                            fiStream = tryPath(home + File.separatorChar
                                    + "lib" + File.separatorChar + "cmm", fName //$NON-NLS-1$ //$NON-NLS-2$
                            );
                        }

                        return fiStream;
                    }
                });

        if (fiStream == null) {
            // awt.161=Unable to open file {0}
            throw new IOException(Messages.getString("awt.161", fileName)); //$NON-NLS-1$
        }

        ICC_Profile pf = getInstance(fiStream);
        fiStream.close();
        return pf;
    
public static java.awt.color.ICC_ProfilegetInstance(java.io.InputStream s)
Gets the single instance of ICC_Profile with data in the specified InputStream.

param
s the InputStream with ICC profile data.
return
single instance of ICC_Profile.
throws
IOException if an I/O exception has occurred during reading from InputStream.
throws
IllegalArgumentException if the file does not contain valid ICC Profile data.

        byte[] header = new byte[headerSize];
        // awt.162=Invalid ICC Profile Data
        String invalidDataMessage = Messages.getString("awt.162"); //$NON-NLS-1$

        // Get header from the input stream
        if (s.read(header) != headerSize) {
            throw new IllegalArgumentException(invalidDataMessage);
        }

        // Check the profile data for consistency
        if (ICC_ProfileHelper.getBigEndianFromByteArray(header, icHdrMagic) != headerMagicNumber) {
            throw new IllegalArgumentException(invalidDataMessage);
        }

        // Get profile size from header, create an array for profile data
        int profileSize = ICC_ProfileHelper.getBigEndianFromByteArray(header, icHdrSize);
        byte[] profileData = new byte[profileSize];

        // Copy header into it
        System.arraycopy(header, 0, profileData, 0, headerSize);

        // Read the profile itself
        if (s.read(profileData, headerSize, profileSize - headerSize) != profileSize - headerSize) {
            throw new IllegalArgumentException(invalidDataMessage);
        }

        return getInstance(profileData);
    
public static java.awt.color.ICC_ProfilegetInstance(byte[] data)
Gets the single instance of ICC_Profile from the specified data in a byte array.

param
data the byte array of ICC profile.
return
single instance of ICC_Profile from the specified data in a byte array.
throws
IllegalArgumentException if the file does not contain valid ICC Profile data.

        ICC_Profile res = null;

        try {
            res = new ICC_Profile(data);
        } catch (CMMException e) {
            // awt.162=Invalid ICC Profile Data
            throw new IllegalArgumentException(Messages.getString("awt.162")); //$NON-NLS-1$
        }

        if (System.getProperty("os.name").toLowerCase().indexOf("windows") >= 0) { //$NON-NLS-1$ //$NON-NLS-2$
            try {
                if (res.getColorSpaceType() == ColorSpace.TYPE_RGB
                        && res.getDataSize(icSigMediaWhitePointTag) > 0
                        && res.getDataSize(icSigRedColorantTag) > 0
                        && res.getDataSize(icSigGreenColorantTag) > 0
                        && res.getDataSize(icSigBlueColorantTag) > 0
                        && res.getDataSize(icSigRedTRCTag) > 0
                        && res.getDataSize(icSigGreenTRCTag) > 0
                        && res.getDataSize(icSigBlueTRCTag) > 0) {
                    res = new ICC_ProfileRGB(res.getProfileHandle());
                } else if (res.getColorSpaceType() == ColorSpace.TYPE_GRAY
                        && res.getDataSize(icSigMediaWhitePointTag) > 0
                        && res.getDataSize(icSigGrayTRCTag) > 0) {
                    res = new ICC_ProfileGray(res.getProfileHandle());
                }

            } catch (CMMException e) { /* return res in this case */
            }
        }

        return res;
    
public static java.awt.color.ICC_ProfilegetInstance(int cspace)
Gets the single instance of ICC_Profile with the specific color space defined by the ColorSpace class: CS_sRGB, CS_LINEAR_RGB, CS_CIEXYZ, CS_PYCC, CS_GRAY.

param
cspace the type of color space defined in the ColorSpace class.
return
single instance of ICC_Profile.
throws
IllegalArgumentException is not one of the defined color space types.

        try {
            switch (cspace) {

                case ColorSpace.CS_sRGB:
                    if (sRGBProfile == null) {
                        sRGBProfile = getInstance("sRGB.pf"); //$NON-NLS-1$
                    }
                    return sRGBProfile;

                case ColorSpace.CS_CIEXYZ:
                    if (xyzProfile == null) {
                        xyzProfile = getInstance("CIEXYZ.pf"); //$NON-NLS-1$
                    }
                    return xyzProfile;

                case ColorSpace.CS_GRAY:
                    if (grayProfile == null) {
                        grayProfile = getInstance("GRAY.pf"); //$NON-NLS-1$
                    }
                    return grayProfile;

                case ColorSpace.CS_PYCC:
                    if (pyccProfile == null) {
                        pyccProfile = getInstance("PYCC.pf"); //$NON-NLS-1$
                    }
                    return pyccProfile;

                case ColorSpace.CS_LINEAR_RGB:
                    if (linearRGBProfile == null) {
                        linearRGBProfile = getInstance("LINEAR_RGB.pf"); //$NON-NLS-1$
                    }
                    return linearRGBProfile;
            }

        } catch (IOException e) {
            // awt.163=Can't open color profile
            throw new IllegalArgumentException(Messages.getString("Can't open color profile")); //$NON-NLS-1$
        }

        // awt.164=Not a predefined color space
        throw new IllegalArgumentException(Messages.getString("Not a predefined color space")); //$NON-NLS-1$
    
private intgetIntFromHeader(int idx)
Reads an integer from the profile header at the specified position.

param
idx - offset in bytes from the beginning of the header
return
the integer value from header

        if (headerData == null) {
            headerData = getData(icSigHead);
        }

        return ((headerData[idx] & 0xFF) << 24) | ((headerData[idx + 1] & 0xFF) << 16)
                | ((headerData[idx + 2] & 0xFF) << 8) | ((headerData[idx + 3] & 0xFF));
    
public intgetMajorVersion()
Gets the major version of this ICC profile.

return
the major version of this ICC profile.

        return getByteFromHeader(icHdrVersion);
    
float[]getMediaWhitePoint()
Gets the media white point.

return
the media white point.

        return getXYZValue(icSigMediaWhitePointTag);
    
public intgetMinorVersion()
Gets the minor version of this ICC profile.

return
the minor version of this ICC profile.

        return getByteFromHeader(icHdrVersion + 1);
    
public intgetNumComponents()
Gets the number of components of this ICC Profile.

return
the number of components of this ICC Profile.

        switch (getIntFromHeader(icHdrColorSpace)) {
            // The most common cases go first to increase speed
            case icSigRgbData:
            case icSigXYZData:
            case icSigLabData:
                return 3;
            case icSigCmykData:
                return 4;
                // Then all other
            case icSigGrayData:
                return 1;
            case icSigSpace2CLR:
                return 2;
            case icSigYCbCrData:
            case icSigLuvData:
            case icSigYxyData:
            case icSigHlsData:
            case icSigHsvData:
            case icSigCmyData:
            case icSigSpace3CLR:
                return 3;
            case icSigSpace4CLR:
                return 4;
            case icSigSpace5CLR:
                return 5;
            case icSigSpace6CLR:
                return 6;
            case icSigSpace7CLR:
                return 7;
            case icSigSpace8CLR:
                return 8;
            case icSigSpace9CLR:
                return 9;
            case icSigSpaceACLR:
                return 10;
            case icSigSpaceBCLR:
                return 11;
            case icSigSpaceCCLR:
                return 12;
            case icSigSpaceDCLR:
                return 13;
            case icSigSpaceECLR:
                return 14;
            case icSigSpaceFCLR:
                return 15;
            default:
        }

        // awt.160=Color space doesn't comply with ICC specification
        throw new ProfileDataException(Messages.getString("awt.160") //$NON-NLS-1$
        );
    
public intgetPCSType()
Gets the color space type of the Profile Connection Space (PCS).

return
the PCS type.

        return csFromSignature(getIntFromHeader(icHdrPcs));
    
public intgetProfileClass()
Gets the profile class.

return
the profile class constant.

        int deviceClassSignature = getIntFromHeader(icHdrDeviceClass);

        switch (deviceClassSignature) {
            case icSigColorSpaceClass:
                return CLASS_COLORSPACECONVERSION;
            case icSigDisplayClass:
                return CLASS_DISPLAY;
            case icSigOutputClass:
                return CLASS_OUTPUT;
            case icSigInputClass:
                return CLASS_INPUT;
            case icSigLinkClass:
                return CLASS_DEVICELINK;
            case icSigAbstractClass:
                return CLASS_ABSTRACT;
            case icSigNamedColorClass:
                return CLASS_NAMEDCOLOR;
            default:
        }

        // Not an ICC profile class
        // awt.15F=Profile class does not comply with ICC specification
        throw new IllegalArgumentException(Messages.getString("awt.15F")); //$NON-NLS-1$

    
private longgetProfileHandle()
Gets the profile handle.

return
the profile handle

        handleStolen = true;
        return profileHandle;
    
short[]getTRC(int tagSignature)
Gets the TRC.

param
tagSignature the tag signature
return
the tRC

        short[] dataTRC = null;
        getGammaOrTRC(tagSignature, dataTRC);

        if (dataTRC == null) {
            // awt.167=TRC is a gamma value, not a table.
            throw new ProfileDataException(Messages.getString("awt.167")); //$NON-NLS-1$
        }
        return dataTRC;
    
float[]getXYZValue(int tagSignature)
Reads XYZ value from the tag data.

param
tagSignature the tag signature
return
the XYZ value

        float[] res = new float[3];
        byte[] data = getData(tagSignature);

        // Convert from ICC s15Fixed16Number type
        // 1 (float) = 0x10000 (s15Fixed16Number),
        // hence dividing by 0x10000
        res[0] = ICC_ProfileHelper.getIntFromByteArray(data, 0) / 65536.f;
        res[1] = ICC_ProfileHelper.getIntFromByteArray(data, 4) / 65536.f;
        res[2] = ICC_ProfileHelper.getIntFromByteArray(data, 8) / 65536.f;

        return res;
    
private voidreadObject(java.io.ObjectInputStream s)
Serializable implementation.

param
s the s
throws
IOException Signals that an I/O exception has occurred.
throws
ClassNotFoundException the class not found exception

        s.defaultReadObject();
        String colorSpaceStr = (String)s.readObject();
        byte[] data = (byte[])s.readObject();

        if (colorSpaceStr != null) {
            if (colorSpaceStr.equals("CS_sRGB")) { //$NON-NLS-1$
                openedProfileObject = getInstance(ColorSpace.CS_sRGB);
            } else if (colorSpaceStr.equals("CS_GRAY")) { //$NON-NLS-1$
                openedProfileObject = getInstance(ColorSpace.CS_GRAY);
            } else if (colorSpaceStr.equals("CS_LINEAR_RGB")) { //$NON-NLS-1$
                openedProfileObject = getInstance(ColorSpace.CS_LINEAR_RGB);
            } else if (colorSpaceStr.equals("CS_CIEXYZ")) { //$NON-NLS-1$
                openedProfileObject = getInstance(ColorSpace.CS_CIEXYZ);
            } else if (colorSpaceStr.equals("CS_PYCC")) { //$NON-NLS-1$
                openedProfileObject = getInstance(ColorSpace.CS_PYCC);
            } else {
                openedProfileObject = ICC_Profile.getInstance(data);
            }
        } else {
            openedProfileObject = ICC_Profile.getInstance(data);
        }
    
protected java.lang.ObjectreadResolve()
Resolves instances being deserialized into instances registered with CMM.

return
ICC_Profile object for profile registered with CMM.
throws
ObjectStreamException if there is an error in the serialized files or during the process of reading them.

        return openedProfileObject;
    
public voidsetData(int tagSignature, byte[] tagData)
Sets a tagged data element in the profile from a byte array.

param
tagSignature the ICC tag signature for the data element to be set.
param
tagData the data to be set for the specified tag signature.

        NativeCMM.cmmSetProfileElement(profileHandle, tagSignature, tagData);
        // Remove cached header data if header is modified
        if (tagSignature == icSigHead) {
            headerData = null;
        }
    
private static java.io.FileInputStreamtryPath(java.lang.String path, java.lang.String fileName)
Tries to open the file at the specified path. Path entries can be divided by a separator character.

param
path the path to the file.
param
fileName the file name.
return
the input stream to read the file.

        FileInputStream fiStream = null;

        if (path == null) {
            return null;
        }

        StringTokenizer st = new StringTokenizer(path, File.pathSeparator);

        while (st.hasMoreTokens()) {
            String pathEntry = st.nextToken();
            try {
                fiStream = new FileInputStream(pathEntry + File.separatorChar + fileName);
                if (fiStream != null) {
                    return fiStream;
                }
            } catch (FileNotFoundException e) {
            }
        }

        return fiStream;
    
public voidwrite(java.lang.String fileName)
Writes the ICC_Profile to a file with the specified name.

param
fileName the file name.
throws
IOException if an I/O exception has occurred during writing or opening the file.

        FileOutputStream oStream = new FileOutputStream(fileName);
        oStream.write(getData());
        oStream.close();
    
public voidwrite(java.io.OutputStream s)
Writes the ICC_Profile to an OutputStream.

param
s the OutputStream.
throws
IOException signals that an I/O exception has occurred during writing or opening OutputStream.

        s.write(getData());
    
private voidwriteObject(java.io.ObjectOutputStream s)
Serializable implementation.

param
s the s
throws
IOException Signals that an I/O exception has occurred.

        s.defaultWriteObject();
        s.writeObject(null);
        s.writeObject(getData());