📄 headerdecoder.java
字号:
* */ public final int getNomTileHeight(){ return tileH; } /** * Returns the tiling origin, refferred to as '(Px,Py)' in the 'ImgData' * interface. * * @param co If not null this object is used to return the information. If * null a new one is created and returned. * * @return The coordinate of the tiling origin, in the canvas system, on * the reference grid. * * @see ImgData * */ public final Coord getTilingOrigin(Coord co) { if (co != null) { co.x = tilingOrigX; co.y = tilingOrigY; return co; } else { return new Coord(tilingOrigX,tilingOrigY); } } /** * Returns true if the original data of the specified component was * signed. If the data was not signed a level shift has to be applied at * the end of the decompression chain. * * @param c The index of the component * * @return True if the original image component was signed. * */ public final boolean isOriginalSigned(int c) { return isOrigSigned[c]; } /** * Returns the original bitdepth of the specified component. * * @param c The index of the component * * @return The bitdepth of the component * */ public final int getOriginalBitDepth(int c) { return origBitDepth[c]; } /** * Returns the number of components in the image. * * @return The number of components in the image. * */ public final int getNumComps() { return nComp; } /** * Returns the component subsampling factor, with respect to the reference * grid,along the horizontal direction for the specified component. * * @param c The index of the component * * @return The component subsampling factor X-wise. * */ public final int getCompSubsX(int c) { return compSubsX[c]; } /** * Returns the component subsampling 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 subsampling factor Y-wise. * */ public final int getCompSubsY(int c) { return compSubsY[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. * * @return The dequantizer * */ public final Dequantizer createDequantizer(CBlkQuantDataSrcDec src, int rb[]) { return new StdDequantizer(src,rb,decSpec); } /** * Returns the horizontal coordinate of the origin of the cell and * code-block partition, with respect to the canvas origin, on the * reference grid. Allowable values are 0 and 1, nothing else. * * @return The horizontal coordinate of the origin of the cell and * code-block partitions, with respect to the canvas origin, on the * reference grid. * */ public final int getPartitionULX() { // NOTE: This will probably make more sense to store it in the wavelet // decomposition spec. return partOrigX; } /** * Returns the vertical coordinate of the origin of the cell and * code-block partition, with respect to the canvas origin, on the * reference grid. Allowable values are 0 and 1, nothing else. * * @return The vertical coordinate of the origin of the cell and * code-block partitions, with respect to the canvas origin, on the * reference grid. * */ public final int getPartitionULY() { // NOTE: This will probably make more sense to store it in the wavelet // decomposition spec. return partOrigY; } /** * Returns the scaling value to use if the maxshift method was specified * * <P>NOTE: All ROI parameters should be grouped in an ROI spec object. * * @return The scaling value to use if the maxshift method was specifiedn * */ public final int[] getMaxBoost(){ return maxBoost; } /** * Returns the precinct partition width for the specified component, tile * and resolution level. * * @param c the component * * @param t the tile index * * @param rl the resolution level * * @return The precinct partition width for the specified component, * tile 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 component, tile * and resolution level. * * @param c the component * * @param t the tile index * * @param rl the resolution level * * @return The precinct partition height for the specified component, * tile 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 * */ private SynWTFilter readFilter(DataInputStream ehs) throws IOException { int kid; // the filter id kid = 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 length is correct. The filler (i.e. "res") byte * is skipped if there is one. If less bytes than the given length * ('mlen') are read a warning is printed and the "useless" bytes are * skipped. If more bytes than the given length ('mlen') have been read * then a 'CorruptedCodestreamException' is thrown. * * @param ehs The encoded header stream * * @param spos The marker start position in 'ehs' * * @param mlen The marker length, as written in the codestream * * @param str The string identifying the marker, such as "SIZ marker" * * @exception CorruptedCodestreamException If too much marker data was * read, according to the given length. * * @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."); } } /** * Read SIZ marker segment, and realign the codestream at the point where * the next marker should be found. It is a fixed information marker * segment containing informations about image and tile sizes. It is * required in the main header immediately after SOC marker segment. * * @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 { int curMarkSegLen; // Store current marker segment length int tmp; // Read the length of SIZ fields (Lsiz) curMarkSegLen = ehs.readUnsignedShort(); // Read the capability of the codestream (Rsiz) cdstrmCap = ehs.readUnsignedShort(); if(cdstrmCap!=0) throw new Error("Codestream capabiities not JPEG 2000 - Part I"+ " compliant"); // Read image size imgW = ehs.readInt(); // Xsiz imgH = ehs.readInt(); // Ysiz if (imgW<=0 || imgH<=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 imgW -= imgOrigX = ehs.readInt(); // XOsiz imgH -= imgOrigY = ehs.readInt(); // Y0siz if (imgOrigX<0 || imgOrigY<0 ) { throw new IOException("JJ2000 does not support images offset "+ "not in the range: 0 -- (2^31)-1"); } // Read size of tile tileW = ehs.readInt(); tileH = ehs.readInt(); if ( tileW<=0 || tileH<=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 tilingOrigX = ehs.readInt(); // XTOsiz tilingOrigY = ehs.readInt(); // YTOsiz if ( tilingOrigX<0 || tilingOrigY<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 = ehs.readUnsignedShort(); if (nComp<1 || nComp>16384) { throw new IllegalArgumentException("Number of component out of "+ "range 1--16384: "+nComp); } origBitDepth = new int[nComp]; isOrigSigned = new boolean[nComp]; compSubsX = new int[nComp]; compSubsY = new int[nComp]; // Read bitdepth and downsampling factors for each component for(int i = 0; i<nComp; i++) { tmp = ehs.readUnsignedByte(); isOrigSigned[i] = ((tmp>>>SSIZ_DEPTH_BITS)==1); origBitDepth[i] = (tmp & ((1<<SSIZ_DEPTH_BITS)-1))+1; if( (origBitDepth[i]+(isOrigSigned[i]?1:0)) > MAX_COMP_BITDEPTH) throw new Error("More than "+MAX_COMP_BITDEPTH+" bit-planes "+ "signalled for component "+i); compSubsX[i] = ehs.readUnsignedByte(); compSubsY[i] = ehs.readUnsignedByte(); } // Check marker length checkMarkerLength(ehs,"SIZ marker"); // Create needed ModuleSpec nTiles = ((imgOrigX+imgW-tilingOrigX+tileW-1) / tileW) * ((imgOrigY+imgH-tilingOrigY+tileH-1) / tileH); // Finish initialization of decSpec decSpec = new DecoderSpecs(nTiles,nComp); if(printInfo){ String info = nComp+" component(s), "+nTiles+" tile(s)\n"; info += "Image dimension: "+imgW+"x"+imgH; if(nTiles!=1) info += "\nNominal Tile dimension: "+tileW+"x"+tileH; FacilityManager.getMsgLogger().printmsg(MsgLogger.INFO,info); } // Store information in hdStr if required if(printHeader){ hdStr += " --- SIZ ---\n"; hdStr += " Capabilities: "+cdstrmCap+"\n"; hdStr += " Image dim. : "+imgW+"x"+imgH+", (off="+imgOrigX+"," +imgOrigY+")\n"; hdStr += " Tile dim. : "+tileW+"x"+tileH+", (off="+tilingOrigX+"," +tilingOrigY+")\n"; hdStr += " Component(s): "+nComp+"\n"; hdStr += " Orig. depth :"; for(int i=0; i<nComp; i++) hdStr += " "+origBitDepth[i]; hdStr += "\n"; hdStr += " Orig. signed:"; for(int i=0; i<nComp; i++) hdStr += " "+isOrigSigned[i]; hdStr += "\n"; hdStr += " Subs. factor:"; for(int i=0; i<nComp; i++) hdStr += " "+compSubsX[i]+","+compSubsY[i]; hdStr += "\n"; } } /** * Reads the CRG marker segment and check segment length * */ private void readCRG(DataInputStream ehs) throws IOException { int curMarkSegLen; // Store the length of the current segment curMarkSegLen = ehs.readUnsignedShort(); FacilityManager.getMsgLogger(). printmsg(MsgLogger.WARNING,"Information in CRG marker segment "+ "not taken into account. This may affect the display "+ "of the decoded image."); ehs.skipBytes(curMarkSegLen-2);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -