📄 icc_profile.java
字号:
*/ public static final int icSigPs2CRD1Tag = 0x70736431; /* 'psd1' */ /** * ICC Profile Tag Signature: 'psd2'. */ public static final int icSigPs2CRD2Tag = 0x70736432; /* 'psd2' */ /** * ICC Profile Tag Signature: 'psd3'. */ public static final int icSigPs2CRD3Tag = 0x70736433; /* 'psd3' */ /** * ICC Profile Tag Signature: 'ps2s'. */ public static final int icSigPs2CSATag = 0x70733273; /* 'ps2s' */ /** * ICC Profile Tag Signature: 'ps2i'. */ public static final int icSigPs2RenderingIntentTag = 0x70733269; /* 'ps2i' */ /** * ICC Profile Tag Signature: 'rXYZ'. */ public static final int icSigRedColorantTag = 0x7258595A; /* 'rXYZ' */ /** * ICC Profile Tag Signature: 'rTRC'. */ public static final int icSigRedTRCTag = 0x72545243; /* 'rTRC' */ /** * ICC Profile Tag Signature: 'scrd'. */ public static final int icSigScreeningDescTag = 0x73637264; /* 'scrd' */ /** * ICC Profile Tag Signature: 'scrn'. */ public static final int icSigScreeningTag = 0x7363726E; /* 'scrn' */ /** * ICC Profile Tag Signature: 'tech'. */ public static final int icSigTechnologyTag = 0x74656368; /* 'tech' */ /** * ICC Profile Tag Signature: 'bfd '. */ public static final int icSigUcrBgTag = 0x62666420; /* 'bfd ' */ /** * ICC Profile Tag Signature: 'vued'. */ public static final int icSigViewingCondDescTag = 0x76756564; /* 'vued' */ /** * ICC Profile Tag Signature: 'view'. */ public static final int icSigViewingConditionsTag = 0x76696577;/* 'view' */ /** * ICC Profile Tag Signature: 'chrm'. */ public static final int icSigChromaticityTag = 0x6368726d; /* 'chrm' */ /** * ICC Profile Header Location: profile size in bytes. */ public static final int icHdrSize = 0; /* Profile size in bytes */ /** * ICC Profile Header Location: CMM for this profile. */ public static final int icHdrCmmId = 4; /* CMM for this profile */ /** * ICC Profile Header Location: format version number. */ public static final int icHdrVersion = 8; /* Format version number */ /** * ICC Profile Header Location: type of profile. */ public static final int icHdrDeviceClass = 12; /* Type of profile */ /** * ICC Profile Header Location: color space of data. */ public static final int icHdrColorSpace = 16; /* Color space of data */ /** * ICC Profile Header Location: PCS - XYZ or Lab only. */ public static final int icHdrPcs = 20; /* PCS - XYZ or Lab only */ /** * ICC Profile Header Location: date profile was created. */ public static final int icHdrDate = 24; /* Date profile was created */ /** * ICC Profile Header Location: icMagicNumber. */ public static final int icHdrMagic = 36; /* icMagicNumber */ /** * ICC Profile Header Location: primary platform. */ public static final int icHdrPlatform = 40; /* Primary Platform */ /** * ICC Profile Header Location: various bit settings. */ public static final int icHdrFlags = 44; /* Various bit settings */ /** * ICC Profile Header Location: device manufacturer. */ public static final int icHdrManufacturer = 48; /* Device manufacturer */ /** * ICC Profile Header Location: device model number. */ public static final int icHdrModel = 52; /* Device model number */ /** * ICC Profile Header Location: device attributes. */ public static final int icHdrAttributes = 56; /* Device attributes */ /** * ICC Profile Header Location: rendering intent. */ public static final int icHdrRenderingIntent = 64; /* Rendering intent */ /** * ICC Profile Header Location: profile illuminant. */ public static final int icHdrIlluminant = 68; /* Profile illuminant */ /** * ICC Profile Header Location: profile creator. */ public static final int icHdrCreator = 80; /* Profile creator */ /** * ICC Profile Constant: tag type signaturE. */ public static final int icTagType = 0; /* tag type signature */ /** * ICC Profile Constant: reserved. */ public static final int icTagReserved = 4; /* reserved */ /** * ICC Profile Constant: curveType count. */ public static final int icCurveCount = 8; /* curveType count */ /** * ICC Profile Constant: curveType data. */ public static final int icCurveData = 12; /* curveType data */ /** * ICC Profile Constant: XYZNumber X. */ public static final int icXYZNumberX = 8; /* XYZNumber X */ /** * Constructs an ICC_Profile object with a given ID. */ ICC_Profile(long ID) { this.ID = ID; } /** * Constructs an ICC_Profile object whose loading will be deferred. * The ID will be 0 until the profile is loaded. */ ICC_Profile(ProfileDeferralInfo pdi) { this.deferralInfo = pdi; this.profileActivator = new ProfileActivator() { public void activate() { activateDeferredProfile(); } }; ProfileDeferralMgr.registerDeferral(this.profileActivator); } /** * Frees the resources associated with an ICC_Profile object. */ protected void finalize () { if (ID != 0) { CMM.checkStatus(CMM.cmmFreeProfile(ID)); } else if (profileActivator != null) { ProfileDeferralMgr.unregisterDeferral(profileActivator); } } /** * 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 <code>ICC_Profile</code> object corresponding to * the data in the specified <code>data</code> array. */ public static ICC_Profile getInstance(byte[] data) { 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; } /** * 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 <CODE>ColorSpace</CODE> class. * * @return an <code>ICC_Profile</code> object corresponding to * the specified <code>ColorSpace</code> type. * @exception IllegalArgumentException If <CODE>cspace</CODE> is not * one of the predefined color space types. */ public static ICC_Profile getInstance (int cspace) { ICC_Profile thisProfile = null; String fileName; try { switch (cspace) { case ColorSpace.CS_sRGB: if (sRGBprofile == null) { sRGBprofile = getDeferredInstance( new ProfileDeferralInfo("sRGB.pf", ColorSpace.TYPE_RGB, 3, CLASS_DISPLAY)); } thisProfile = sRGBprofile; break; case ColorSpace.CS_CIEXYZ: if (XYZprofile == null) { XYZprofile = getInstance ("CIEXYZ.pf"); } thisProfile = XYZprofile; break; case ColorSpace.CS_PYCC: if (PYCCprofile == null) { PYCCprofile = getInstance ("PYCC.pf"); } thisProfile = PYCCprofile; break; case ColorSpace.CS_GRAY: if (GRAYprofile == null) { GRAYprofile = getInstance ("GRAY.pf"); } thisProfile = GRAYprofile; break; case ColorSpace.CS_LINEAR_RGB: if (LINEAR_RGBprofile == null) { LINEAR_RGBprofile = getInstance ("LINEAR_RGB.pf"); } thisProfile = LINEAR_RGBprofile; break; default: throw new IllegalArgumentException("Unknown color space"); } } catch (IOException e) { throw new IllegalArgumentException("Can't load standard profile"); } return thisProfile; } /** * 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 <code>ICC_Profile</code> 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. */ public static ICC_Profile getInstance(String fileName) throws IOException { ICC_Profile thisProfile; FileInputStream fis; if ((fis = openProfile(fileName)) == null) { throw new IOException("Cannot open file " + fileName); } thisProfile = getInstance(fis); fis.close(); /* close the file */ return thisProfile; } /** * 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 <CODE>ICC_Profile</CODE> object corresponding to the * data in the specified <code>InputStream</code>. * * @exception IOException If an I/O error occurs while reading the stream. * * @exception IllegalArgumentException If the stream does not * contain valid ICC Profile data. */ public static ICC_Profile getInstance(InputStream s) throws IOException { 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); } static byte[] getProfileDataFromStream(InputStream s) throws IOException { 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; } /** * 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. */ static ICC_Profile getDeferredInstance(ProfileDeferralInfo pdi) throws IOException { if (!ProfileDeferralMgr.deferring) { return getInstance(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); } } void activateDeferredProfile() { long[] theID = new long [1]; byte profileData[]; FileInputStream fis;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -