📄 filebitstreamreaderagent.java
字号:
/* * CVS identifier: * * $Id: FileBitstreamReaderAgent.java,v 1.1.1.1 2002/07/22 09:26:46 grosbois Exp $ * * Class: FileBitstreamReaderAgent * * Description: Retrieve code-blocks codewords in the bit stream * * * * 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.quantization.dequantizer.*;import jj2000.j2k.wavelet.synthesis.*;import jj2000.j2k.entropy.decoder.*;import jj2000.j2k.codestream.*;import jj2000.j2k.decoder.*;import jj2000.j2k.entropy.*;import jj2000.j2k.image.*;import jj2000.j2k.util.*;import jj2000.j2k.io.*;import jj2000.j2k.*;import java.util.*;import java.io.*;/** * This class reads the bit stream (with the help of HeaderDecoder for tile * headers and PktDecoder for packets header and body) and retrives location * of all code-block's codewords. * * <p>Note: All tile-parts headers are read by the constructor whereas packets * are processed when decoding related tile (when setTile method is * called).</p> * * <p>In parsing mode, the reader simulates a virtual layer-resolution * progressive bit stream with the same truncation points in each code-block, * whereas in truncation mode, only the first bytes are taken into account (it * behaves like if it is a real truncated codestream).</p> * * @see HeaderDecoder * @see PktDecoder * */public class FileBitstreamReaderAgent extends BitstreamReaderAgent implements Markers, ProgressionType, StdEntropyCoderOptions { /** Whether or not the last read Psot value was zero. Only the Psot in the * last tile-part in the codestream can have such a value. */ private boolean isPsotEqualsZero = true; /** Reference to the PktDecoder instance */ public PktDecoder pktDec; /** Reference to the ParameterList instance */ private ParameterList pl; /** The RandomAccessIO where to get data from */ private RandomAccessIO in; /** Offset of the first packet in each tile-part in each tile */ private int[][] firstPackOff; /** * Returns the number of tile-part found for a given tile * * @param t Tile index * * */ public int getNumTileParts(int t) { if(firstPackOff==null || firstPackOff[t]==null) { throw new Error("Tile "+t+" not found in input codestream."); } return firstPackOff[t].length; } /** * Number of bytes allocated to each tile. In parsing mode, this number * is related to the tile length in the codestream whereas in truncation * mode all the rate is affected to the first tiles. */ private int[] nBytes; /** Whether or not to print information found in codestream */ private boolean printInfo = false; /** * Backup of the number of bytes allocated to each tile. This array is * used to restore the number of bytes to read in each tile when the * codestream is read several times (for instance when decoding an R,G,B * image to three output files) * */ private int[] baknBytes; /** Length of each tile-part (written in Psot) */ private int[][] tilePartLen; /** Total length of each tile */ private int[] totTileLen; /** Total length of tiles' header */ private int[] totTileHeadLen; /** First tile part header length*/ private int firstTilePartHeadLen; /** Total length of all tile parts in all tiles */ private double totAllTileLen; /** Length of main header */ private int mainHeadLen; /** Length of main and tile-parts headers */ private int headLen = 0; /** Length of all tile-part headers */ private int[][] tilePartHeadLen; /** Length of each packet head found in the tile */ private Vector pktHL; /** True if truncation mode is used. False if parsing mode */ private boolean isTruncMode; /** The number of tile-parts that remain to read */ private int remainingTileParts; /** The number of tile-parts read so far for each tile */ private int[] tilePartsRead; /** Thetotal number of tile-parts read so far */ private int totTilePartsRead=0; /** The number of found tile-parts in each tile. */ private int[] tileParts; /** The current tile part being used */ private int curTilePart; /** The number of the tile-parts found in the codestream after reading the * tp'th tile-part of tile t */ private int[][] tilePartNum; /** Whether or not a EOC marker has been found instead of a SOT */ private boolean isEOCFound = false; /** Reference to the HeaderInfo instance (used when reading SOT marker * segments) */ private HeaderInfo hi; /** Array containing information for all the code-blocks: * * <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 CBlkInfo[][][][][] cbI; /** Gets the reference to the CBlkInfo array */ public CBlkInfo[][][][][] getCBlkInfo() { return cbI; } /** The maximum number of layers to decode for any code-block */ private int lQuit; /** Whether or not to use only first progression order */ private boolean usePOCQuit = false; /** * Reads all tiles headers and keep offset of their first * packet. Finally it calls the rate allocation method. * * @param hd HeaderDecoder of the codestream. * * @param ehs The input stream where to read bit-stream. * * @param decSpec The decoder specifications * * @param pl The ParameterList instance created from the * command-line arguments. * * @param cdstrInfo Whether or not to print information found in * codestream. * * @see #allocateRate * */ public FileBitstreamReaderAgent(HeaderDecoder hd,RandomAccessIO ehs, DecoderSpecs decSpec,ParameterList pl, boolean cdstrInfo,HeaderInfo hi) throws IOException { super(hd,decSpec); this.pl = pl; this.printInfo = cdstrInfo; this.hi = hi; String strInfo = "Codestream elements information in bytes "+ "(offset, total length, header length):\n\n"; // Check whether quit conditiosn used usePOCQuit = pl.getBooleanParameter("poc_quit"); // Get decoding rate boolean rateInBytes; boolean parsing = pl.getBooleanParameter("parsing"); try { trate = pl.getFloatParameter("rate"); if(trate==-1) { trate = Float.MAX_VALUE; } } catch (NumberFormatException e) { throw new Error("Invalid value in 'rate' option: "+ pl.getParameter("rate")); } catch (IllegalArgumentException e) { throw new Error("'rate' option is missing"); } try { tnbytes = pl.getIntParameter("nbytes"); } catch (NumberFormatException e) { throw new Error("Invalid value in 'nbytes' option: "+ pl.getParameter("nbytes")); } catch (IllegalArgumentException e) { throw new Error("'nbytes' option is missing"); } // Check that '-rate' and '-nbytes' are not used at the same time ParameterList defaults = pl.getDefaultParameterList(); if(tnbytes!=defaults.getFloatParameter("nbytes")) { rateInBytes = true; } else { rateInBytes = false; } if(rateInBytes) { trate = tnbytes*8f/hd.getMaxCompImgWidth()/ hd.getMaxCompImgHeight(); } else { tnbytes = (int)(trate*hd.getMaxCompImgWidth()* hd.getMaxCompImgHeight())/8; } isTruncMode = !pl.getBooleanParameter("parsing"); // Check if quit conditions are being used int ncbQuit; try { ncbQuit = pl.getIntParameter("ncb_quit"); } catch (NumberFormatException e) { throw new Error("Invalid value in 'ncb_quit' option: "+ pl.getParameter("ncb_quit")); } catch (IllegalArgumentException e) { throw new Error("'ncb_quit' option is missing"); } if(ncbQuit != -1 && !isTruncMode){ throw new Error("Cannot use -parsing and -ncb_quit condition at "+ "the same time."); } try { lQuit = pl.getIntParameter("l_quit"); } catch (NumberFormatException e) { throw new Error("Invalid value in 'l_quit' option: "+ pl.getParameter("l_quit")); } catch (IllegalArgumentException e) { throw new Error("'l_quit' option is missing"); } // initializations in = ehs; pktDec = new PktDecoder(decSpec,hd,ehs,this,isTruncMode,ncbQuit); tileParts = new int[nt]; totTileLen = new int[nt]; tilePartLen = new int[nt][]; tilePartNum = new int[nt][]; firstPackOff = new int[nt][]; tilePartsRead = new int[nt]; totTileHeadLen = new int[nt]; tilePartHeadLen = new int[nt][]; nBytes = new int[nt]; baknBytes = new int[nt]; hd.nTileParts = new int[nt]; this.isTruncMode = isTruncMode; int t=0, pos, tp=0, tptot=0; // Keeps main header's length, takes file format overhead into account int cdstreamStart = hd.mainHeadOff; // Codestream offset in the file mainHeadLen = in.getPos() - cdstreamStart; headLen = mainHeadLen; // If ncb and lbody quit conditions are used, headers are not counted if(ncbQuit == -1) { anbytes = mainHeadLen; } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -