?? stdquantizer.java
字號:
/* * CVS identifier: * * $Id: StdQuantizer.java,v 1.12 2001/01/08 13:28:38 grosbois Exp $ * * Class: StdQuantizer * * Description: Scalar deadzone quantizer of integer or float * data. * * Mergerd from StdQuantizerInt and * StdQuantizerFloat from Joel Askelof. * * * 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.quantization.quantizer;import jj2000.j2k.codestream.writer.*;import jj2000.j2k.wavelet.analysis.*;import jj2000.j2k.quantization.*;import jj2000.j2k.wavelet.*;import jj2000.j2k.encoder.*;import jj2000.j2k.image.*;import jj2000.j2k.*;/** * This class implements scalar quantization of integer or floating-point * valued source data. The source data is the wavelet transformed image data * and the output is the quantized wavelet coefficients represented in * sign-magnitude (see below). * * <P>Sign magnitude representation is used (instead of two's complement) for * the output data. The most significant bit is used for the sign (0 if * positive, 1 if negative). Then the magnitude of the quantized coefficient * is stored in the next M most significat bits. The rest of the bits (least * significant bits) can contain a fractional value of the quantized * coefficient. This fractional value is not to be coded by the entropy * coder. However, it can be used to compute rate-distortion measures with * greater precision. * * <P>The value of M is determined for each subband as the sum of the number * of guard bits G and the nominal range of quantized wavelet coefficients in * the corresponding subband (Rq), minus 1: * * <P>M = G + Rq -1 * * <P>The value of G should be the same for all subbands. The value of Rq * depends on the quantization step size, the nominal range of the component * before the wavelet transform and the analysis gain of the subband (see * Subband). * * <P>The blocks of data that are requested should not cross subband * boundaries. * * @see Subband * * @see Quantizer * */public class StdQuantizer extends Quantizer { /** The number of mantissa bits for the quantization steps */ public final static int QSTEP_MANTISSA_BITS = 11; /** The number of exponent bits for the quantization steps */ // NOTE: formulas in 'convertFromExpMantissa()' and // 'convertToExpMantissa()' methods do not support more than 5 bits. public final static int QSTEP_EXPONENT_BITS = 5; /** The maximum value of the mantissa for the quantization steps */ public final static int QSTEP_MAX_MANTISSA = (1<<QSTEP_MANTISSA_BITS)-1; /** The maximum value of the exponent for the quantization steps */ public final static int QSTEP_MAX_EXPONENT = (1<<QSTEP_EXPONENT_BITS)-1; /** Natural log of 2, used as a convenience variable */ private static double log2 = Math.log(2); /** The quantization type specifications */ private QuantTypeSpec qts; /** The quantization step size specifications */ private QuantStepSizeSpec qsss; /** The guard bits specifications */ private GuardBitsSpec gbs; /** The 'CBlkWTDataFloat' object used to request data, used when * quantizing floating-point data. */ // This variable makes the class thread unsafe, but it avoids allocating // new objects for code-block that is quantized. private CBlkWTDataFloat infblk; /** * Initializes the source of wavelet transform coefficients. The * constructor takes information on whether the quantizer is in * reversible, derived or expounded mode. If the quantizer is reversible * the value of 'derived' is ignored. If the source data is not integer * (int) then the quantizer can not be reversible. * * <P> After initializing member attributes, getSubbandTree is called for * all components setting the 'stepWMSE' for all subbands in the current * tile. * * @param src The source of wavelet transform coefficients. * * @param encSpec The encoder specifications * */ public StdQuantizer(CBlkWTDataSrc src,EncoderSpecs encSpec){ super(src); qts = encSpec.qts; qsss = encSpec.qsss; gbs = encSpec.gbs; } /** * Returns the quantization type spec object associated to the quantizer. * * @return The quantization type spec * */ public QuantTypeSpec getQuantTypeSpec(){ return qts; } /** * Returns the number of guard bits used by this quantizer in the given * tile-component. * * @param t Tile index * * @param c Component index * * @return The number of guard bits * */ public int getNumGuardBits(int t,int c){ return ((Integer)gbs.getTileCompVal(t,c)).intValue(); } /** * Returns the number of code-blocks in a subband, along the horizontal * and vertical dimensions. * * <P>Since the quantizer does not modify the number of code-blocks it * just returns the values obtained by calling the same method on the * source of non-quantized data. * * @param sb The subband for which to return the number of blocks. * * @param co If not null the values are returned in this object. If null a * new object is allocated and returned. * * @return The number of code-blocks along the horizontal dimension in * 'Coord.x' and the number of code-blocks along the vertical dimension in * 'Coord.y'. * */ public Coord getNumCodeBlocks(SubbandAn sb, Coord co) { return src.getNumCodeBlocks(sb,co); } /** * Returns true if the quantized data is reversible, for the specified * tile-component. For the quantized data to be reversible it is necessary * and sufficient that the quantization is reversible. * * @param t The tile to test for reversibility * * @param c The component to test for reversibility * * @return True if the quantized data is reversible, false if not. * */ public boolean isReversible(int t,int c){ return qts.isReversible(t,c); } /** * Returns true if given tile-component uses derived quantization step * sizes. * * @param t Tile index * * @param c Component index * * @return True if derived * */ public boolean isDerived(int t,int c){ return qts.isDerived(t,c); } /** * Returns the next code-block in the current tile for the specified * component, as a copy (see below). The order in which code-blocks are * returned is not specified. However each code-block is returned only * once and all code-blocks will be returned if the method is called 'N' * times, where 'N' is the number of code-blocks in the tile. After all * the code-blocks have been returned for the current tile calls to this * method will return 'null'. * * <P>When changing the current tile (through 'setTile()' or 'nextTile()') * this method will always return the first code-block, as if this method * was never called before for the new current tile. * * <P>The data returned by this method is always a copy of the * data. Therfore it can be modified "in place" without any problems after * being returned. The 'offset' of the returned data is 0, and the 'scanw' * is the same as the code-block width. See the 'CBlkWTData' class. * * <P>The 'ulx' and 'uly' members of the returned 'CBlkWTData' object * contain the coordinates of the top-left corner of the block, with * respect to the tile, not the subband. * * @param c The component for which to return the next code-block. * * @param cblk If non-null this object will be used to return the new * code-block. If null a new one will be allocated and returned. If the * "data" array of the object is non-null it will be reused, if possible, * to return the data. * * @return The next code-block in the current tile for component 'n', or * null if all code-blocks for the current tile have been returned. * * @see CBlkWTData * */ public CBlkWTData getNextCodeBlock(int c,CBlkWTData cblk) { return getNextInternCodeBlock(c,cblk); } /** * Returns the next code-block in the current tile for the specified * component. The order in which code-blocks are returned is not * specified. However each code-block is returned only once and all * code-blocks will be returned if the method is called 'N' times, where * 'N' is the number of code-blocks in the tile. After all the code-blocks * have been returned for the current tile calls to this method will * return 'null'. * * <P>When changing the current tile (through 'setTile()' or 'nextTile()') * this method will always return the first code-block, as if this method * was never called before for the new current tile. * * <P>The data returned by this method can be the data in the internal * buffer of this object, if any, and thus can not be modified by the * caller. The 'offset' and 'scanw' of the returned data can be * arbitrary. See the 'CBlkWTData' class. * * <P>The 'ulx' and 'uly' members of the returned 'CBlkWTData' object * contain the coordinates of the top-left corner of the block, with * respect to the tile, not the subband. * * @param c The component for which to return the next code-block. * * @param cblk If non-null this object will be used to return the new * code-block. If null a new one will be allocated and returned. If the * "data" array of the object is non-null it will be reused, if possible, * to return the data. * * @return The next code-block in the current tile for component 'n', or * null if all code-blocks for the current tile have been returned. * * @see CBlkWTData * */ public final CBlkWTData getNextInternCodeBlock(int c, CBlkWTData cblk) { // NOTE: this method is declared final since getNextCodeBlock() relies // on this particular implementation int k,j; int tmp,shiftBits,jmin; int w,h; int outarr[]; float infarr[] = null; CBlkWTDataFloat infblk; float invstep; // The inverse of the quantization step size boolean intq; // flag for quantizig ints SubbandAn sb; float stepUDR; // The quantization step size (for a dynamic // range of 1, or unit) int g = ((Integer)gbs.getTileCompVal(tIdx,c)).intValue(); // Are we quantizing ints or floats? intq = (src.getDataType(tIdx,c) == DataBlk.TYPE_INT); // Check that we have an output object if (cblk == null) { cblk = new CBlkWTDataInt(); } // Cache input float code-block infblk = this.infblk; // Get data to quantize. When quantizing int data 'cblk' is used to // get the data to quantize and to return the quantized data as well, // that's why 'getNextCodeBlock()' is used. This can not be done when // quantizing float data because of the different data types, that's // why 'getNextInternCodeBlock()' is used in that case. if (intq) { // Source data is int cblk = src.getNextCodeBlock(c,cblk); if (cblk == null) { return null; // No more code-blocks in current tile for comp. }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -