📄 icc_profile.java
字号:
/* ICC_Profile.java -- color space profiling Copyright (C) 2000, 2002, 2004 Free Software FoundationThis file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package java.awt.color;import gnu.java.awt.color.ProfileHeader;import gnu.java.awt.color.TagEntry;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.io.ObjectStreamException;import java.io.OutputStream;import java.io.Serializable;import java.io.UnsupportedEncodingException;import java.nio.ByteBuffer;import java.util.Enumeration;import java.util.Hashtable;/** * ICC Profile - represents an ICC Color profile. * The ICC profile format is a standard file format which maps the transform * from a device color space to a standard Profile Color Space (PCS), which * can either be CIE L*a*b or CIE XYZ. * (With the exception of device link profiles which map from one device space * to another) * * ICC profiles calibrated to specific input/output devices are used when color * fidelity is of importance. * * An instance of ICC_Profile can be created using the getInstance() methods, * either using one of the predefined color spaces enumerated in ColorSpace, * or from an ICC profile file, or from an input stream. * * An ICC_ColorSpace object can then be created to transform color values * through the profile. * * The ICC_Profile class implements the version 2 format specified by * International Color Consortium Specification ICC.1:1998-09, * and its addendum ICC.1A:1999-04, April 1999 * (available at www.color.org) * * @author Sven de Marothy * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) * @since 1.2 */public class ICC_Profile implements Serializable{ /** * Compatible with JDK 1.2+. */ private static final long serialVersionUID = -3938515861990936766L; /** * ICC Profile classes */ public static final int CLASS_INPUT = 0; public static final int CLASS_DISPLAY = 1; public static final int CLASS_OUTPUT = 2; public static final int CLASS_DEVICELINK = 3; public static final int CLASS_COLORSPACECONVERSION = 4; public static final int CLASS_ABSTRACT = 5; public static final int CLASS_NAMEDCOLOR = 6; /** * ICC Profile class signatures */ public static final int icSigInputClass = 0x73636e72; // 'scnr' public static final int icSigDisplayClass = 0x6d6e7472; // 'mntr' public static final int icSigOutputClass = 0x70727472; // 'prtr' public static final int icSigLinkClass = 0x6c696e6b; // 'link' public static final int icSigColorSpaceClass = 0x73706163; // 'spac' public static final int icSigAbstractClass = 0x61627374; // 'abst' public static final int icSigNamedColorClass = 0x6e6d636c; // 'nmcl' /** * Color space signatures */ public static final int icSigXYZData = 0x58595A20; // 'XYZ ' public static final int icSigLabData = 0x4C616220; // 'Lab ' public static final int icSigLuvData = 0x4C757620; // 'Luv ' public static final int icSigYCbCrData = 0x59436272; // 'YCbr' public static final int icSigYxyData = 0x59787920; // 'Yxy ' public static final int icSigRgbData = 0x52474220; // 'RGB ' public static final int icSigGrayData = 0x47524159; // 'GRAY' public static final int icSigHsvData = 0x48535620; // 'HSV ' public static final int icSigHlsData = 0x484C5320; // 'HLS ' public static final int icSigCmykData = 0x434D594B; // 'CMYK' public static final int icSigCmyData = 0x434D5920; // 'CMY ' public static final int icSigSpace2CLR = 0x32434C52; // '2CLR' public static final int icSigSpace3CLR = 0x33434C52; // '3CLR' public static final int icSigSpace4CLR = 0x34434C52; // '4CLR' public static final int icSigSpace5CLR = 0x35434C52; // '5CLR' public static final int icSigSpace6CLR = 0x36434C52; // '6CLR' public static final int icSigSpace7CLR = 0x37434C52; // '7CLR' public static final int icSigSpace8CLR = 0x38434C52; // '8CLR' public static final int icSigSpace9CLR = 0x39434C52; // '9CLR' public static final int icSigSpaceACLR = 0x41434C52; // 'ACLR' public static final int icSigSpaceBCLR = 0x42434C52; // 'BCLR' public static final int icSigSpaceCCLR = 0x43434C52; // 'CCLR' public static final int icSigSpaceDCLR = 0x44434C52; // 'DCLR' public static final int icSigSpaceECLR = 0x45434C52; // 'ECLR' public static final int icSigSpaceFCLR = 0x46434C52; // 'FCLR' /** * Rendering intents */ public static final int icPerceptual = 0; public static final int icRelativeColorimetric = 1; public static final int icSaturation = 2; public static final int icAbsoluteColorimetric = 3; /** * Tag signatures */ public static final int icSigAToB0Tag = 0x41324230; // 'A2B0' public static final int icSigAToB1Tag = 0x41324231; // 'A2B1' public static final int icSigAToB2Tag = 0x41324232; // 'A2B2' public static final int icSigBlueColorantTag = 0x6258595A; // 'bXYZ' public static final int icSigBlueTRCTag = 0x62545243; // 'bTRC' public static final int icSigBToA0Tag = 0x42324130; // 'B2A0' public static final int icSigBToA1Tag = 0x42324131; // 'B2A1' public static final int icSigBToA2Tag = 0x42324132; // 'B2A2' public static final int icSigCalibrationDateTimeTag = 0x63616C74; // 'calt' public static final int icSigCharTargetTag = 0x74617267; // 'targ' public static final int icSigCopyrightTag = 0x63707274; // 'cprt' public static final int icSigCrdInfoTag = 0x63726469; // 'crdi' public static final int icSigDeviceMfgDescTag = 0x646D6E64; // 'dmnd' public static final int icSigDeviceModelDescTag = 0x646D6464; // 'dmdd' public static final int icSigDeviceSettingsTag = 0x64657673; // 'devs' public static final int icSigGamutTag = 0x67616D74; // 'gamt' public static final int icSigGrayTRCTag = 0x6b545243; // 'kTRC' public static final int icSigGreenColorantTag = 0x6758595A; // 'gXYZ' public static final int icSigGreenTRCTag = 0x67545243; // 'gTRC' public static final int icSigLuminanceTag = 0x6C756d69; // 'lumi' public static final int icSigMeasurementTag = 0x6D656173; // 'meas' public static final int icSigMediaBlackPointTag = 0x626B7074; // 'bkpt' public static final int icSigMediaWhitePointTag = 0x77747074; // 'wtpt' public static final int icSigNamedColor2Tag = 0x6E636C32; // 'ncl2' public static final int icSigOutputResponseTag = 0x72657370; // 'resp' public static final int icSigPreview0Tag = 0x70726530; // 'pre0' public static final int icSigPreview1Tag = 0x70726531; // 'pre1' public static final int icSigPreview2Tag = 0x70726532; // 'pre2' public static final int icSigProfileDescriptionTag = 0x64657363; // 'desc' public static final int icSigProfileSequenceDescTag = 0x70736571; // 'pseq' public static final int icSigPs2CRD0Tag = 0x70736430; // 'psd0' public static final int icSigPs2CRD1Tag = 0x70736431; // 'psd1' public static final int icSigPs2CRD2Tag = 0x70736432; // 'psd2' public static final int icSigPs2CRD3Tag = 0x70736433; // 'psd3' public static final int icSigPs2CSATag = 0x70733273; // 'ps2s' public static final int icSigPs2RenderingIntentTag = 0x70733269; // 'ps2i' public static final int icSigRedColorantTag = 0x7258595A; // 'rXYZ' public static final int icSigRedTRCTag = 0x72545243; // 'rTRC' public static final int icSigScreeningDescTag = 0x73637264; // 'scrd' public static final int icSigScreeningTag = 0x7363726E; // 'scrn' public static final int icSigTechnologyTag = 0x74656368; // 'tech' public static final int icSigUcrBgTag = 0x62666420; // 'bfd ' public static final int icSigViewingCondDescTag = 0x76756564; // 'vued' public static final int icSigViewingConditionsTag = 0x76696577; // 'view' public static final int icSigChromaticityTag = 0x6368726D; // 'chrm' /** * Non-ICC tag 'head' for use in retrieving the header with getData() */ public static final int icSigHead = 0x68656164; /** * Header offsets */ public static final int icHdrSize = 0; public static final int icHdrCmmId = 4; public static final int icHdrVersion = 8; public static final int icHdrDeviceClass = 12; public static final int icHdrColorSpace = 16; public static final int icHdrPcs = 20; public static final int icHdrDate = 24; public static final int icHdrMagic = 36; public static final int icHdrPlatform = 40; public static final int icHdrFlags = 44; public static final int icHdrManufacturer = 48; public static final int icHdrModel = 52; public static final int icHdrAttributes = 56; public static final int icHdrRenderingIntent = 64; public static final int icHdrIlluminant = 68; public static final int icHdrCreator = 80; /** * */ public static final int icTagType = 0; public static final int icTagReserved = 4; public static final int icCurveCount = 8; public static final int icCurveData = 12; public static final int icXYZNumberX = 8; /** * offset of the Tag table */ private static final int tagTableOffset = 128; /** * @serial */ private static final int iccProfileSerializedDataVersion = 1; /** * Constants related to generating profiles for * built-in colorspace profiles */ /** * Copyright notice to stick into built-in-profile files. */ private static final String copyrightNotice = "Generated by GNU Classpath."; /** * Resolution of the TRC to use for predefined profiles. * 1024 should suffice. */ private static final int TRC_POINTS = 1024; /** * CIE 1931 D50 white point (in Lab coordinates) */ private static final float[] D50 = { 0.96422f, 1.00f, 0.82521f }; /** * Color space profile ID * Set to the predefined profile class (e.g. CS_sRGB) if a predefined * color space is used, set to -1 otherwise. * (or if the profile has been modified) */ private transient int profileID; /** * The profile header data */ private transient ProfileHeader header; /** * A hashtable containing the profile tags as TagEntry objects */ private transient Hashtable tagTable; /** * Contructor for predefined colorspaces */ ICC_Profile(int profileID) { header = null; tagTable = null; createProfile(profileID); } /** * Constructs an ICC_Profile from a header and a table of loaded tags. */ ICC_Profile(ProfileHeader h, Hashtable tags) throws IllegalArgumentException { header = h; tagTable = tags; profileID = -1; // Not a predefined color space } /** * Constructs an ICC_Profile from a byte array of data. */ ICC_Profile(byte[] data) throws IllegalArgumentException { // get header and verify it header = new ProfileHeader(data); header.verifyHeader(data.length); tagTable = createTagTable(data); profileID = -1; // Not a predefined color space } /** * Free up the used memory. */ protected void finalize() { } /** * Returns an ICC_Profile instance from a byte array of profile data. * * An instance of the specialized classes ICC_ProfileRGB or ICC_ProfileGray * may be returned if appropriate. * * @param data - the profile data * @return An ICC_Profile object * * @throws IllegalArgumentException if the profile data is an invalid * v2 profile. */ public static ICC_Profile getInstance(byte[] data) { ProfileHeader header = new ProfileHeader(data); // verify it as a correct ICC header, including size header.verifyHeader(data.length); Hashtable tags = createTagTable(data); if (isRGBProfile(header, tags)) return new ICC_ProfileRGB(data); if (isGrayProfile(header, tags)) return new ICC_ProfileGray(data); return new ICC_Profile(header, tags); } /** * Returns an predefined ICC_Profile instance. * * This will construct an ICC_Profile instance from one of the predefined * color spaces in the ColorSpace class. (e.g. CS_sRGB, CS_GRAY, etc) * * An instance of the specialized classes ICC_ProfileRGB or ICC_ProfileGray * may be returned if appropriate. * * @return An ICC_Profile object */ public static ICC_Profile getInstance(int cspace) { if (cspace == ColorSpace.CS_sRGB || cspace == ColorSpace.CS_LINEAR_RGB) return new ICC_ProfileRGB(cspace); if (cspace == ColorSpace.CS_GRAY) return new ICC_ProfileGray(cspace); return new ICC_Profile(cspace); } /** * Returns an ICC_Profile instance from an ICC Profile file. * * An instance of the specialized classes ICC_ProfileRGB or ICC_ProfileGray * may be returned if appropriate. * * @param filename - the file name of the profile file. * @return An ICC_Profile object * * @throws IllegalArgumentException if the profile data is an invalid * v2 profile. * @throws IOException if the file could not be read. */ public static ICC_Profile getInstance(String filename) throws IOException { return getInstance(new FileInputStream(filename)); } /** * Returns an ICC_Profile instance from an InputStream. * * This method can be used for reading ICC profiles embedded in files * which support this. (JPEG and SVG for instance). * * The stream is treated in the following way: The profile header * (128 bytes) is read first, and the header is validated. If the profile * header is valid, it will then attempt to read the rest of the profile * from the stream. The stream is not closed after reading. * * An instance of the specialized classes ICC_ProfileRGB or ICC_ProfileGray * may be returned if appropriate. * * @param in - the input stream to read the profile from. * @return An ICC_Profile object * * @throws IllegalArgumentException if the profile data is an invalid * v2 profile. * @throws IOException if the stream could not be read. */ public static ICC_Profile getInstance(InputStream in) throws IOException { // read the header byte[] headerData = new byte[ProfileHeader.HEADERSIZE]; if (in.read(headerData) != ProfileHeader.HEADERSIZE)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -