📄 icc_profile.java
字号:
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]; } /** * Returns profile major version. * @return The major version of the profile. */ public int getMajorVersion() { byte[] theHeader; theHeader = getData(icSigHead); /* getData will activate deferred profiles if necessary */ return (int) theHeader[8]; } /** * Returns profile minor version. * @return The minor version of the profile. */ public int getMinorVersion() { byte[] theHeader; theHeader = getData(icSigHead); /* getData will activate deferred profiles if necessary */ return (int) theHeader[9]; } /** * Returns the profile class. * @return One of the predefined profile class constants. */ public int getProfileClass() { 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; } /** * 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 * <CODE>ColorSpace</CODE> class. */ public int getColorSpaceType() { 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 int getColorSpaceType(long profileID) { byte[] theHeader; int theColorSpaceSig, theColorSpace; theHeader = getData(profileID, icSigHead); theColorSpaceSig = intFromBigEndian(theHeader, icHdrColorSpace); theColorSpace = iccCStoJCS (theColorSpaceSig); return theColorSpace; } /** * 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 * <CODE>ColorSpace</CODE> class. */ public int getPCSType() { if (ProfileDeferralMgr.deferring) { ProfileDeferralMgr.activateProfiles(); } return getPCSType(ID); } static int getPCSType(long profileID) { byte[] theHeader; int thePCSSig, thePCS; theHeader = getData(profileID, icSigHead); thePCSSig = intFromBigEndian(theHeader, icHdrPcs); thePCS = iccCStoJCS(thePCSSig); return thePCS; } /** * 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. */ public void write(String fileName) throws IOException { FileOutputStream outputFile; byte profileData[]; profileData = getData(); /* this will activate deferred profiles if necessary */ outputFile = new FileOutputStream(fileName); outputFile.write(profileData); outputFile.close (); } /** * 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. */ public void write(OutputStream s) throws IOException { byte profileData[]; profileData = getData(); /* this will activate deferred profiles if necessary */ s.write(profileData); } /** * 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[]) */ public byte[] getData() { 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; } /** * 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 * <code>null</code> if the specified tag doesn't exist. * @see #setData(int, byte[]) */ public byte[] getData(int tagSignature) { 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; } /** * 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 */ public void setData(int tagSignature, byte[] tagData) { if (ProfileDeferralMgr.deferring) { ProfileDeferralMgr.activateProfiles(); } CMM.checkStatus(CMM.cmmSetTagData(ID, tagSignature, tagData)); } /** * Sets the rendering intent of the profile. * This is used to select the proper transform from a profile that * has multiple transforms. */ void setRenderingIntent(int renderingIntent) { byte[] theHeader = getData(icSigHead);/* getData will activate deferred profiles if necessary */ intToBigEndian (renderingIntent, theHeader, icHdrRenderingIntent); /* set the rendering intent */ setData (icSigHead, theHeader); } /** * 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. */ int getRenderingIntent() { byte[] theHeader = getData(icSigHead);/* getData will activate deferred profiles if necessary */ int renderingIntent = intFromBigEndian(theHeader, icHdrRenderingIntent); /* set the rendering intent */ return renderingIntent; } /** * 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 */ public int getNumComponents() { 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; } /** * Returns a float array of length 3 containing the X, Y, and Z * components of the mediaWhitePointTag in the ICC profile. */ float[] getMediaWhitePoint() { return getXYZTag(icSigMediaWhitePointTag); /* get the media white point tag */ } /** * Returns a float array of length 3 containing the X, Y, and Z * components encoded in an XYZType tag. */ float[] getXYZTag(int theTagSignature) { 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; } /** * Returns a gamma value representing a tone reproduction * curve (TRC). If the profile represents the TRC as a table rather
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -