📄 iccprofiler.java
字号:
/***************************************************************************** * * $Id: ICCProfiler.java,v 1.2 2002/08/08 08:46:32 grosbois Exp $ * * Copyright Eastman Kodak Company, 343 State Street, Rochester, NY 14650 * $Date $ *****************************************************************************/package icc;import java.io.*;import jj2000.j2k.decoder.*;import jj2000.j2k.image.*;import jj2000.j2k.util.*;import jj2000.j2k.io.*;import colorspace.*;import icc.lut.*;/** * This class provides ICC Profiling API for the jj2000.j2k imaging chain * by implementing the BlkImgDataSrc interface, in particular the getCompData * and getInternCompData methods. * * @see jj2000.j2k.icc.ICCProfile * @version 1.0 * @author Bruce A. Kern */public class ICCProfiler extends ColorSpaceMapper { /** The prefix for ICC Profiler options */ public final static char OPT_PREFIX = 'I'; /** Platform dependant end of line String. */ protected final static String eol = System.getProperty("line.separator"); // Renamed for convenience: private static final int GRAY = RestrictedICCProfile.GRAY; private static final int RED = RestrictedICCProfile.RED; private static final int GREEN = RestrictedICCProfile.GREEN; private static final int BLUE = RestrictedICCProfile.BLUE; // ICCProfiles. RestrictedICCProfile ricc = null; ICCProfile icc = null; // Temporary variables needed during profiling. private DataBlkInt[] tempInt; // Holds the results of the transform. private DataBlkFloat [] tempFloat; // Holds the results of the transform. private Object xform = null; /** The image's ICC profile. */ private RestrictedICCProfile iccp = null; /** * Factory method for creating instances of this class. * @param src -- source of image data * @param csMap -- provides colorspace info * @return ICCProfiler instance * @exception IOException profile access exception * @exception ICCProfileException profile content exception */ public static BlkImgDataSrc createInstance(BlkImgDataSrc src, ColorSpace csMap) throws IOException, ICCProfileException, ColorSpaceException { return new ICCProfiler (src, csMap); } /** * Ctor which creates an ICCProfile for the image and initializes * all data objects (input, working, output). * * @param src -- Source of image data * @param csm -- provides colorspace info * * @exception IOException * @exception ICCProfileException * @exception IllegalArgumentException */ protected ICCProfiler (BlkImgDataSrc src, ColorSpace csMap) throws ColorSpaceException, IOException, ICCProfileException, IllegalArgumentException { super (src, csMap); initialize (); iccp = getICCProfile(csMap); if(ncomps==1) { xform = new MonochromeTransformTosRGB(iccp,maxValueArray[0], shiftValueArray[0]); } else { xform = new MatrixBasedTransformTosRGB(iccp,maxValueArray, shiftValueArray); } /* end ICCProfiler ctor */ } /** General utility used by ctors */ private void initialize() { tempInt = new DataBlkInt [ncomps]; tempFloat = new DataBlkFloat [ncomps]; /* For each component, get the maximum data value, a reference * to the pixel data and set up working and temporary DataBlks * for both integer and float output. */ for (int i=0;i<ncomps;++i) { tempInt [i] = new DataBlkInt(); tempFloat [i] = new DataBlkFloat(); }} /** * Get the ICCProfile information JP2 ColorSpace * @param csm provides all necessary info about the colorspace * @return ICCMatrixBasedInputProfile for 3 component input and * ICCMonochromeInputProfile for a 1 component source. Returns * null if exceptions were encountered. * @exception ColorSpaceException * @exception ICCProfileException * @exception IllegalArgumentException */ private RestrictedICCProfile getICCProfile (ColorSpace csm) throws ColorSpaceException, ICCProfileException, IllegalArgumentException { switch (ncomps) { case 1: icc=ICCMonochromeInputProfile.createInstance (csm); ricc = icc.parse(); if (ricc.getType() != RestrictedICCProfile.kMonochromeInput) throw new IllegalArgumentException("wrong ICCProfile type"+ " for image"); break; case 3: icc=ICCMatrixBasedInputProfile.createInstance (csm); ricc = icc.parse(); if (ricc.getType() != RestrictedICCProfile.kThreeCompInput) throw new IllegalArgumentException("wrong ICCProfile type"+ " for image"); break; default: throw new IllegalArgumentException ("illegal number of "+ "components ("+ncomps+ ") in image"); } return ricc; } /** * Returns, in the blk argument, a block of image data containing the * specifed rectangular area, in the specified component. The data is * returned, as a copy of the internal data, therefore the returned data * can be modified "in place". * * <P>The rectangular area to return is specified by the 'ulx', 'uly', 'w' * and 'h' members of the 'blk' argument, relative to the current * tile. These members are not modified by this method. The 'offset' of * the returned data is 0, and the 'scanw' is the same as the block's * width. See the 'DataBlk' class. * * <P>If the data array in 'blk' is 'null', then a new one is created. If * the data array is not 'null' then it is reused, and it must be large * enough to contain the block's data. Otherwise an 'ArrayStoreException' * or an 'IndexOutOfBoundsException' is thrown by the Java system. * * <P>The returned data has its 'progressive' attribute set to that of the * input data. * * @param out Its coordinates and dimensions specify the area to * return. If it contains a non-null data array, then it must have the * correct dimensions. If it contains a null data array a new one is * created. The fields in this object are modified to return the data. * * @param c The index of the component from which to get the data. Only 0 * and 3 are valid. * * @return The requested DataBlk * * @see #getInternCompData **/ public DataBlk getCompData (DataBlk outblk, int c) { try { if (ncomps != 1 && ncomps != 3) { String msg = "ICCProfiler: icc profile _not_ applied to " + ncomps + " component image"; FacilityManager.getMsgLogger().printmsg(MsgLogger.WARNING,msg); return src.getCompData(outblk, c); } int type = outblk.getDataType(); int leftedgeOut= -1; // offset to the start of the output scanline int rightedgeOut= -1; // offset to the end of the output // scanline + 1 int leftedgeIn= -1; // offset to the start of the input scanline int rightedgeIn= -1; // offset to the end of the input // scanline + 1 // Calculate all components: for (int i=0; i<ncomps; ++i) { int fixedPtBits = src.getFixedPoint(i); int shiftVal = shiftValueArray[i]; int maxVal = maxValueArray[i]; // Initialize general input and output indexes int kOut= -1; int kIn= -1; switch (type) { // Int and Float data only
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -