📄 headerdecoder.java
字号:
/* * CVS identifier: * * $Id: HeaderDecoder.java,v 1.40 2001/02/26 11:08:23 grosbois Exp $ * * Class: HeaderDecoder * * Description: Reads main and tile-part headers. * * * * 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.quantization.*;import jj2000.j2k.codestream.*;import jj2000.j2k.wavelet.*;import jj2000.j2k.entropy.*;import jj2000.j2k.decoder.*;import jj2000.j2k.image.*;import jj2000.j2k.util.*;import jj2000.j2k.roi.*;import jj2000.j2k.io.*;import jj2000.j2k.*;import java.io.*;import java.util.*;/** * This class reads Main and Tile-part headers from the codestream. It is * created by the run() method of the Decoder instance. * * <p>A marker segment includes a marker and eventually marker segment * parameters. It is designed by the three letters code of the marker * associated with the marker segment. JPEG 2000 part 1 defines 6 types of * markers: * * <ul> * <li> Delimiting : SOC,SOT (read in FileBitstreamReaderAgent),SOD,EOC * (read in FileBitstreamReaderAgent).</li> <li> Fixed information: SIZ.</li> * * <li> Functional: COD,COC,RGN,QCD,QCC,POC.</li> <li> In bit-stream: * SOP,EPH.</li> * * <li> Pointer: TLM,PLM,PLT,PPM,PPT.</li> * * <li> Informational: CRG,COM.</li> * </ul> * * <p>The main header is read when the constructor is called whereas tile-part * headers are read when the FileBitstreamReaderAgent instance is created. The * reading is done in 2 passes: * * <ul> * <li>All marker segments are buffered and their corresponding flag is * activated (extractMainMarkSeg and extractTilePartMarkSeg methods).</li> * * <li>Buffered marker segment are analyzed in a logical way and * specifications are stored in appropriate member of DecoderSpecs instance * (readFoundMainMarkSeg and readFoundTilePartMarkSeg methods).</li> * </ul> * * <p>Whenever a marker segment is not recognized a warning message is * displayed and its length parameter is used to skip it. * * @see DecoderSpecs * @see Decoder * @see FileBitstreamReaderAgent * */public class HeaderDecoder implements ProgressionType, Markers, StdEntropyCoderOptions { /** The prefix for header decoder options: 'H' */ public final static char OPT_PREFIX = 'H'; /** The list of parameters that is accepted for quantization. Options * for quantization start with 'Q'. */ private final static String [][] pinfo = null; /** Whether to display header information */ private boolean printHeader = false; /** Current header information in a string */ private String hdStr = ""; /** Whether to print 'INFO' type info */ private boolean printInfo; /** The ParameterList instance of the decoder */ private ParameterList pl; /** The number of tiles within the image */ private int nTiles; /** The number of tile parts per tile */ public int[] nTileParts; /** Used to store which markers have been already read, by using flag * bits. The different markers are marked with XXX_FOUND flags, such as * SIZ_FOUND */ int markersFound = 0; /** Counts number of COC markers found in the header */ private int nCOCmarker=0; /** Counts number of QCC markers found in the header */ private int nQCCmarker=0; /** Counts number of COM markers found in the header */ private int nCOMmarker=0; /** Counts number of RGN markers found in the header */ private int nRGNmarker=0; /** Counts number of PPM markers found in the header */ private int nPPMmarker=0; /** Counts number of PPT markers found in the header */ private int[] nPPTmarker; /** Number of read PPT markers found in the header */ private int nReadPPMmarker=0; /** Number of read PPT markers found in the header */ private int[] nReadPPTmarker; /** Flag bit for SIZ marker segment found */ private static final int SIZ_FOUND = 1; /** Flag bit for COD marker segment found */ private static final int COD_FOUND = 1<<1; /** Flag bit for COC marker segment found */ private static final int COC_FOUND = 1<<2; /** Flag bit for QCD marker segment found */ private static final int QCD_FOUND = 1<<3; /** Flag bit for TLM marker segment found */ private static final int TLM_FOUND = 1<<4; /** Flag bit for PLM marker segment found */ private static final int PLM_FOUND = 1<<5; /** Flag bit for SOT marker segment found */ private static final int SOT_FOUND = 1<<6; /** Flag bit for PLT marker segment found */ private static final int PLT_FOUND = 1<<7; /** Flag bit for QCC marker segment found */ private static final int QCC_FOUND = 1<<8; /** Flag bit for RGN marker segment found */ private static final int RGN_FOUND = 1<<9; /** Flag bit for POC marker segment found */ private static final int POC_FOUND = 1<<10; /** Flag bit for COM marker segment found */ private static final int COM_FOUND = 1<<11; /** Flag bit for SOD marker segment found */ public static final int SOD_FOUND = 1<<13; /** Flag bit for SOD marker segment found */ public static final int PPM_FOUND = 1<<14; /** Flag bit for SOD marker segment found */ public static final int PPT_FOUND = 1<<15; /** Flag bit for CRG marker segment found */ public static final int CRG_FOUND = 1<<16; /** The reset mask for new tiles */ private static final int TILE_RESET = ~(PLM_FOUND|SIZ_FOUND|RGN_FOUND); /** HashTable used to store marker segment byte buffers */ private Hashtable ht = new Hashtable(); /** The total header length, including SOC marker segment, header length * number, and encoded header length */ private int thlen; /** Denotes the capabilities of the codestream (e.g., error-resilience, * ROI, etc.), as found in the SIZ tag. The values are defined in * Markers. */ private int cdstrmCap; /** The image width, in the reference grid */ private int imgW; /** The image height, in the reference grid */ private int imgH; /** The horizontal image origin, with respect to the canvas origin, in the * reference grid */ private int imgOrigX; /** The vertical image origin, with respect to the canvas origin, in the * reference grid */ private int imgOrigY; /** The nominal tile width, in the reference grid */ private int tileW; /** The nominal tile width, in thr reference grid */ private int tileH; /** The horizontal tiling origin, with respect to the canvas origin, in the * reference grid */ private int tilingOrigX; /** The vertical tiling origin, with respect to the canvas origin, in the * reference grid */ private int tilingOrigY; /** The number of components in the image */ private int nComp; /** Downsampling factors along X-axis for each component of the image */ private int compSubsX[]; /** Downsampling factors along Y-axis for each component of the image */ private int compSubsY[]; /** The bit-depth (i.e. precision) for each component, before the multiple * component transform. */ private int origBitDepth[]; /** If the data was originally signed, for each component */ private boolean isOrigSigned[]; /** The horizontal code-block and cell partitioning origin, with respect * to the canvas origin. */ private int partOrigX; /** The vertical code-block and cell partitioning origin, with respect * to the canvas origin. */ private int partOrigY; /** The decoder specifications */ private DecoderSpecs decSpec; /** The boost value used if maxshift was used */ private int[] maxBoost; /** Is the precinct partition used */ boolean precinctPartitionIsUsed; /** The starting position of the codestream in the file */ public int initPos; /** Vector containing info as to which tile each tilepart belong */ public Vector tileOfTileParts; /** The packed packet headers if the PPM markers are used */ private Vector unsortedPkdPktHeaders; /** The packed packet headers if the PPM or PPT markers are used */ private ByteArrayOutputStream[] pkdPktHeaders; /** The remaining Ippm data to read */ private int remPPMData; /** The last non-finished Ippm field read */ private byte[] readIPPMData; /** The length of the packed packet headers for each tile part */ private Vector[] tilePartPktHeadLen; /** The last tile part that was read for each tile */ private int[] lastTilePartRead; /** * Returns the total header length, including the magic number, header * length number and encoded header length. * * @return The total header length. * */ public final int getTotalHeaderLength() { return thlen; } /** * Returns the codestream capabilities, as defined in the 'Markers' * interface. These capabilities are flag bits, the different flags are * defined in 'Markers' as constants with the 'RSIZ' prefix. * * @return The codestream capabilities * * @see Markers * */ public final int getCodeStreamCaps() { return cdstrmCap; } /** * Returns the image width, in the reference grid. * * @return The image width in the reference grid * */ public final int getImgWidth() { return imgW; } /** * Returns the image height, in the reference grid. * * @return The image height in the reference grid * */ public final int getImgHeight() { return imgH; } /** * Return the horizontal coordinate of the image origin with respect to * the canvas one, in the reference grid. * * @return The horizontal coordinate of the image origin. * */ public final int getImgULX() { return imgOrigX; } /** * Return the vertical coordinate of the image origin with respect to the * canvas one, in the reference grid. * * @return The vertical coordinate of the image origin. * */ public final int getImgULY() { return imgOrigY; } /** * Returns the nominal width of the tiles in the reference grid. * * @return The nominal tile width, in the reference grid. * */ public final int getNomTileWidth() { return tileW; } /** * Returns the nominal width of the tiles in the reference grid. * * @return The nominal tile width, in the reference grid.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -