?? iccprofile.java
字號:
/** profile type */ public final static int kdwInputProfile = ICCProfile.getInt(new String ("scnr").getBytes(), 0); /** tag type */ public final static int kdwDisplayProfile = ICCProfile.getInt(new String ("mntr").getBytes(), 0); /** tag type */ public final static int kdwRGBData = ICCProfile.getInt(new String ("RGB ").getBytes(), 0); /** tag type */ public final static int kdwGrayData = ICCProfile.getInt(new String ("GRAY").getBytes(), 0); /** tag type */ public final static int kdwXYZData = ICCProfile.getInt(new String ("XYZ ").getBytes(), 0); /** input type */ public final static int kMonochromeInput = 0; /** input type */ public final static int kThreeCompInput = 1; /** tag signature */ public final static int kdwGrayTRCTag = ICCProfile.getInt(new String ("kTRC").getBytes(), 0); /** tag signature */ public final static int kdwRedColorantTag = ICCProfile.getInt(new String ("rXYZ").getBytes(), 0); /** tag signature */ public final static int kdwGreenColorantTag = ICCProfile.getInt(new String ("gXYZ").getBytes(), 0); /** tag signature */ public final static int kdwBlueColorantTag = ICCProfile.getInt(new String ("bXYZ").getBytes(), 0); /** tag signature */ public final static int kdwRedTRCTag = ICCProfile.getInt(new String ("rTRC").getBytes(), 0); /** tag signature */ public final static int kdwGreenTRCTag = ICCProfile.getInt(new String ("gTRC").getBytes(), 0); /** tag signature */ public final static int kdwBlueTRCTag = ICCProfile.getInt(new String ("bTRC").getBytes(), 0); /** tag signature */ public final static int kdwCopyrightTag = ICCProfile.getInt(new String ("cprt").getBytes(), 0); /** tag signature */ public final static int kdwMediaWhiteTag = ICCProfile.getInt(new String ("wtpt").getBytes(), 0); /** tag signature */ public final static int kdwProfileDescTag = ICCProfile.getInt(new String ("desc").getBytes(), 0); private ICCProfileHeader header = null; private ICCTagTable tags = null; private byte [] profile = null; private int getProfileSize () { return header.dwProfileSize; } private int getCMMTypeSignature () { return header.dwCMMTypeSignature; } private int getProfileClass () { return header.dwProfileClass ; } private int getColorSpaceType () { return header.dwColorSpaceType; } private int getPCSType () { return header.dwPCSType; } private int getProfileSignature () { return header.dwProfileSignature; } private int getPlatformSignature () { return header.dwPlatformSignature; } private int getCMMFlags () { return header.dwCMMFlags; } private int getDeviceManufacturer () { return header.dwDeviceManufacturer; } private int getDeviceModel () { return header.dwDeviceModel; } private int getDeviceAttributes1 () { return header.dwDeviceAttributes1; } private int getDeviceAttributesReserved () { return header.dwDeviceAttributesReserved; } private int getRenderingIntent () { return header.dwRenderingIntent; } private int getCreatorSig () { return header.dwCreatorSig; } private ICCProfileVersion getProfileVersion () { return header.profileVersion; } private void setProfileSignature (int profilesig) { header.dwProfileSignature = profilesig; } private void setProfileSize (int size) { header.dwProfileSize = size; } private void setCMMTypeSignature (int cmmsig) { header.dwCMMTypeSignature = cmmsig; } private void setProfileClass (int pclass) { header.dwProfileClass = pclass; } private void setColorSpaceType (int colorspace) { header.dwColorSpaceType = colorspace; } private void setPCSIlluminant(XYZNumber xyz) { header.PCSIlluminant = xyz; } private void setPCSType (int PCStype) { header.dwPCSType = PCStype; } private void setPlatformSignature (int platformsig) { header.dwPlatformSignature = platformsig; } private void setCMMFlags (int cmmflags) { header.dwCMMFlags = cmmflags; } private void setDeviceManufacturer (int manufacturer) { header.dwDeviceManufacturer = manufacturer; } private void setDeviceModel (int model) { header.dwDeviceModel = model; } private void setDeviceAttributes1 (int attr1) { header.dwDeviceAttributes1 = attr1; } private void setDeviceAttributesReserved (int attrreserved) { header.dwDeviceAttributesReserved = attrreserved; } private void setRenderingIntent (int rendering) { header.dwRenderingIntent = rendering; } private void setCreatorSig (int creatorsig) { header.dwCreatorSig = creatorsig; } private void setProfileVersion (ICCProfileVersion version) { header.profileVersion = version; } private void setDateTime (ICCDateTime datetime) { header.dateTime = datetime; } private byte [] data = null; private ParameterList pl = null; private ICCProfile () throws ICCProfileException { throw new ICCProfileException ("illegal to invoke empty constructor"); } /** * ParameterList constructor * @param csb provides colorspace information */ protected ICCProfile (ColorSpace csm) throws ColorSpaceException, ICCProfileInvalidException { this.pl = csm.pl; profile = csm.getICCProfile(); initProfile(profile); } /** * Read the header and tags into memory and verify * that the correct type of profile is being used. for encoding. * @param data ICCProfile * @exception ICCProfileInvalidException for bad signature and class and bad type */ private void initProfile (byte [] data) throws ICCProfileInvalidException { header = new ICCProfileHeader (data); tags = ICCTagTable.createInstance(data); // Verify that the data pointed to by icc is indeed a valid profile // and that it is possibly of one of the Restricted ICC types. The simplest way to check // this is to verify that the profile signature is correct, that it is an input profile, // and that the PCS used is XYX. // However, a common error in profiles will be to create Monitor profiles rather // than input profiles. If this is the only error found, it's still useful to let this // go through with an error written to stderr. if (getProfileClass() == kdwDisplayProfile) { String message = "NOTE!! Technically, this profile is a Display profile, not an" + " Input Profile, and thus is not a valid Restricted ICC profile." + " However, it is quite possible that this profile is usable as" + " a Restricted ICC profile, so this code will ignore this state" + " and proceed with processing."; FacilityManager.getMsgLogger(). printmsg(MsgLogger.WARNING,message); } if ((getProfileSignature() != kdwProfileSignature) || ((getProfileClass() != kdwInputProfile) && (getProfileClass() != kdwDisplayProfile)) || (getPCSType() != kdwXYZData)) { throw new ICCProfileInvalidException (); }} /** Provide a suitable string representation for the class */ public String toString () { StringBuffer rep = new StringBuffer("[ICCProfile:"); StringBuffer body = new StringBuffer(); body.append(eol).append(header); body.append(eol).append(eol).append(tags); rep.append(ColorSpace.indent(" ", body)); return rep.append("]").toString(); } /** * Create a two character hex representation of a byte * @param i byte to represent * @return representation */ public static String toHexString(byte i) { String rep = (i>=0 && i<16 ? "0" : "") + Integer.toHexString((int)i); if (rep.length()>2) rep = rep.substring(rep.length()-2); return rep; } /** * Create a 4 character hex representation of a short * @param i short to represent * @return representation */ public static String toHexString(short i) { String rep; if (i>=0 && i<0x10) rep = "000" + Integer.toHexString((int)i); else if (i>=0 && i<0x100) rep = "00" + Integer.toHexString((int)i); else if (i>=0 && i<0x1000) rep = "0" + Integer.toHexString((int)i); else rep = "" + Integer.toHexString((int)i); if (rep.length()>4) rep = rep.substring(rep.length()-4); return rep; } /** * Create a 8 character hex representation of a int * @param i int to represent * @return representation */ public static String toHexString(int i) { String rep; if (i>=0 && i<0x10) rep = "0000000" + Integer.toHexString((int)i); else if (i>=0 && i<0x100) rep = "000000" + Integer.toHexString((int)i); else if (i>=0 && i<0x1000) rep = "00000" + Integer.toHexString((int)i); else if (i>=0 && i<0x10000) rep = "0000" + Integer.toHexString((int)i); else if (i>=0 && i<0x100000) rep = "000" + Integer.toHexString((int)i); else if (i>=0 && i<0x1000000) rep = "00" + Integer.toHexString((int)i); else if (i>=0 && i<0x10000000) rep = "0" + Integer.toHexString((int)i); else rep = "" + Integer.toHexString((int)i); if (rep.length()>8) rep = rep.substring(rep.length()-8); return rep; } public static String toString (byte [] data) { int i, row,col,rem,rows,cols; StringBuffer rep = new StringBuffer(); StringBuffer rep0 = null; StringBuffer rep1 = null; StringBuffer rep2 = null; cols = 16; rows = data.length/cols; rem = data.length%cols; byte [] lbytes = new byte [8]; for(row=0, i=0; row<rows; ++row) { rep1 = new StringBuffer(); rep2 = new StringBuffer(); for (i=0;i<8;++i) lbytes[i]=0; byte [] tbytes = Integer.toHexString (row*16).getBytes(); for (int t=0,l=lbytes.length-tbytes.length; t<tbytes.length; ++l,++t) lbytes[l] = tbytes[t]; rep0 = new StringBuffer(new String(lbytes)); for (col=0; col<cols; ++col) { byte b = data[i++]; rep1 .append(toHexString(b)).append(i%2 == 0 ? " " : ""); if (Character.isJavaIdentifierStart((char)b)) rep2 .append((char)b); else rep2 .append("."); } rep .append(rep0) .append(" : ") .append(rep1) .append(": ") .append(rep2).append(eol); } rep1 = new StringBuffer(); rep2 = new StringBuffer(); for (i=0;i<8;++i) lbytes[i]=0; byte [] tbytes = Integer.toHexString (row*16).getBytes(); for (int t=0,l=lbytes.length-tbytes.length; t<tbytes.length; ++l,++t) lbytes[l] = tbytes[t]; rep0 = new StringBuffer(new String(lbytes)); for (col=0; col<rem; ++col) { byte b = data[i++]; rep1 .append(toHexString(b)).append(i%2 == 0 ? " " : ""); if (Character.isJavaIdentifierStart((char)b)) rep2 .append((char)b); else rep2 .append("."); } for (col=rem; col<16; ++col) rep1 .append(" ").append(col%2 == 0 ? " " : ""); rep .append(rep0) .append(" : ") .append(rep1) .append(": ") .append(rep2).append(eol); return rep.toString(); } /** * Access the profile header * @return ICCProfileHeader */ public ICCProfileHeader getHeader () {return header;} /** * Access the profile tag table * @return ICCTagTable */ public ICCTagTable getTagTable () {return tags;} /** * Parse this ICCProfile into a RestrictedICCProfile * which is appropriate to the data in this profile. * Either a MonochromeInputRestrictedProfile or * MatrixBasedRestrictedProfile is returned * @return RestrictedICCProfile * @exception ICCProfileInvalidException no curve data */ public RestrictedICCProfile parse () throws ICCProfileInvalidException { // The next step is to determine which Restricted ICC type is used by this profile. // Unfortunately, the only way to do this is to look through the tag table for // the tags required by the two types. // First look for the gray TRC tag. If the profile is indeed an input profile, and this // tag exists, then the profile is a Monochrome Input profile ICCCurveType grayTag = (ICCCurveType) tags.get(new Integer(kdwGrayTRCTag)); if (grayTag != null) { return RestrictedICCProfile.createInstance (grayTag); } // If it wasn't a Monochrome Input profile, look for the Red Colorant tag. If that // tag is found and the profile is indeed an input profile, then this profile is // a Three-Component Matrix-Based Input profile ICCCurveType rTRCTag = (ICCCurveType) tags.get(new Integer(kdwRedTRCTag)); if (rTRCTag != null) { ICCCurveType gTRCTag = (ICCCurveType) tags.get(new Integer(kdwGreenTRCTag)); ICCCurveType bTRCTag = (ICCCurveType) tags.get(new Integer(kdwBlueTRCTag)); ICCXYZType rColorantTag = (ICCXYZType) tags.get(new Integer(kdwRedColorantTag)); ICCXYZType gColorantTag = (ICCXYZType) tags.get(new Integer(kdwGreenColorantTag)); ICCXYZType bColorantTag = (ICCXYZType) tags.get(new Integer(kdwBlueColorantTag)); return RestrictedICCProfile.createInstance (rTRCTag, gTRCTag, bTRCTag, rColorantTag, gColorantTag, bColorantTag); } throw new ICCProfileInvalidException ("curve data not found in profile"); } /** * Output this ICCProfile to a RandomAccessFile * @param os output file */ public void write (RandomAccessFile os) throws IOException { getHeader().write (os); getTagTable().write (os); } /* end class ICCProfile */ }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -