📄 pktdecoder.java
字号:
/* * CVS identifier: * * $Id: PktDecoder.java,v 1.29 2001/03/02 10:09:45 grosbois Exp $ * * Class: PktDecoder * * Description: Reads packets heads and keeps location of * code-blocks' codewords * * * * COPYRIGHT: * * This software module was originally developed by Rapha雔 Grosbois and * Diego Santa Cruz (Swiss Federal Institute of Technology-EPFL); Joel * Askel鰂 (Ericsson Radio Systems AB); and Bertrand Berthelot, David * Bouchard, F閘ix Henry, Gerard Mozelle and Patrice Onno (Canon Research * Centre France S.A) in the course of development of the JPEG2000 * standard as specified by ISO/IEC 15444 (JPEG 2000 Standard). This * software module is an implementation of a part of the JPEG 2000 * Standard. Swiss Federal Institute of Technology-EPFL, Ericsson Radio * Systems AB and Canon Research Centre France S.A (collectively JJ2000 * Partners) agree not to assert against ISO/IEC and users of the JPEG * 2000 Standard (Users) any of their rights under the copyright, not * including other intellectual property rights, for this software module * with respect to the usage by ISO/IEC and Users of this software module * or modifications thereof for use in hardware or software products * claiming conformance to the JPEG 2000 Standard. Those intending to use * this software module in hardware or software products are advised that * their use may infringe existing patents. The original developers of * this software module, JJ2000 Partners and ISO/IEC assume no liability * for use of this software module or modifications thereof. No license * or right to this software module is granted for non JPEG 2000 Standard * conforming products. JJ2000 Partners have full right to use this * software module for his/her own purpose, assign or donate this * software module to any third party and to inhibit third parties from * using this software module for non JPEG 2000 Standard conforming * products. This copyright notice must be included in all copies or * derivative works of this software module. * * Copyright (c) 1999/2000 JJ2000 Partners. * */package jj2000.j2k.codestream.reader;import jj2000.j2k.wavelet.synthesis.*;import jj2000.j2k.codestream.*;import jj2000.j2k.entropy.*;import jj2000.j2k.wavelet.*;import jj2000.j2k.decoder.*;import jj2000.j2k.image.*;import jj2000.j2k.util.*;import jj2000.j2k.io.*;import java.util.*;import java.io.*;/** * This class is used to read packet's head and body. All the members must be * re-initialized at the beginning of each tile thanks to the restart() * method. * */public class PktDecoder implements StdEntropyCoderOptions{ /** Reference to the codestream reader agent */ private FileBitstreamReaderAgent src; /** Flag indicating whether packed packet header was used for this tile*/ private boolean pph=false; /** The packed packet header if it was used */ private ByteArrayInputStream pphbais; /** Reference to decoder specifications */ private DecoderSpecs decSpec; /** Reference to the HeaderDecoder */ private HeaderDecoder hd; /** Initial value of the state variable associated with code-block * length. */ private final int INIT_LBLOCK = 3; /** The wrapper to read bits for the packet heads */ private PktHeaderBitReader bin; /** Reference to the stream where to read from */ private RandomAccessIO ehs; /** * Maximum number of precincts : * * <ul> * <li> 1st dim: component index.</li> * <li> 2nd dim: resolution level index.</li> * </ul> * */ private Coord[][] maxNumPrecincts; /** Index of the current tile */ private int tIdx; /** * Array containing the coordinates, width, height, indexes, ... of the * code-blocks in the current tile. * * <ul> * <li> 1st dim: component index.</li> * <li> 2nd dim: resolution level index.</li> * <li> 3rd dim: subband index.</li> * <li> 4th/5th dim: code-block index (vert. and horiz.).</li> * </ul> * */ private CBlkCoordInfo[][][][][] cbCoord; /** * Array containing the coordinates, width, height, indexes, ... of the * precincts in the current tile: * * <ul> * <li> 1st dim: component index.</li> * <li> 2nd dim: resolution level index.</li> * <li> 3rd dim: subband index.</li> * <li> 4th dim: precinct index.</li> * </ul> * */ private PrecCoordInfo[][][][] precCoord; /** * Lblock value used to read code size information in each packet head: * * <ul> * <li> 1st dim: component index.</li> * <li> 2nd dim: resolution level index.</li> * <li> 3rd dim: subband index.</li> * <li> 4th/5th dim: code-block index (vert. and horiz.).</li> * </ul> * */ private int[][][][][] lblock; /** * Tag tree used to read inclusion informations in packet's head: * * <ul> * <li> 1st dim: component index.</li> * <li> 2nd dim: resolution level index.</li> * <li> 3rd dim: subband index.</li> * <li> 4th dim: precinct index.</li> * */ private TagTreeDecoder[][][][] tdInclA; /** * Tag tree used to read bit-depth information in packet's head: * * <ul> * <li> 1st dim: component index.</li> * <li> 2nd dim: resolution level index.</li> * <li> 3rd dim: subband index.</li> * <li> 4th dim: precinct index.</li> * </ul> * */ private TagTreeDecoder[][][][] tdBDA; /** Number of layers in t he current tile */ private int nl = 0; /** * Keeps the first and the last subband index in the associated component * and resolution level: * * <ul> * <li> 1st dim: component index</li> * <li> 2nd dim: resolution level index</li> * <li> 3rd dim: max and min value</li> * </ul> * */ private int[][][] subRange; /** The maximum number of decomposition levels for each component */ private int[] mdl = null; /** The number of components */ private int nc; /** * Array containing the increment step * * <ul> * <li> 1st dim : component index</li> * <li> 2nd dim : resolution level</li> * </ul> * */ private Coord incArray[][]; /** * Array containing the maximum increment step * * <ul> * <li> 1st dim : component index</li> * </ul> * */ private Coord incArrayMax[]; /** * Array used to store the start/end of tile horizontal and vertical * coordinates at each resolution level * * <ul> * <li> 1st dim : component index</li> * <li> 2nd dim : resolution level</li> * <li> 3rd dim : 0, start of tile, 1, end of tile</li> * </ul> * */ private Coord sotEotArray[][][]; /** * Array used to store the start/end of tile horizontal and vertical * coordinates at the highest resolution level using the smallest * increments * * <ul> * <li> 1st dim : component index</li> * <li> 2nd dim : 0, start of tile, 1, end of tile</li> * </ul> * */ private Coord sotEotArrayMax[][]; /** Whether or not SOP marker segment are used */ private boolean sopUsed = false; /** Whether or not EPH marker are used */ private boolean ephUsed = false; /** Index of the current packet in the tile. Used with SOP marker segment*/ private int pktIdx; /** List of code-blocks found in last read packet head (one list * per subband) */ private Vector[] cblks; /** True if truncation mode is used. False if it is parsing mode */ private boolean isTruncMode; /** * Create an empty PktDecoder object associated with given decoder * specifications and HeaderDecoder. This object must be initialized * thanks to the restart method before being used. * * @param decSpec The decoder specifications * * @param hd The HeaderDecoder instance * * @param ehs The stream where to read data from * * @param src The bit stream reader agent * * @param isTruncMode Whether or not truncation mode is used * */ public PktDecoder(DecoderSpecs decSpec,HeaderDecoder hd, RandomAccessIO ehs, FileBitstreamReaderAgent src,boolean isTruncMode){ this.decSpec = decSpec; this.hd = hd; this.ehs = ehs; this.isTruncMode = isTruncMode; bin = new PktHeaderBitReader(ehs); this.src = src; } /** * Re-initialize the PacketDecoder at the beginning of a new tile. * * @param nc The number of components in this tile * * @param mdl The maximum number of decomposition level in each component * of this tile * * @param nl The number of layers in this tile * * @param cbI The code-blocks array * * @param pph Flag inicating whether packed packet headers was used * * @param pphbais Stream containing the packed packet headers * */ CBlkInfo[][][][][] restart(int nc,int[] mdl,int nl, CBlkInfo[][][][][] cbI, boolean pph, ByteArrayInputStream pphbais){ this.nc = nc; this.nl = nl; this.mdl = mdl; this.tIdx = src.getTileIdx(); this.pph = pph; this.pphbais = pphbais; sopUsed = ((Boolean)decSpec.sops.getTileDef(tIdx)).booleanValue(); pktIdx = 0; ephUsed = ((Boolean)decSpec.ephs.getTileDef(tIdx)).booleanValue(); cbI = new CBlkInfo[nc][][][][]; lblock = new int[nc][][][][]; tdInclA = new TagTreeDecoder[nc][][][]; tdBDA = new TagTreeDecoder[nc][][][]; maxNumPrecincts = new Coord[nc][]; cbCoord = new CBlkCoordInfo[nc][][][][]; precCoord = new PrecCoordInfo[nc][][][]; incArray = new Coord[nc][]; incArrayMax = new Coord[nc]; sotEotArray = new Coord[nc][][]; sotEotArrayMax = new Coord[nc][2]; subRange = findSubInResLvl(); SubbandSyn curSub; int tx0,ty0,tx1,ty1;// Current tile position in the reference grid int tcx0, tcy0, tcx1, tcy1; // Current tile position in the domain of // the image component int trx0, try0, trx1, try1; // Current tile position in the reduced // resolution image domain int xrsiz, yrsiz; // Component sub-sampling factors Coord nBlk = null; for(int c=0; c<nc; c++){ cbI[c] = new CBlkInfo[mdl[c]+1][][][]; lblock[c] = new int[mdl[c]+1][][][]; tdInclA[c] = new TagTreeDecoder[mdl[c]+1][][]; tdBDA[c] = new TagTreeDecoder[mdl[c]+1][][]; maxNumPrecincts[c] = new Coord[mdl[c]+1]; cbCoord[c] = new CBlkCoordInfo[mdl[c]+1][][][]; precCoord[c] = new PrecCoordInfo[mdl[c]+1][][]; sotEotArray[c] = new Coord[mdl[c]+1][2]; incArray[c] = new Coord[mdl[c]+1]; // Get the tile's coordinates on the reference grid tx0 = src.getULX(c,mdl[c]); ty0 = src.getULY(c,mdl[c]); tx1 = tx0 + src.getCompWidth(c,mdl[c]); ty1 = ty0 + src.getCompHeight(c,mdl[c]); // Subsampling factors xrsiz = src.getCompSubsX(c); yrsiz = src.getCompSubsY(c); // Tile's coordinates in the image component domain tcx0 = (int)Math.ceil(tx0/(double)(xrsiz)); tcy0 = (int)Math.ceil(ty0/(double)(yrsiz)); tcx1 = (int)Math.ceil(tx1/(double)(xrsiz)); tcy1 = (int)Math.ceil(ty1/(double)(yrsiz)); buildIncArrays(c); buildSotEotArrays(c); for(int r=0; r<=mdl[c]; r++){ // Tile's coordinates in the reduced resolution image domain trx0 = (int)Math.ceil(tcx0/(double)(1<<(mdl[c]-r))); try0 = (int)Math.ceil(tcy0/(double)(1<<(mdl[c]-r))); trx1 = (int)Math.ceil(tcx1/(double)(1<<(mdl[c]-r))); try1 = (int)Math.ceil(tcy1/(double)(1<<(mdl[c]-r))); cbI[c][r] = new CBlkInfo[subRange[c][r][1]+1][][]; lblock[c][r] = new int[subRange[c][r][1]+1][][]; // Calculate the maximum number of precincts for each // resolution level taking into account tile specific options. double twoppx = (double)getPPX(tIdx,c,r); double twoppy = (double)getPPY(tIdx,c,r); maxNumPrecincts[c][r] = new Coord(); if( trx1>trx0 ) { maxNumPrecincts[c][r].x = (int)Math.ceil(trx1/twoppx) - (int)Math.floor(trx0/twoppx); } if( try1>try0 ) { maxNumPrecincts[c][r].y = (int)Math.ceil(try1/twoppy) - (int)Math.floor(try0/twoppy); } int maxPrec = maxNumPrecincts[c][r].x * maxNumPrecincts[c][r].y; tdInclA[c][r] = new TagTreeDecoder[subRange[c][r][1]+1][maxPrec]; tdBDA[c][r] = new TagTreeDecoder[subRange[c][r][1]+1][maxPrec]; cbCoord[c][r] = new CBlkCoordInfo[subRange[c][r][1]+1][][]; precCoord[c][r] = new PrecCoordInfo[subRange[c][r][1]+1] [maxPrec]; for(int s=subRange[c][r][0];s<=subRange[c][r][1];s++){ curSub = (SubbandSyn)src.getSubbandTree(tIdx,c). getSubbandByIdx(r,s); nBlk = src.getNumCodeBlocks(curSub,c,nBlk); cbI[c][r][s] = new CBlkInfo[nBlk.y][nBlk.x]; cbCoord[c][r][s] = new CBlkCoordInfo[nBlk.y][nBlk.x]; lblock[c][r][s] = new int[nBlk.y][nBlk.x]; for(int i=nBlk.y-1;i>=0;i--) { ArrayUtil.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -