palettizedcolorspacemapper.java

来自「jpeg2000编解码」· Java 代码 · 共 414 行 · 第 1/2 页

JAVA
414
字号
/***************************************************************************** * * $Id: PalettizedColorSpaceMapper.java,v 1.3 2002/08/08 13:55:08 grosbois Exp $ * * Copyright Eastman Kodak Company, 343 State Street, Rochester, NY 14650 * $Date $ *****************************************************************************/package colorspace;import jj2000.j2k.image.*;import jj2000.j2k.util.*;import colorspace.boxes.*;/** * This class provides decoding of images with palettized colorspaces. * Here each sample in the input is treated as an index into a color * palette of triplet sRGB output values. *  * @see		jj2000.j2k.colorspace.ColorSpace * @version	1.0 * @author	Bruce A. Kern */public class PalettizedColorSpaceMapper extends ColorSpaceMapper {    int [] outShiftValueArray;    int srcChannel = 0;    /** Access to the palette box information. */     private PaletteBox /*final*/ pbox;     /**     * Factory method for creating instances of this class.     *   @param src -- source of image data     *   @param csMap -- provides colorspace info     * @return PalettizedColorSpaceMapper instance     */    public static BlkImgDataSrc createInstance(BlkImgDataSrc src, 					       ColorSpace csMap)         throws ColorSpaceException {        return new PalettizedColorSpaceMapper (src, csMap);     }    /**     * Ctor which creates an ICCProfile for the image and initializes     * all data objects (input, working, and output).     *     *   @param src -- Source of image data     *   @param csm -- provides colorspace info     */    protected PalettizedColorSpaceMapper(BlkImgDataSrc src, ColorSpace csMap)          throws ColorSpaceException {        super (src, csMap);        pbox = csMap.getPaletteBox();        initialize();    }    /** General utility used by ctors */    private void initialize() throws ColorSpaceException {        if(ncomps!=1 && ncomps!= 3)             throw new ColorSpaceException                 ("wrong number of components ("+ncomps+		 ") for palettized image");         int outComps = getNumComps();        outShiftValueArray = new int[outComps];        for (int i=0; i<outComps; i++) {            outShiftValueArray[i] = 1<<(getNomRangeBits(i)-1); }}    /**     * 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 blk 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 out, int c) {        if (pbox==null) return src.getCompData(out,c);        if (ncomps != 1) {            String msg = "PalettizedColorSpaceMapper: color palette "+		"_not_ applied, incorrect number ("                +String.valueOf(ncomps) + ") of components";            FacilityManager.getMsgLogger().printmsg(MsgLogger.WARNING,msg);            return src.getCompData(out, c); }                // Initialize general input and output indexes        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        int kOut= -1;         int kIn=  -1;        // Assure a properly sized data buffer for output.        setInternalBuffer (out);        switch (out.getDataType()) { // Int and Float data only            case DataBlk.TYPE_INT:                copyGeometry (inInt[0], out);                                // Request data from the source.                        inInt [0] = (DataBlkInt) src.getInternCompData(inInt[0],0);                dataInt[0] = (int[]) inInt[0].getData();                int [] outdataInt = ((DataBlkInt) out).getDataInt();                // The nitty-gritty.                for(int row=0; row<out.h; ++row) {                    leftedgeIn  = inInt[0].offset + row*inInt[0].scanw;                    rightedgeIn = leftedgeIn + inInt[0].w;                    leftedgeOut  = out.offset + row*out.scanw;                    rightedgeOut = leftedgeOut + out.w;                                        for(kOut=leftedgeOut, kIn=leftedgeIn; kIn<rightedgeIn; 			++kIn, ++kOut) {                                                     outdataInt[kOut] =                             pbox.getEntry(c,dataInt[0][kIn]+shiftValueArray[0])                            -outShiftValueArray[c]; }}                out.progressive = inInt[0].progressive;                break;                                case DataBlk.TYPE_FLOAT:                copyGeometry (inFloat[0], out);                                // Request data from the source.                        inFloat[0] = (DataBlkFloat)src.getInternCompData(inFloat[0],0);                dataFloat[0] = (float[]) inFloat[0].getData();                float [] outdataFloat = ((DataBlkFloat) out).getDataFloat();                // The nitty-gritty.                for(int row=0; row<out.h; ++row) {                    leftedgeIn  = inFloat[0].offset + row*inFloat[0].scanw;                    rightedgeIn = leftedgeIn + inFloat[0].w;                    leftedgeOut  = out.offset + row*out.scanw;                    rightedgeOut = leftedgeOut + out.w;                    for(kOut=leftedgeOut, kIn=leftedgeIn; kIn<rightedgeIn; 			++kIn, ++kOut) {                                             outdataFloat[kOut] =                             pbox.getEntry(c,(int)dataFloat[0][kIn]+					  shiftValueArray[0])			    -outShiftValueArray[c]; }}                out.progressive = inFloat[0].progressive;                break;                                case DataBlk.TYPE_SHORT:            case DataBlk.TYPE_BYTE:            default:                // Unsupported output type.                 throw new IllegalArgumentException("invalid source datablock"+						   " type"); }        // Initialize the output block geometry and set the profiled        // data into the output block.        out.offset = 0;        out.scanw = out.w;        return out; }     /** Return a suitable String representation of the class instance, e.g.     *  <p>     *  [PalettizedColorSpaceMapper      *    ncomps= 3, scomp= 1, nentries= 1024     *    column=0, 7 bit signed entry     *    column=1, 7 bit unsigned entry     *    column=2, 7 bit signed entry]     *  <p>     **/    public String toString () {        int c;        StringBuffer rep= new StringBuffer("[PalettizedColorSpaceMapper ");

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?