FileDocCategorySizeDatePackage
ICC_Profile.javaAPI DocJava SE 5 API62769Fri Aug 26 14:56:46 BST 2005java.awt.color

ICC_Profile

public class ICC_Profile extends Object implements Serializable
A representation of color profile data for device independent and device dependent color spaces based on the International Color Consortium Specification ICC.1:2001-12, File Format for Color Profiles, (see http://www.color.org).

An ICC_ColorSpace object can be constructed from an appropriate ICC_Profile. Typically, an ICC_ColorSpace would be associated with an ICC Profile which is either an input, display, or output profile (see the ICC specification). There are also device link, abstract, color space conversion, and named color profiles. These are less useful for tagging a color or image, but are useful for other purposes (in particular device link profiles can provide improved performance for converting from one device's color space to another's).

ICC Profiles represent transformations from the color space of the profile (e.g. a monitor) to a Profile Connection Space (PCS). Profiles of interest for tagging images or colors have a PCS which is one of the two specific device independent spaces (one CIEXYZ space and one CIELab space) defined in the ICC Profile Format Specification. Most profiles of interest either have invertible transformations or explicitly specify transformations going both directions.

version
10 Feb 1997
see
ICC_ColorSpace

Fields Summary
private static final long
serialVersionUID
transient long
ID
private transient sun.awt.color.ProfileDeferralInfo
deferralInfo
private transient sun.awt.color.ProfileActivator
profileActivator
private static ICC_Profile
sRGBprofile
private static ICC_Profile
XYZprofile
private static ICC_Profile
PYCCprofile
private static ICC_Profile
GRAYprofile
private static ICC_Profile
LINEAR_RGBprofile
public static final int
CLASS_INPUT
Profile class is input.
public static final int
CLASS_DISPLAY
Profile class is display.
public static final int
CLASS_OUTPUT
Profile class is output.
public static final int
CLASS_DEVICELINK
Profile class is device link.
public static final int
CLASS_COLORSPACECONVERSION
Profile class is color space conversion.
public static final int
CLASS_ABSTRACT
Profile class is abstract.
public static final int
CLASS_NAMEDCOLOR
Profile class is named color.
public static final int
icSigXYZData
ICC Profile Color Space Type Signature: 'XYZ '.
public static final int
icSigLabData
ICC Profile Color Space Type Signature: 'Lab '.
public static final int
icSigLuvData
ICC Profile Color Space Type Signature: 'Luv '.
public static final int
icSigYCbCrData
ICC Profile Color Space Type Signature: 'YCbr'.
public static final int
icSigYxyData
ICC Profile Color Space Type Signature: 'Yxy '.
public static final int
icSigRgbData
ICC Profile Color Space Type Signature: 'RGB '.
public static final int
icSigGrayData
ICC Profile Color Space Type Signature: 'GRAY'.
public static final int
icSigHsvData
ICC Profile Color Space Type Signature: 'HSV'.
public static final int
icSigHlsData
ICC Profile Color Space Type Signature: 'HLS'.
public static final int
icSigCmykData
ICC Profile Color Space Type Signature: 'CMYK'.
public static final int
icSigCmyData
ICC Profile Color Space Type Signature: 'CMY '.
public static final int
icSigSpace2CLR
ICC Profile Color Space Type Signature: '2CLR'.
public static final int
icSigSpace3CLR
ICC Profile Color Space Type Signature: '3CLR'.
public static final int
icSigSpace4CLR
ICC Profile Color Space Type Signature: '4CLR'.
public static final int
icSigSpace5CLR
ICC Profile Color Space Type Signature: '5CLR'.
public static final int
icSigSpace6CLR
ICC Profile Color Space Type Signature: '6CLR'.
public static final int
icSigSpace7CLR
ICC Profile Color Space Type Signature: '7CLR'.
public static final int
icSigSpace8CLR
ICC Profile Color Space Type Signature: '8CLR'.
public static final int
icSigSpace9CLR
ICC Profile Color Space Type Signature: '9CLR'.
public static final int
icSigSpaceACLR
ICC Profile Color Space Type Signature: 'ACLR'.
public static final int
icSigSpaceBCLR
ICC Profile Color Space Type Signature: 'BCLR'.
public static final int
icSigSpaceCCLR
ICC Profile Color Space Type Signature: 'CCLR'.
public static final int
icSigSpaceDCLR
ICC Profile Color Space Type Signature: 'DCLR'.
public static final int
icSigSpaceECLR
ICC Profile Color Space Type Signature: 'ECLR'.
public static final int
icSigSpaceFCLR
ICC Profile Color Space Type Signature: 'FCLR'.
public static final int
icSigInputClass
ICC Profile Class Signature: 'scnr'.
public static final int
icSigDisplayClass
ICC Profile Class Signature: 'mntr'.
public static final int
icSigOutputClass
ICC Profile Class Signature: 'prtr'.
public static final int
icSigLinkClass
ICC Profile Class Signature: 'link'.
public static final int
icSigAbstractClass
ICC Profile Class Signature: 'abst'.
public static final int
icSigColorSpaceClass
ICC Profile Class Signature: 'spac'.
public static final int
icSigNamedColorClass
ICC Profile Class Signature: 'nmcl'.
public static final int
icPerceptual
ICC Profile Rendering Intent: Perceptual.
public static final int
icRelativeColorimetric
ICC Profile Rendering Intent: RelativeColorimetric.
public static final int
icMediaRelativeColorimetric
ICC Profile Rendering Intent: Media-RelativeColorimetric.
public static final int
icSaturation
ICC Profile Rendering Intent: Saturation.
public static final int
icAbsoluteColorimetric
ICC Profile Rendering Intent: AbsoluteColorimetric.
public static final int
icICCAbsoluteColorimetric
ICC Profile Rendering Intent: ICC-AbsoluteColorimetric.
public static final int
icSigHead
ICC Profile Tag Signature: 'head' - special.
public static final int
icSigAToB0Tag
ICC Profile Tag Signature: 'A2B0'.
public static final int
icSigAToB1Tag
ICC Profile Tag Signature: 'A2B1'.
public static final int
icSigAToB2Tag
ICC Profile Tag Signature: 'A2B2'.
public static final int
icSigBlueColorantTag
ICC Profile Tag Signature: 'bXYZ'.
public static final int
icSigBlueMatrixColumnTag
ICC Profile Tag Signature: 'bXYZ'.
public static final int
icSigBlueTRCTag
ICC Profile Tag Signature: 'bTRC'.
public static final int
icSigBToA0Tag
ICC Profile Tag Signature: 'B2A0'.
public static final int
icSigBToA1Tag
ICC Profile Tag Signature: 'B2A1'.
public static final int
icSigBToA2Tag
ICC Profile Tag Signature: 'B2A2'.
public static final int
icSigCalibrationDateTimeTag
ICC Profile Tag Signature: 'calt'.
public static final int
icSigCharTargetTag
ICC Profile Tag Signature: 'targ'.
public static final int
icSigCopyrightTag
ICC Profile Tag Signature: 'cprt'.
public static final int
icSigCrdInfoTag
ICC Profile Tag Signature: 'crdi'.
public static final int
icSigDeviceMfgDescTag
ICC Profile Tag Signature: 'dmnd'.
public static final int
icSigDeviceModelDescTag
ICC Profile Tag Signature: 'dmdd'.
public static final int
icSigDeviceSettingsTag
ICC Profile Tag Signature: 'devs'.
public static final int
icSigGamutTag
ICC Profile Tag Signature: 'gamt'.
public static final int
icSigGrayTRCTag
ICC Profile Tag Signature: 'kTRC'.
public static final int
icSigGreenColorantTag
ICC Profile Tag Signature: 'gXYZ'.
public static final int
icSigGreenMatrixColumnTag
ICC Profile Tag Signature: 'gXYZ'.
public static final int
icSigGreenTRCTag
ICC Profile Tag Signature: 'gTRC'.
public static final int
icSigLuminanceTag
ICC Profile Tag Signature: 'lumi'.
public static final int
icSigMeasurementTag
ICC Profile Tag Signature: 'meas'.
public static final int
icSigMediaBlackPointTag
ICC Profile Tag Signature: 'bkpt'.
public static final int
icSigMediaWhitePointTag
ICC Profile Tag Signature: 'wtpt'.
public static final int
icSigNamedColor2Tag
ICC Profile Tag Signature: 'ncl2'.
public static final int
icSigOutputResponseTag
ICC Profile Tag Signature: 'resp'.
public static final int
icSigPreview0Tag
ICC Profile Tag Signature: 'pre0'.
public static final int
icSigPreview1Tag
ICC Profile Tag Signature: 'pre1'.
public static final int
icSigPreview2Tag
ICC Profile Tag Signature: 'pre2'.
public static final int
icSigProfileDescriptionTag
ICC Profile Tag Signature: 'desc'.
public static final int
icSigProfileSequenceDescTag
ICC Profile Tag Signature: 'pseq'.
public static final int
icSigPs2CRD0Tag
ICC Profile Tag Signature: 'psd0'.
public static final int
icSigPs2CRD1Tag
ICC Profile Tag Signature: 'psd1'.
public static final int
icSigPs2CRD2Tag
ICC Profile Tag Signature: 'psd2'.
public static final int
icSigPs2CRD3Tag
ICC Profile Tag Signature: 'psd3'.
public static final int
icSigPs2CSATag
ICC Profile Tag Signature: 'ps2s'.
public static final int
icSigPs2RenderingIntentTag
ICC Profile Tag Signature: 'ps2i'.
public static final int
icSigRedColorantTag
ICC Profile Tag Signature: 'rXYZ'.
public static final int
icSigRedMatrixColumnTag
ICC Profile Tag Signature: 'rXYZ'.
public static final int
icSigRedTRCTag
ICC Profile Tag Signature: 'rTRC'.
public static final int
icSigScreeningDescTag
ICC Profile Tag Signature: 'scrd'.
public static final int
icSigScreeningTag
ICC Profile Tag Signature: 'scrn'.
public static final int
icSigTechnologyTag
ICC Profile Tag Signature: 'tech'.
public static final int
icSigUcrBgTag
ICC Profile Tag Signature: 'bfd '.
public static final int
icSigViewingCondDescTag
ICC Profile Tag Signature: 'vued'.
public static final int
icSigViewingConditionsTag
ICC Profile Tag Signature: 'view'.
public static final int
icSigChromaticityTag
ICC Profile Tag Signature: 'chrm'.
public static final int
icSigChromaticAdaptationTag
ICC Profile Tag Signature: 'chad'.
public static final int
icSigColorantOrderTag
ICC Profile Tag Signature: 'clro'.
public static final int
icSigColorantTableTag
ICC Profile Tag Signature: 'clrt'.
public static final int
icHdrSize
ICC Profile Header Location: profile size in bytes.
public static final int
icHdrCmmId
ICC Profile Header Location: CMM for this profile.
public static final int
icHdrVersion
ICC Profile Header Location: format version number.
public static final int
icHdrDeviceClass
ICC Profile Header Location: type of profile.
public static final int
icHdrColorSpace
ICC Profile Header Location: color space of data.
public static final int
icHdrPcs
ICC Profile Header Location: PCS - XYZ or Lab only.
public static final int
icHdrDate
ICC Profile Header Location: date profile was created.
public static final int
icHdrMagic
ICC Profile Header Location: icMagicNumber.
public static final int
icHdrPlatform
ICC Profile Header Location: primary platform.
public static final int
icHdrFlags
ICC Profile Header Location: various bit settings.
public static final int
icHdrManufacturer
ICC Profile Header Location: device manufacturer.
public static final int
icHdrModel
ICC Profile Header Location: device model number.
public static final int
icHdrAttributes
ICC Profile Header Location: device attributes.
public static final int
icHdrRenderingIntent
ICC Profile Header Location: rendering intent.
public static final int
icHdrIlluminant
ICC Profile Header Location: profile illuminant.
public static final int
icHdrCreator
ICC Profile Header Location: profile creator.
public static final int
icHdrProfileID
ICC Profile Header Location: profile's ID.
public static final int
icTagType
ICC Profile Constant: tag type signaturE.
public static final int
icTagReserved
ICC Profile Constant: reserved.
public static final int
icCurveCount
ICC Profile Constant: curveType count.
public static final int
icCurveData
ICC Profile Constant: curveType data.
public static final int
icXYZNumberX
ICC Profile Constant: XYZNumber X.
private int
iccProfileSerializedDataVersion
Version of the format of additional serialized data in the stream. Version 1 corresponds to Java 2 Platform, v1.3.
private transient ICC_Profile
resolvedDeserializedProfile
Constructors Summary
ICC_Profile(long ID)
Constructs an ICC_Profile object with a given ID.

    /* XYZNumber X */


                 
      
        this.ID = ID;
    
ICC_Profile(sun.awt.color.ProfileDeferralInfo pdi)
Constructs an ICC_Profile object whose loading will be deferred. The ID will be 0 until the profile is loaded.

        this.deferralInfo = pdi;
        this.profileActivator = new ProfileActivator() {
            public void activate() {
                activateDeferredProfile();
            }
        };
        ProfileDeferralMgr.registerDeferral(this.profileActivator);
    
Methods Summary
voidactivateDeferredProfile()

    long[] theID = new long [1];
    byte profileData[];
    FileInputStream fis;
    String fileName = deferralInfo.filename;

        profileActivator = null;
        deferralInfo = null;
        if ((fis = openProfile(fileName)) == null) {
            throw new IllegalArgumentException("Cannot open file " + fileName);
        }
        try {
            profileData = getProfileDataFromStream(fis);
            fis.close();    /* close the file */
        }
        catch (IOException e) {
            throw new IllegalArgumentException("Invalid ICC Profile Data" +
                fileName);
        }
        if (profileData == null) {
            throw new IllegalArgumentException("Invalid ICC Profile Data" +
                fileName);
        }
        try {
            CMM.checkStatus(CMM.cmmLoadProfile(profileData, theID));
        } catch (CMMException c) {
            throw new IllegalArgumentException("Invalid ICC Profile Data" +
                fileName);
        }
        ID = theID[0];
    
protected voidfinalize()
Frees the resources associated with an ICC_Profile object.

        if (ID != 0) {
            CMM.checkStatus(CMM.cmmFreeProfile(ID));
        } else if (profileActivator != null) {
            ProfileDeferralMgr.unregisterDeferral(profileActivator);
        }
    
public intgetColorSpaceType()
Returns the color space type. Returns one of the color space type constants defined by the ColorSpace class. This is the "input" color space of the profile. The type defines the number of components of the color space and the interpretation, e.g. TYPE_RGB identifies a color space with three components - red, green, and blue. It does not define the particular color characteristics of the space, e.g. the chromaticities of the primaries.

return
One of the color space type constants defined in the ColorSpace class.

        if (deferralInfo != null) {
            return deferralInfo.colorSpaceType; /* Need to have this info for
                                                   ICC_ColorSpace without
                                                   causing a deferred profile
                                                   to be loaded */
        }
        return    getColorSpaceType(ID);
    
static intgetColorSpaceType(long profileID)

    byte[] theHeader;
    int theColorSpaceSig, theColorSpace;
    
        theHeader = getData(profileID, icSigHead);
        theColorSpaceSig = intFromBigEndian(theHeader, icHdrColorSpace);
        theColorSpace = iccCStoJCS (theColorSpaceSig);
        return theColorSpace;
    
public byte[]getData()
Returns a byte array corresponding to the data of this ICC_Profile.

return
A byte array that contains the profile data.
see
#setData(int, byte[])

    int[] profileSize = new int [1];
    byte[] profileData;

        if (ProfileDeferralMgr.deferring) {
            ProfileDeferralMgr.activateProfiles();
        }

        /* get the number of bytes needed for this profile */
        CMM.checkStatus(CMM.cmmGetProfileSize(ID, profileSize));

        profileData = new byte [profileSize[0]];

        /* get the data for the profile */
        CMM.checkStatus(CMM.cmmGetProfileData(ID, profileData));

        return profileData;
    
public byte[]getData(int tagSignature)
Returns a particular tagged data element from the profile as a byte array. Elements are identified by signatures as defined in the ICC specification. The signature icSigHead can be used to get the header. This method is useful for advanced applets or applications which need to access profile data directly.

param
tagSignature The ICC tag signature for the data element you want to get.
return
A byte array that contains the tagged data element. Returns null if the specified tag doesn't exist.
see
#setData(int, byte[])


        if (ProfileDeferralMgr.deferring) {
            ProfileDeferralMgr.activateProfiles();
        }

        return getData(ID, tagSignature);
    
static byte[]getData(long profileID, int tagSignature)

    int[] tagSize = new int [1];
    byte[] tagData;

	try {
            /* get the number of bytes needed for this tag */
            CMM.checkStatus(CMM.cmmGetTagSize(profileID, tagSignature,
                                              tagSize));

            tagData = new byte[tagSize[0]]; /* get an array for the tag */

            /* get the tag's data */
            CMM.checkStatus(CMM.cmmGetTagData(profileID, tagSignature,
                                              tagData));
	} catch(CMMException c) {
	    tagData = null;
	}

        return tagData;
    
static java.awt.color.ICC_ProfilegetDeferredInstance(sun.awt.color.ProfileDeferralInfo pdi)
Constructs an ICC_Profile for which the actual loading of the profile data from a file and the initialization of the CMM should be deferred as long as possible. Deferral is only used for standard profiles. If deferring is disabled, then getStandardProfile() ensures that all of the appropriate access privileges are granted when loading this profile. If deferring is enabled, then the deferred activation code will take care of access privileges.

see
activateDeferredProfile()


        if (!ProfileDeferralMgr.deferring) {
            return getStandardProfile(pdi.filename);
        }
        if (pdi.colorSpaceType == ColorSpace.TYPE_RGB) {
            return new ICC_ProfileRGB(pdi);
        } else if (pdi.colorSpaceType == ColorSpace.TYPE_GRAY) {
            return new ICC_ProfileGray(pdi);
        } else {
            return new ICC_Profile(pdi);
        }
    
floatgetGamma(int theTagSignature)
Returns a gamma value representing a tone reproduction curve (TRC). If the profile represents the TRC as a table rather than a single gamma value, then an exception is thrown. In this case the actual table can be obtained via getTRC(). theTagSignature should be one of icSigGrayTRCTag, icSigRedTRCTag, icSigGreenTRCTag, or icSigBlueTRCTag.

return
the gamma value as a float.
exception
ProfileDataException if the profile does not specify the TRC as a single gamma value.

    byte[] theTRCData;
    float theGamma;
    int theU8Fixed8;

        theTRCData = getData(theTagSignature); /* get the TRC */
                                               /* getData will activate deferred
                                                  profiles if necessary */
        
        if (intFromBigEndian (theTRCData, icCurveCount) != 1) {
            throw new ProfileDataException ("TRC is not a gamma");
        }

        /* convert u8Fixed8 to float */
        theU8Fixed8 = (shortFromBigEndian(theTRCData, icCurveData)) & 0xffff;
            
        theGamma = ((float) theU8Fixed8) / 256.0f;
        
        return theGamma;
    
public static java.awt.color.ICC_ProfilegetInstance(byte[] data)
Constructs an ICC_Profile object corresponding to the data in a byte array. Throws an IllegalArgumentException if the data does not correspond to a valid ICC Profile.

param
data the specified ICC Profile data
return
an ICC_Profile object corresponding to the data in the specified data array.

    ICC_Profile thisProfile;

        long[] theID = new long [1];

        if (ProfileDeferralMgr.deferring) {
            ProfileDeferralMgr.activateProfiles();
        }
        
        try {
            CMM.checkStatus(CMM.cmmLoadProfile(data, theID));
        } catch (CMMException c) {
            throw new IllegalArgumentException("Invalid ICC Profile Data");
        }

        try {
            if ((getColorSpaceType (theID[0]) == ColorSpace.TYPE_GRAY) &&
                (getData (theID[0], icSigMediaWhitePointTag) != null) &&
                (getData (theID[0], icSigGrayTRCTag) != null)) {
                thisProfile = new ICC_ProfileGray (theID[0]);
            }
            else if ((getColorSpaceType (theID[0]) == ColorSpace.TYPE_RGB) &&
                (getData (theID[0], icSigMediaWhitePointTag) != null) &&
                (getData (theID[0], icSigRedColorantTag) != null) &&
                (getData (theID[0], icSigGreenColorantTag) != null) &&
                (getData (theID[0], icSigBlueColorantTag) != null) &&
                (getData (theID[0], icSigRedTRCTag) != null) &&
                (getData (theID[0], icSigGreenTRCTag) != null) &&
                (getData (theID[0], icSigBlueTRCTag) != null)) {
                thisProfile = new ICC_ProfileRGB (theID[0]);
            }
            else {
                thisProfile = new ICC_Profile (theID[0]);
            }
        } catch (CMMException c) {
            thisProfile = new ICC_Profile (theID[0]);
        }
        return thisProfile;
    
public static java.awt.color.ICC_ProfilegetInstance(int cspace)
Constructs an ICC_Profile corresponding to one of the specific color spaces defined by the ColorSpace class (for example CS_sRGB). Throws an IllegalArgumentException if cspace is not one of the defined color spaces.

param
cspace the type of color space to create a profile for. The specified type is one of the color space constants defined in the ColorSpace class.
return
an ICC_Profile object corresponding to the specified ColorSpace type.
exception
IllegalArgumentException If cspace is not one of the predefined color space types.

	ICC_Profile thisProfile = null;
	String fileName;

	switch (cspace) {
	case ColorSpace.CS_sRGB:
	    if (sRGBprofile == null) {
		try {
		    /*
		     * Deferral is only used for standard profiles.
		     * Enabling the appropriate access privileges is handled
		     * at a lower level.
		     */
		    sRGBprofile = getDeferredInstance(
			new ProfileDeferralInfo("sRGB.pf", ColorSpace.TYPE_RGB,
						3, CLASS_DISPLAY)); 
		} catch (IOException e) {
		    throw new IllegalArgumentException(
                          "Can't load standard profile: sRGB.pf");
		}
	    }
	    thisProfile = sRGBprofile;

	    break;

	case ColorSpace.CS_CIEXYZ:
	    if (XYZprofile == null) {
		XYZprofile = getStandardProfile("CIEXYZ.pf");
	    }
	    thisProfile = XYZprofile;

	    break;

	case ColorSpace.CS_PYCC:
	    if (PYCCprofile == null) {
		PYCCprofile = getStandardProfile("PYCC.pf");
	    }
	    thisProfile = PYCCprofile;

	    break;

	case ColorSpace.CS_GRAY:
	    if (GRAYprofile == null) {
		GRAYprofile = getStandardProfile("GRAY.pf");
	    }
	    thisProfile = GRAYprofile;

	    break;

	case ColorSpace.CS_LINEAR_RGB:
	    if (LINEAR_RGBprofile == null) {
		LINEAR_RGBprofile = getStandardProfile("LINEAR_RGB.pf");
	    }
	    thisProfile = LINEAR_RGBprofile;

	    break;

	default:
	    throw new IllegalArgumentException("Unknown color space");
	}

        return thisProfile;
    
public static java.awt.color.ICC_ProfilegetInstance(java.lang.String fileName)
Constructs an ICC_Profile corresponding to the data in a file. fileName may be an absolute or a relative file specification. Relative file names are looked for in several places: first, relative to any directories specified by the java.iccprofile.path property; second, relative to any directories specified by the java.class.path property; finally, in a directory used to store profiles always available, such as the profile for sRGB. Built-in profiles use .pf as the file name extension for profiles, e.g. sRGB.pf. This method throws an IOException if the specified file cannot be opened or if an I/O error occurs while reading the file. It throws an IllegalArgumentException if the file does not contain valid ICC Profile data.

param
fileName The file that contains the data for the profile.
return
an ICC_Profile object corresponding to the data in the specified file.
exception
IOException If the specified file cannot be opened or an I/O error occurs while reading the file.
exception
IllegalArgumentException If the file does not contain valid ICC Profile data.
exception
SecurityException If a security manager is installed and it does not permit read access to the given file.

    ICC_Profile thisProfile;
    FileInputStream fis;

        SecurityManager security = System.getSecurityManager();
	if (security != null) {
            security.checkRead(fileName);
        }

        if ((fis = openProfile(fileName)) == null) {
            throw new IOException("Cannot open file " + fileName);
        }

        thisProfile = getInstance(fis);

        fis.close();    /* close the file */
    
        return thisProfile;
    
public static java.awt.color.ICC_ProfilegetInstance(java.io.InputStream s)
Constructs an ICC_Profile corresponding to the data in an InputStream. This method throws an IllegalArgumentException if the stream does not contain valid ICC Profile data. It throws an IOException if an I/O error occurs while reading the stream.

param
s The input stream from which to read the profile data.
return
an ICC_Profile object corresponding to the data in the specified InputStream.
exception
IOException If an I/O error occurs while reading the stream.
exception
IllegalArgumentException If the stream does not contain valid ICC Profile data.

    byte profileData[];

        if (s instanceof ProfileDeferralInfo) {
            /* hack to detect profiles whose loading can be deferred */
            return getDeferredInstance((ProfileDeferralInfo) s);
        }

        if ((profileData = getProfileDataFromStream(s)) == null) {
            throw new IllegalArgumentException("Invalid ICC Profile Data");
        }

        return getInstance(profileData);
    
public intgetMajorVersion()
Returns profile major version.

return
The major version of the profile.

    byte[] theHeader;
    
        theHeader = getData(icSigHead); /* getData will activate deferred
                                           profiles if necessary */

        return (int) theHeader[8];
    
float[]getMediaWhitePoint()
Returns a float array of length 3 containing the X, Y, and Z components of the mediaWhitePointTag in the ICC profile.

        return getXYZTag(icSigMediaWhitePointTag);
                                           /* get the media white point tag */
    
public intgetMinorVersion()
Returns profile minor version.

return
The minor version of the profile.

    byte[] theHeader;
    
        theHeader = getData(icSigHead); /* getData will activate deferred
                                           profiles if necessary */

        return (int) theHeader[9];
    
public intgetNumComponents()
Returns the number of color components in the "input" color space of this profile. For example if the color space type of this profile is TYPE_RGB, then this method will return 3.

return
The number of color components in the profile's input color space.
throws
ProfileDataException if color space is in the profile is invalid

    byte[]    theHeader;
    int    theColorSpaceSig, theNumComponents;
    
        if (deferralInfo != null) {
            return deferralInfo.numComponents; /* Need to have this info for
                                                  ICC_ColorSpace without
                                                  causing a deferred profile
                                                  to be loaded */
        }
        theHeader = getData(icSigHead);

        theColorSpaceSig = intFromBigEndian (theHeader, icHdrColorSpace);

        switch (theColorSpaceSig) {
        case icSigGrayData:
            theNumComponents = 1;
            break;

        case icSigSpace2CLR:
            theNumComponents = 2;
            break;

        case icSigXYZData:
        case icSigLabData:
        case icSigLuvData:
        case icSigYCbCrData:
        case icSigYxyData:
        case icSigRgbData:
        case icSigHsvData:
        case icSigHlsData:
        case icSigCmyData:
        case icSigSpace3CLR:
            theNumComponents = 3;
            break;

        case icSigCmykData:
        case icSigSpace4CLR:
            theNumComponents = 4;
            break;

        case icSigSpace5CLR:
            theNumComponents = 5;
            break;

        case icSigSpace6CLR:
            theNumComponents = 6;
            break;

        case icSigSpace7CLR:
            theNumComponents = 7;
            break;

        case icSigSpace8CLR:
            theNumComponents = 8;
            break;

        case icSigSpace9CLR:
            theNumComponents = 9;
            break;

        case icSigSpaceACLR:
            theNumComponents = 10;
            break;

        case icSigSpaceBCLR:
            theNumComponents = 11;
            break;

        case icSigSpaceCCLR:
            theNumComponents = 12;
            break;

        case icSigSpaceDCLR:
            theNumComponents = 13;
            break;

        case icSigSpaceECLR:
            theNumComponents = 14;
            break;

        case icSigSpaceFCLR:
            theNumComponents = 15;
            break;

        default:
            throw new ProfileDataException ("invalid ICC color space");
        }
        
        return theNumComponents;
    
public intgetPCSType()
Returns the color space type of the Profile Connection Space (PCS). Returns one of the color space type constants defined by the ColorSpace class. This is the "output" color space of the profile. For an input, display, or output profile useful for tagging colors or images, this will be either TYPE_XYZ or TYPE_Lab and should be interpreted as the corresponding specific color space defined in the ICC specification. For a device link profile, this could be any of the color space type constants.

return
One of the color space type constants defined in the ColorSpace class.

        if (ProfileDeferralMgr.deferring) {
            ProfileDeferralMgr.activateProfiles();
        }
        return getPCSType(ID);
    
static intgetPCSType(long profileID)

    byte[] theHeader;
    int thePCSSig, thePCS;
    
        theHeader = getData(profileID, icSigHead);
        thePCSSig = intFromBigEndian(theHeader, icHdrPcs);
        thePCS = iccCStoJCS(thePCSSig);
        return thePCS;
    
public intgetProfileClass()
Returns the profile class.

return
One of the predefined profile class constants.

    byte[] theHeader;
    int theClassSig, theClass;
    
        if (deferralInfo != null) {
            return deferralInfo.profileClass; /* Need to have this info for
                                                 ICC_ColorSpace without
                                                 causing a deferred profile
                                                 to be loaded */
        }

        theHeader = getData(icSigHead);

        theClassSig = intFromBigEndian (theHeader, icHdrDeviceClass);
                
        switch (theClassSig) {
        case icSigInputClass:
            theClass = CLASS_INPUT;
            break;

        case icSigDisplayClass:
            theClass = CLASS_DISPLAY;
            break;

        case icSigOutputClass:
            theClass = CLASS_OUTPUT;
            break;

        case icSigLinkClass:
            theClass = CLASS_DEVICELINK;
            break;

        case icSigColorSpaceClass:
            theClass = CLASS_COLORSPACECONVERSION;
            break;

        case icSigAbstractClass:
            theClass = CLASS_ABSTRACT;
            break;

        case icSigNamedColorClass:
            theClass = CLASS_NAMEDCOLOR;
            break;

        default:
            throw new IllegalArgumentException("Unknown profile class");
        }
        
        return theClass;
    
static byte[]getProfileDataFromStream(java.io.InputStream s)

    byte profileData[];
    int profileSize;

        byte header[] = new byte[128];
        int bytestoread = 128;
        int bytesread = 0;
        int n;

        while (bytestoread != 0) {
            if ((n = s.read(header, bytesread, bytestoread)) < 0) {
                return null;
            }
            bytesread += n;
            bytestoread -= n;
        }
        if (header[36] != 0x61 || header[37] != 0x63 ||
            header[38] != 0x73 || header[39] != 0x70) {
            return null;   /* not a valid profile */
        }
        profileSize = ((header[0] & 0xff) << 24) |
                      ((header[1] & 0xff) << 16) |
                      ((header[2] & 0xff) <<  8) |
                       (header[3] & 0xff);
        profileData = new byte[profileSize];
        System.arraycopy(header, 0, profileData, 0, 128);
        bytestoread = profileSize - 128;
        bytesread = 128;
        while (bytestoread != 0) {
            if ((n = s.read(profileData, bytesread, bytestoread)) < 0) {
                return null;
            }
            bytesread += n;
            bytestoread -= n;
        }

        return profileData;
    
intgetRenderingIntent()
Returns the rendering intent of the profile. This is used to select the proper transform from a profile that has multiple transforms. It is typically set in a source profile to select a transform from an output profile.

        byte[] theHeader = getData(icSigHead);/* getData will activate deferred
                                                 profiles if necessary */
        
        int renderingIntent = intFromBigEndian(theHeader, icHdrRenderingIntent);
                                                 /* set the rendering intent */
        return renderingIntent;
    
private static java.awt.color.ICC_ProfilegetStandardProfile(java.lang.String name)

        
	return (ICC_Profile) AccessController.doPrivileged(
	    new PrivilegedAction() {
                 public Object run() {
                     ICC_Profile p = null;
                     try {
                         p = getInstance (name);
                     } catch (IOException ex) {
                         throw new IllegalArgumentException(
			       "Can't load standard profile: " + name);
                     }
                     return p;
                 }
             });
    
short[]getTRC(int theTagSignature)
Returns the TRC as an array of shorts. If the profile has specified the TRC as linear (gamma = 1.0) or as a simple gamma value, this method throws an exception, and the getGamma() method should be used to get the gamma value. Otherwise the short array returned here represents a lookup table where the input Gray value is conceptually in the range [0.0, 1.0]. Value 0.0 maps to array index 0 and value 1.0 maps to array index length-1. Interpolation may be used to generate output values for input values which do not map exactly to an index in the array. Output values also map linearly to the range [0.0, 1.0]. Value 0.0 is represented by an array value of 0x0000 and value 1.0 by 0xFFFF, i.e. the values are really unsigned short values, although they are returned in a short array. theTagSignature should be one of icSigGrayTRCTag, icSigRedTRCTag, icSigGreenTRCTag, or icSigBlueTRCTag.

return
a short array representing the TRC.
exception
ProfileDataException if the profile does not specify the TRC as a table.

    byte[] theTRCData;
    short[] theTRC;
    int i1, i2, nElements, theU8Fixed8;

        theTRCData = getData(theTagSignature); /* get the TRC */
                                               /* getData will activate deferred
                                                  profiles if necessary */
        
        nElements = intFromBigEndian(theTRCData, icCurveCount);

        if (nElements == 1) {
            throw new ProfileDataException("TRC is not a table");
        }

        /* make the short array */
        theTRC = new short [nElements];

        for (i1 = 0, i2 = icCurveData; i1 < nElements; i1++, i2 += 2) {
            theTRC[i1] = shortFromBigEndian(theTRCData, i2);
        }
        
        return theTRC;
    
float[]getXYZTag(int theTagSignature)
Returns a float array of length 3 containing the X, Y, and Z components encoded in an XYZType tag.

    byte[] theData;
    float[] theXYZNumber;
    int i1, i2, theS15Fixed16;
    
        theData = getData(theTagSignature); /* get the tag data */
                                            /* getData will activate deferred
                                               profiles if necessary */
        
        theXYZNumber = new float [3];        /* array to return */

        /* convert s15Fixed16Number to float */
        for (i1 = 0, i2 = icXYZNumberX; i1 < 3; i1++, i2 += 4) {
            theS15Fixed16 = intFromBigEndian(theData, i2);
            theXYZNumber [i1] = ((float) theS15Fixed16) / 65536.0f;
        }
        return theXYZNumber;
    
static inticcCStoJCS(int theColorSpaceSig)

    int theColorSpace;

        switch (theColorSpaceSig) {
        case icSigXYZData:
            theColorSpace = ColorSpace.TYPE_XYZ;
            break;

        case icSigLabData:
            theColorSpace = ColorSpace.TYPE_Lab;
            break;

        case icSigLuvData:
            theColorSpace = ColorSpace.TYPE_Luv;
            break;

        case icSigYCbCrData:
            theColorSpace = ColorSpace.TYPE_YCbCr;
            break;

        case icSigYxyData:
            theColorSpace = ColorSpace.TYPE_Yxy;
            break;

        case icSigRgbData:
            theColorSpace = ColorSpace.TYPE_RGB;
            break;

        case icSigGrayData:
            theColorSpace = ColorSpace.TYPE_GRAY;
            break;

        case icSigHsvData:
            theColorSpace = ColorSpace.TYPE_HSV;
            break;

        case icSigHlsData:
            theColorSpace = ColorSpace.TYPE_HLS;
            break;

        case icSigCmykData:
            theColorSpace = ColorSpace.TYPE_CMYK;
            break;

        case icSigCmyData:
            theColorSpace = ColorSpace.TYPE_CMY;
            break;

        case icSigSpace2CLR:
            theColorSpace = ColorSpace.TYPE_2CLR;
            break;

        case icSigSpace3CLR:
            theColorSpace = ColorSpace.TYPE_3CLR;
            break;

        case icSigSpace4CLR:
            theColorSpace = ColorSpace.TYPE_4CLR;
            break;

        case icSigSpace5CLR:
            theColorSpace = ColorSpace.TYPE_5CLR;
            break;

        case icSigSpace6CLR:
            theColorSpace = ColorSpace.TYPE_6CLR;
            break;

        case icSigSpace7CLR:
            theColorSpace = ColorSpace.TYPE_7CLR;
            break;

        case icSigSpace8CLR:
            theColorSpace = ColorSpace.TYPE_8CLR;
            break;

        case icSigSpace9CLR:
            theColorSpace = ColorSpace.TYPE_9CLR;
            break;

        case icSigSpaceACLR:
            theColorSpace = ColorSpace.TYPE_ACLR;
            break;

        case icSigSpaceBCLR:
            theColorSpace = ColorSpace.TYPE_BCLR;
            break;

        case icSigSpaceCCLR:
            theColorSpace = ColorSpace.TYPE_CCLR;
            break;

        case icSigSpaceDCLR:
            theColorSpace = ColorSpace.TYPE_DCLR;
            break;

        case icSigSpaceECLR:
            theColorSpace = ColorSpace.TYPE_ECLR;
            break;

        case icSigSpaceFCLR:
            theColorSpace = ColorSpace.TYPE_FCLR;
            break;

        default:
            throw new IllegalArgumentException ("Unknown color space");
        }
        
        return theColorSpace;
    
static intintFromBigEndian(byte[] array, int index)

        return (((array[index]   & 0xff) << 24) |
                ((array[index+1] & 0xff) << 16) |
                ((array[index+2] & 0xff) <<  8) |
                 (array[index+3] & 0xff));
    
static voidintToBigEndian(int value, byte[] array, int index)

            array[index]   = (byte) (value >> 24);
            array[index+1] = (byte) (value >> 16);
            array[index+2] = (byte) (value >>  8);
            array[index+3] = (byte) (value);
    
private static java.io.FileInputStreamopenProfile(java.lang.String fileName)

	return (FileInputStream)java.security.AccessController.doPrivileged(
	    new java.security.PrivilegedAction() {
	    public Object run() {
		return privilegedOpenProfile(fileName);
	    }
	});
    
private static java.io.FileInputStreamprivilegedOpenProfile(java.lang.String fileName)

        FileInputStream fis = null;
        String path, dir, fullPath;

	    try {
	        fis = new FileInputStream(fileName);  /* absolute file name */
	    }
	    catch (FileNotFoundException e) {
	    }

	    if ((fis == null) &&
		((path = System.getProperty("java.iccprofile.path")) != null)){
                                    /* try relative to java.iccprofile.path */
	        StringTokenizer st = 
		    new StringTokenizer(path, File.pathSeparator);
		while (st.hasMoreTokens() && (fis == null)) {
		    dir = st.nextToken();
		    try {
		        fullPath = dir + File.separatorChar + fileName;
			fis = new FileInputStream(fullPath);
		    }
		    catch (FileNotFoundException e) {
		    }
		}
	    }

	    if ((fis == null) &&
		((path = System.getProperty("java.class.path")) != null)) {
                                    /* try relative to java.class.path */
	        StringTokenizer st =
		    new StringTokenizer(path, File.pathSeparator);
		while (st.hasMoreTokens() && (fis == null)) {
		    dir = st.nextToken();
		    try {
		        fullPath = dir + File.separatorChar + fileName;
			fis = new FileInputStream(fullPath);
		    }
		    catch (FileNotFoundException e) {
		    }
		}
	    }

	    if (fis == null) {    /* try the directory of built-in profiles */
	        dir = System.getProperty("java.home") +
		    File.separatorChar + "lib" + File.separatorChar + "cmm";
		fullPath = dir + File.separatorChar + fileName;
		try {
		    fis = new FileInputStream(fullPath);
		}
		catch (FileNotFoundException e) {
		}
	    }
        return fis;
    
private voidreadObject(java.io.ObjectInputStream s)
Reads default serializable fields from the stream. Reads from the stream a string and an array of bytes as additional data.

param
s stream used for deserialization.
throws
IOException thrown by ObjectInputStream.
throws
ClassNotFoundException thrown by ObjectInputStream.
serialData
The String is the name of one of CS_* constants defined in the {@link ColorSpace} class if the profile object is a profile for a predefined color space (for example "CS_sRGB"). The string is null otherwise.

The byte[] array is the profile data for the profile. It will usually be null for the predefined profiles.

If the string is recognized as a constant name for predefined color space the object will be resolved into profile obtained with getInstance(int cspace) and the profile data are ignored. Otherwise the object will be resolved into profile obtained with getInstance(byte[] data).

see
#readResolve()
see
#getInstance(int)
see
#getInstance(byte[])

	s.defaultReadObject();

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

	int cspace = 0;		// ColorSpace.CS_* constant if known
	boolean isKnownPredefinedCS = false;
	if (csName != null) {
	    isKnownPredefinedCS = true;
	    if (csName.equals("CS_sRGB")) {
		cspace = ColorSpace.CS_sRGB;
	    } else if (csName.equals("CS_CIEXYZ")) {
		cspace = ColorSpace.CS_CIEXYZ;
	    } else if (csName.equals("CS_PYCC")) {
		cspace = ColorSpace.CS_PYCC;
	    } else if (csName.equals("CS_GRAY")) {
		cspace = ColorSpace.CS_GRAY;
	    } else if (csName.equals("CS_LINEAR_RGB")) {
		cspace = ColorSpace.CS_LINEAR_RGB;
	    } else {
		isKnownPredefinedCS = false;
	    }
	}

	if (isKnownPredefinedCS) {
	    resolvedDeserializedProfile = getInstance(cspace);
	} else {
	    resolvedDeserializedProfile = 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 never thrown, but mandated by the serialization spec.

	return resolvedDeserializedProfile;
    
public voidsetData(int tagSignature, byte[] tagData)
Sets a particular tagged data element in the profile from a byte array. This method is useful for advanced applets or applications which need to access profile data directly.

param
tagSignature The ICC tag signature for the data element you want to set.
param
tagData the data to set for the specified tag signature
see
#getData


        if (ProfileDeferralMgr.deferring) {
            ProfileDeferralMgr.activateProfiles();
        }

        CMM.checkStatus(CMM.cmmSetTagData(ID, tagSignature, tagData));
    
voidsetRenderingIntent(int renderingIntent)
Sets the rendering intent of the profile. This is used to select the proper transform from a profile that has multiple transforms.

        byte[] theHeader = getData(icSigHead);/* getData will activate deferred
                                                 profiles if necessary */
        intToBigEndian (renderingIntent, theHeader, icHdrRenderingIntent);
                                                 /* set the rendering intent */
        setData (icSigHead, theHeader);
    
static shortshortFromBigEndian(byte[] array, int index)

        return (short) (((array[index]   & 0xff) << 8) |
                         (array[index+1] & 0xff));
    
static voidshortToBigEndian(short value, byte[] array, int index)

            array[index]   = (byte) (value >> 8);
            array[index+1] = (byte) (value);
    
public voidwrite(java.lang.String fileName)
Write this ICC_Profile to a file.

param
fileName The file to write the profile data to.
exception
IOException If the file cannot be opened for writing or an I/O error occurs while writing to the file.

    FileOutputStream outputFile;
    byte profileData[];

        profileData = getData(); /* this will activate deferred
                                    profiles if necessary */
        outputFile = new FileOutputStream(fileName);
        outputFile.write(profileData);
        outputFile.close ();
    
public voidwrite(java.io.OutputStream s)
Write this ICC_Profile to an OutputStream.

param
s The stream to write the profile data to.
exception
IOException If an I/O error occurs while writing to the stream.

    byte profileData[];

        profileData = getData(); /* this will activate deferred
                                    profiles if necessary */
        s.write(profileData);
    
private voidwriteObject(java.io.ObjectOutputStream s)
Writes default serializable fields to the stream. Writes a string and an array of bytes to the stream as additional data.

param
s stream used for serialization.
throws
IOException thrown by ObjectInputStream.
serialData
The String is the name of one of CS_* constants defined in the {@link ColorSpace} class if the profile object is a profile for a predefined color space (for example "CS_sRGB"). The string is null otherwise.

The byte[] array is the profile data for the profile. For predefined color spaces null is written instead of the profile data. If in the future versions of Java API new predefined color spaces will be added, future versions of this class may choose to write for new predefined color spaces not only the color space name, but the profile data as well so that older versions could still deserialize the object.



                                                                                                                                                                                                                            
       
       
    
	s.defaultWriteObject();

	String csName = null;
	if (this == sRGBprofile) {
	    csName = "CS_sRGB";
	} else if (this == XYZprofile) {
	    csName = "CS_CIEXYZ";
	} else if (this == PYCCprofile) {
	    csName = "CS_PYCC";
	} else if (this == GRAYprofile) {
	    csName = "CS_GRAY";
	} else if (this == LINEAR_RGBprofile) {
	    csName = "CS_LINEAR_RGB";
	}

	// Future versions may choose to write profile data for new
	// predefined color spaces as well, if any will be introduced,
	// so that old versions that don't recognize the new CS name
	// may fall back to constructing profile from the data.
	byte[] data = null;
	if (csName == null) {
	    // getData will activate deferred profile if necessary
	    data = getData();
	}

	s.writeObject(csName);
	s.writeObject(data);