⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 headerdecoder.java

📁 jpeg2000编解码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    /**     * Returns the component sub-sampling factor, with respect to the     * reference grid, along the vertical direction for the specified     * component.     *     * @param c The index of the component     *     * @return The component sub-sampling factor Y-wise.     * */    public final int getCompSubsY(int c) { return hi.siz.yrsiz[c]; }    /**     * Returns the dequantizer parameters. Dequantizer parameters normally are     * the quantization step sizes, see DequantizerParams.     *     * @param src The source of data for the dequantizer.     *     * @param rb The number of range bits for each component. Must be     * the number of range bits of the mixed components.     *     * @param decSpec2 The DecoderSpecs instance after any image manipulation.     *     * @return The dequantizer     * */    public final Dequantizer createDequantizer(CBlkQuantDataSrcDec src,					       int rb[],                                               DecoderSpecs decSpec2) {        return new StdDequantizer(src,rb,decSpec2);    }    /**     * Returns the horizontal code-block partition origin.Allowable values are     * 0 and 1, nothing else.     * */    public final int getCbULX() {        return cb0x;    }    /**     * Returns the vertical code-block partition origin. Allowable values are     * 0 and 1, nothing else.     * */    public final int getCbULY() {        return cb0y;    }    /**     * Returns the precinct partition width for the specified tile-component     * and resolution level.     *     * @param c the component index     *     * @param t the tile index     *     * @param rl the resolution level     *     * @return The precinct partition width for the specified tile-component     * and resolution level     * */    public final int getPPX(int t,int c,int rl) {        return decSpec.pss.getPPX(t,c,rl);    }        /**     * Returns the precinct partition height for the specified tile-component     * and resolution level.     *     * @param c the component index     *     * @param t the tile index     *     * @param rl the resolution level     *     * @return The precinct partition height for the specified tile-component     * and resolution level     * */    public final int getPPY(int t,int c,int rl) {        return decSpec.pss.getPPY(t,c,rl);    }        /**      * Returns the boolean used to know if the precinct partition is used     **/    public final boolean precinctPartitionUsed() {        return precinctPartitionIsUsed;    }    /**     * Reads a wavelet filter from the codestream and returns the filter     * object that implements it.     *     * @param ehs The encoded header stream from where to read the info     *     * @param filtIdx Int array of one element to return the type of the     * wavelet filter.     * */    private SynWTFilter readFilter(DataInputStream ehs,int[] filtIdx)        throws IOException {        int kid; // the filter id        kid = filtIdx[0] = ehs.readUnsignedByte();        if (kid >= (1<<7)) {            throw new NotImplementedError("Custom filters not supported");        }        // Return filter based on ID        switch (kid) {        case FilterTypes.W9X7:            return new SynWTFilterFloatLift9x7();        case FilterTypes.W5X3:            return new SynWTFilterIntLift5x3();        default:            throw new CorruptedCodestreamException("Specified wavelet filter "+						  "not"+                                                  " JPEG 2000 part I "+						  "compliant");        }    }    /**     * Checks that the marker segment length is correct.      *     * @param ehs The encoded header stream     *     * @param str The string identifying the marker, such as "SIZ marker"     *     * @exception IOException If an I/O error occurs     * */    public void checkMarkerLength(DataInputStream ehs, String str) 	throws IOException {        if (ehs.available()!=0) {            FacilityManager.getMsgLogger().                printmsg(MsgLogger.WARNING,                         str+" length was short, attempting to resync.");        }    }    /**     * Reads the SIZ marker segment and realigns the codestream at the point     * where the next marker segment should be found.      *     * <p>SIZ is a fixed information marker segment containing informations     * about image and tile sizes. It is required in the main header     * immediately after SOC.</p>     *     * @param ehs The encoded header stream     *     * @exception IOException If an I/O error occurs while reading from the     * encoded header stream     * */    private void readSIZ (DataInputStream ehs) throws IOException {        HeaderInfo.SIZ ms = hi.getNewSIZ();        hi.siz = ms;	// Read the length of SIZ marker segment (Lsiz)	ms.lsiz = ehs.readUnsignedShort();	// Read the capability of the codestream (Rsiz)	ms.rsiz = ehs.readUnsignedShort();	if (ms.rsiz > 2) {	    throw new Error("Codestream capabiities not JPEG 2000 - Part I"+			    " compliant");        }	// Read image size	ms.xsiz = ehs.readInt();	ms.ysiz = ehs.readInt();        if ( ms.xsiz<=0 || ms.ysiz<=0 ) {            throw new IOException("JJ2000 does not support images whose "+                                  "width and/or height not in the "+                                  "range: 1 -- (2^31)-1");        }		// Read image offset	ms.x0siz = ehs.readInt();	ms.y0siz = ehs.readInt();        if ( ms.x0siz<0 || ms.y0siz<0 ) {            throw new IOException("JJ2000 does not support images offset "+                                  "not in the range: 0 -- (2^31)-1");        }	// Read size of tile	ms.xtsiz = ehs.readInt();        ms.ytsiz = ehs.readInt();        if ( ms.xtsiz<=0 || ms.ytsiz<=0 ) {            throw new IOException("JJ2000 does not support tiles whose "+                                  "width and/or height are not in  "+                                  "the range: 1 -- (2^31)-1");        }	// Read upper-left tile offset	ms.xt0siz = ehs.readInt();	ms.yt0siz = ehs.readInt();        if ( ms.xt0siz<0 || ms.yt0siz<0 ){            throw new IOException("JJ2000 does not support tiles whose "+                                  "offset is not in  "+                                  "the range: 0 -- (2^31)-1");        }	// Read number of components and initialize related arrays      	nComp = ms.csiz = ehs.readUnsignedShort();        if (nComp<1 || nComp>16384) {            throw new IllegalArgumentException("Number of component out of "+                                               "range 1--16384: "+nComp);        }        ms.ssiz = new int[nComp];        ms.xrsiz = new int[nComp];        ms.yrsiz = new int[nComp];	// Read bit-depth and down-sampling factors of each component	for(int i = 0; i<nComp; i++) {	    ms.ssiz[i] = ehs.readUnsignedByte();            ms.xrsiz[i] = ehs.readUnsignedByte();            ms.yrsiz[i] = ehs.readUnsignedByte();        }        // Check marker length        checkMarkerLength(ehs,"SIZ marker");        // Create needed ModuleSpec        nTiles = ms.getNumTiles();        // Finish initialization of decSpec        decSpec = new DecoderSpecs(nTiles,nComp);    }    /**      * Reads a CRG marker segment and checks its length. CRG is an     * informational marker segment that allows specific registration of     * components with respect to each other.     *     * @param ehs The encoded header stream     * */    private void readCRG (DataInputStream ehs) throws IOException {        HeaderInfo.CRG ms = hi.getNewCRG();        hi.crg = ms;        ms.lcrg = ehs.readUnsignedShort();        ms.xcrg = new int[nComp];        ms.ycrg = new int[nComp];                FacilityManager.getMsgLogger().            printmsg(MsgLogger.WARNING,"Information in CRG marker segment "+                     "not taken into account. This may affect the display "+                     "of the decoded image.");        for(int c=0; c<nComp; c++) {            ms.xcrg[c] = ehs.readUnsignedShort();            ms.ycrg[c] = ehs.readUnsignedShort();        }        // Check marker length        checkMarkerLength(ehs,"CRG marker");    }        /**     * Reads a COM marker segments and realigns the bit stream at the point     * where the next marker segment should be found. COM is an informational     * marker segment that allows to include unstructured data in the main and     * tile-part headers.     *     * @param ehs The encoded header stream     *     * @param mainh Flag indicating whether or not this marker segment is read     * from the main header.     *     * @param tileIdx The index of the current tile     *     * @param comIdx Occurence of this COM marker in eith main or tile-part     * header      *      * @exception IOException If an I/O error occurs while reading from the     * encoded header stream     * */    private void readCOM (DataInputStream ehs, boolean mainh, int tileIdx,                           int comIdx) throws IOException {        HeaderInfo.COM ms = hi.getNewCOM();        	// Read length of COM field	ms.lcom = ehs.readUnsignedShort();        	// Read the registration value of the COM marker segment        ms.rcom = ehs.readUnsignedShort();	switch(ms.rcom) {        case RCOM_GEN_USE:            ms.ccom = new byte[ms.lcom-4];            for(int i=0; i<ms.lcom-4; i++) {                ms.ccom[i] = ehs.readByte();            }            break;	default:            // --- Unknown or unsupported markers ---            // (skip them and see if we can get way with it)            FacilityManager.getMsgLogger().                printmsg(MsgLogger.WARNING,                         "COM marker registered as 0x"+Integer.                         toHexString(ms.rcom)+                         " unknown, ignoring (this might crash the "+                         "decoder or decode a quality degraded or even "+                         "useless image)");            ehs.skipBytes(ms.lcom-4); //Ignore this field for the moment	    break;	}        if (mainh) {            hi.com.put("main_"+comIdx,ms);        } else {            hi.com.put("t"+tileIdx+"_"+comIdx,ms);        }                // Check marker length        checkMarkerLength(ehs,"COM marker");    }    /**     * Reads a QCD marker segment and realigns the codestream at the point     * where the next marker should be found. QCD is a functional marker     * segment that describes the quantization default.     *      * @param ehs The encoded stream.     *     * @param mainh Flag indicating whether or not this marker segment is read     * from the main header.     *     * @param tileIdx The index of the current tile     *     * @param tpIdx Tile-part index     *     * @exception IOException If an I/O error occurs while reading from the     * encoded header stream.     * */    private void readQCD (DataInputStream ehs, boolean mainh, int tileIdx,                          int tpIdx) throws IOException {	StdDequantizerParams qParms;        int guardBits;	int[][] exp;	float[][] nStep = null;        HeaderInfo.QCD ms = hi.getNewQCD();		// Lqcd (length of QCD field)	ms.lqcd = ehs.readUnsignedShort();		// Sqcd (quantization style)        ms.sqcd = ehs.readUnsignedByte();		guardBits = ms.getNumGuardBits();	int qType = ms.getQuantType();        if(mainh){            hi.qcd.put("main",ms);            // If the main header is being read set default value of            // dequantization spec            switch (qType) {            case SQCX_NO_QUANTIZATION:                decSpec.qts.setDefault("reversible");                break;            case SQCX_SCALAR_DERIVED:                decSpec.qts.setDefault("derived");                break;            case SQCX_SCALAR_EXPOUNDED:                decSpec.qts.setDefault("expounded");                break;            default:                throw new CorruptedCodestreamException("Unknown or "+                                                       "unsupported "+                                                       "quantization style "+                                                       "in Sqcd field, QCD "+                                                       "marker main header");            }        } else {

⌨️ 快捷键说明

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