?? iccprofile.java
字號:
/***************************************************************************** * * $Id: ICCProfile.java,v 1.1.1.1 2002/08/02 09:47:03 grosbois Exp $ * * Copyright Eastman Kodak Company, 343 State Street, Rochester, NY 14650 * $Date $ *****************************************************************************/package icc;import java.io.File;import java.io.RandomAccessFile;import java.io.BufferedReader;import java.io.InputStreamReader;import java.io.FileInputStream;import java.io.InputStream;import java.io.IOException;import java.util.Calendar;import java.util.GregorianCalendar;import jj2000.j2k.util.ParameterList;import jj2000.j2k.decoder.DecoderSpecs;import jj2000.j2k.codestream.reader.BitstreamReaderAgent;import colorspace .ColorSpace;import colorspace .ColorSpaceException;import icc .types.ICCProfileHeader;import icc .tags.ICCTag;import icc .tags.ICCTagTable;import icc .tags.ICCCurveType;import icc .tags.ICCXYZType;import icc .types.XYZNumber;import icc .types.ICCProfileVersion;import icc .types.ICCDateTime;import jj2000.j2k.fileformat.FileFormatBoxes;import jj2000.j2k.io.RandomAccessIO;import jj2000.j2k.util.FacilityManager;import jj2000.j2k.util.MsgLogger;import jj2000.j2k.fileformat.FileFormatBoxes;/** * This class models the ICCProfile file. This file is a binary file which is divided * into two parts, an ICCProfileHeader followed by an ICCTagTable. The header is a * straightforward list of descriptive parameters such as profile size, version, date and various * more esoteric parameters. The tag table is a structured list of more complexly aggragated data * describing things such as ICC curves, copyright information, descriptive text blocks, etc. * * Classes exist to model the header and tag table and their various constituent parts the developer * is refered to these for further information on the structure and contents of the header and tag table. * * @see jj2000.j2k.icc.types.ICCProfileHeader * @see jj2000.j2k.icc.tags.ICCTagTable * @version 1.0 * @author Bruce A. Kern */public abstract class ICCProfile { private static final String eol = System.getProperty("line.separator"); // Renamed for convenience: /** Gray index. */ public static final int GRAY = 0; /** RGB index. */ public static final int RED = 0; /** RGB index. */ public static final int GREEN = 1; /** RGB index. */ public static final int BLUE = 2; /** Size of native type */ public final static int boolean_size = 1; /** Size of native type */ public final static int byte_size = 1; /** Size of native type */ public final static int char_size = 2; /** Size of native type */ public final static int short_size = 2; /** Size of native type */ public final static int int_size = 4; /** Size of native type */ public final static int float_size = 4; /** Size of native type */ public final static int long_size = 8; /** Size of native type */ public final static int double_size = 8; /* Bit twiddling constant for integral types. */ public final static int BITS_PER_BYTE = 8; /* Bit twiddling constant for integral types. */ public final static int BITS_PER_SHORT = 16; /* Bit twiddling constant for integral types. */ public final static int BITS_PER_INT = 32; /* Bit twiddling constant for integral types. */ public final static int BITS_PER_LONG = 64; /* Bit twiddling constant for integral types. */ public final static int BYTES_PER_SHORT = 2; /* Bit twiddling constant for integral types. */ public final static int BYTES_PER_INT = 4; /* Bit twiddling constant for integral types. */ public final static int BYTES_PER_LONG = 8; /* JP2 Box structure analysis help */ private static class BoxType extends java.util.Hashtable { private static java.util.Hashtable map = new java.util.Hashtable(); static { put (FileFormatBoxes.BITS_PER_COMPONENT_BOX,"BITS_PER_COMPONENT_BOX"); put (FileFormatBoxes.CAPTURE_RESOLUTION_BOX,"CAPTURE_RESOLUTION_BOX"); put (FileFormatBoxes.CHANNEL_DEFINITION_BOX,"CHANNEL_DEFINITION_BOX"); put (FileFormatBoxes.COLOUR_SPECIFICATION_BOX,"COLOUR_SPECIFICATION_BOX"); put (FileFormatBoxes.COMPONENT_MAPPING_BOX,"COMPONENT_MAPPING_BOX"); put (FileFormatBoxes.CONTIGUOUS_CODESTREAM_BOX,"CONTIGUOUS_CODESTREAM_BOX"); put (FileFormatBoxes.DEFAULT_DISPLAY_RESOLUTION_BOX,"DEFAULT_DISPLAY_RESOLUTION_BOX"); put (FileFormatBoxes.FILE_TYPE_BOX,"FILE_TYPE_BOX"); put (FileFormatBoxes.IMAGE_HEADER_BOX,"IMAGE_HEADER_BOX"); put (FileFormatBoxes.INTELLECTUAL_PROPERTY_BOX,"INTELLECTUAL_PROPERTY_BOX"); put (FileFormatBoxes.JP2_HEADER_BOX,"JP2_HEADER_BOX"); put (FileFormatBoxes.JP2_SIGNATURE_BOX,"JP2_SIGNATURE_BOX"); put (FileFormatBoxes.PALETTE_BOX,"PALETTE_BOX"); put (FileFormatBoxes.RESOLUTION_BOX,"RESOLUTION_BOX"); put (FileFormatBoxes.URL_BOX,"URL_BOX"); put (FileFormatBoxes.UUID_BOX,"UUID_BOX"); put (FileFormatBoxes.UUID_INFO_BOX,"UUID_INFO_BOX"); put (FileFormatBoxes.UUID_LIST_BOX,"UUID_LIST_BOX"); put (FileFormatBoxes.XML_BOX,"XML_BOX"); } public static void put (int type, String desc) { map.put (new Integer (type), desc); } public static String get (int type) { return (String) map.get (new Integer(type));} public static String colorSpecMethod(int meth) { switch (meth) { case 2: return "Restricted ICC Profile"; case 1: return "Enumerated Color Space"; default: return "Undefined Color Spec Method"; }}} /** * Creates an int from a 4 character String * @param fourChar string representation of an integer * @return the integer which is denoted by the input String. */ public static int getIntFromString (String fourChar) { byte [] bytes = fourChar.getBytes(); return getInt (bytes,0); } /** * Create an XYZNumber from byte [] input * @param data array containing the XYZNumber representation * @param offset start of the rep in the array * @return the created XYZNumber */ public static XYZNumber getXYZNumber (byte [] data, int offset) { int x,y,z; x = getInt (data,offset); y = getInt (data,offset+int_size); z = getInt (data,offset+2*int_size); return new XYZNumber (x,y,z); } /** * Create an ICCProfileVersion from byte [] input * @param data array containing the ICCProfileVersion representation * @param offset start of the rep in the array * @return the created ICCProfileVersion */ public static ICCProfileVersion getICCProfileVersion (byte [] data, int offset) { byte major = data [offset]; byte minor = data [offset+byte_size]; byte resv1 = data [offset+2*byte_size]; byte resv2 = data [offset+3*byte_size]; return new ICCProfileVersion (major, minor, resv1, resv2); } /** * Create an ICCDateTime from byte [] input * @param data array containing the ICCProfileVersion representation * @param offset start of the rep in the array * @return the created ICCProfileVersion */ public static ICCDateTime getICCDateTime (byte [] data, int offset) { short wYear = getShort(data, offset); // Number of the actual year (i.e. 1994) short wMonth = getShort(data, offset+ICCProfile.short_size); // Number of the month (1-12) short wDay = getShort(data, offset+2*ICCProfile.short_size); // Number of the day short wHours = getShort(data, offset+3*ICCProfile.short_size); // Number of hours (0-23) short wMinutes = getShort(data, offset+4*ICCProfile.short_size); // Number of minutes (0-59) short wSeconds = getShort(data, offset+5*ICCProfile.short_size); // Number of seconds (0-59) return new ICCDateTime (wYear, wMonth, wDay, wHours, wMinutes, wSeconds); } /** * Create a String from a byte []. Optionally swap adjacent byte * pairs. Intended to be used to create integer String representations * allowing for endian translations. * @param bfr data array * @param offset start of data in array * @param length length of data in array * @param swap swap adjacent bytes? * @return String rep of data */ public static String getString (byte [] bfr, int offset, int length, boolean swap) { byte [] result = new byte [length]; int incr = swap ? -1 : 1; int start = swap ? offset+length-1 : offset; for (int i=0, j=start; i<length; ++i) { result[i] = bfr [j]; j += incr; } return new String (result); } /** * Create a short from a two byte [], with optional byte swapping. * @param bfr data array * @param off start of data in array * @param swap swap bytes? * @return native type from representation. */ public static short getShort (byte [] bfr, int off, boolean swap) { int tmp0 = bfr [off] & 0xff; // Clear the sign extended bits in the int. int tmp1 = bfr [off+1] & 0xff; return (short) (swap ? (tmp1 << BITS_PER_BYTE | tmp0): (tmp0 << BITS_PER_BYTE | tmp1)); } /** * Create a short from a two byte []. * @param bfr data array * @param off start of data in array * @return native type from representation. */ public static short getShort (byte [] bfr, int off) { int tmp0 = bfr [off] & 0xff; // Clear the sign extended bits in the int. int tmp1 = bfr [off+1] & 0xff; return (short) (tmp0 << BITS_PER_BYTE | tmp1); } /** * Separate bytes in an int into a byte array lsb to msb order. * @param d integer to separate * @return byte [] containing separated int. */ public static byte[] setInt (int d) { return setInt(d, new byte [BYTES_PER_INT]); } /** * Separate bytes in an int into a byte array lsb to msb order. * Return the result in the provided array * @param d integer to separate * @param b return output here. * @return reference to output. */ public static byte[] setInt (int d, byte [] b) { if (b==null) b = new byte [BYTES_PER_INT]; for (int i=0;i<BYTES_PER_INT;++i) { b[i] = (byte) (d & 0x0ff); d = d >> BITS_PER_BYTE; } return b; } /** * Separate bytes in a long into a byte array lsb to msb order. * @param d long to separate * @return byte [] containing separated int. */ public static byte[] setLong (long d) { return setLong(d, new byte [BYTES_PER_INT]); } /** * Separate bytes in a long into a byte array lsb to msb order. * Return the result in the provided array * @param d long to separate * @param b return output here. * @return reference to output. */ public static byte[] setLong (long d, byte [] b) { if (b==null) b = new byte [BYTES_PER_LONG]; for (int i=0;i<BYTES_PER_LONG;++i) { b[i] = (byte) (d & 0x0ff); d = d >> BITS_PER_BYTE; } return b; } /** * Create an int from a byte [4], with optional byte swapping. * @param bfr data array * @param off start of data in array * @param swap swap bytes? * @return native type from representation. */ public static int getInt (byte [] bfr, int off, boolean swap) { int tmp0 = getShort (bfr, off, swap) & 0xffff; // Clear the sign extended bits in the int. int tmp1 = getShort (bfr, off+2, swap) & 0xffff; return (int) (swap ? (tmp1 << BITS_PER_SHORT | tmp0): (tmp0 << BITS_PER_SHORT | tmp1)); } /** * Create an int from a byte [4]. * @param bfr data array * @param off start of data in array * @return native type from representation. */ public static int getInt (byte [] bfr, int off) { int tmp0 = getShort (bfr, off) & 0xffff; // Clear the sign extended bits in the int. int tmp1 = getShort (bfr, off+2) & 0xffff; return (int) (tmp0 << BITS_PER_SHORT | tmp1); } /** * Create an long from a byte [8]. * @param bfr data array * @param off start of data in array * @return native type from representation. */ public static long getLong (byte [] bfr, int off) { long tmp0 = getInt (bfr, off) & 0xffffffff; // Clear the sign extended bits in the int. long tmp1 = getInt (bfr, off+4) & 0xffffffff; return (long) (tmp0 << BITS_PER_INT | tmp1); } // Define the set of standard signature and type values // Because of the endian issues and byte swapping, the profile codes must // be stored in memory and be addressed by address. As such, only those // codes required for Restricted ICC use are defined here /** signature */ public final static int kdwProfileSignature = ICCProfile.getInt(new String ("acsp").getBytes(), 0); /** signature */ public final static int kdwProfileSigReverse = ICCProfile.getInt(new String ("psca").getBytes(), 0);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -