/* * CVS identifier: * * $Id: Quantizer.java,v 1.38 2002/01/09 13:24:14 grosbois Exp $ * * Class: Quantizer * * Description: An abstract class for quantizers * * * * COPYRIGHT: * * This software module was originally developed by Raphaël Grosbois and * Diego Santa Cruz (Swiss Federal Institute of Technology-EPFL); Joel * Askelöf (Ericsson Radio Systems AB); and Bertrand Berthelot, David * Bouchard, Félix 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. * */ using System; using CSJ2K.j2k.codestream.writer; using CSJ2K.j2k.wavelet.analysis; using CSJ2K.j2k.quantization; using CSJ2K.j2k.wavelet; using CSJ2K.j2k.encoder; using CSJ2K.j2k.image; using CSJ2K.j2k.util; namespace CSJ2K.j2k.quantization.quantizer { /// This abstract class provides the general interface for quantizers. The /// input of a quantizer is the output of a wavelet transform. The output of /// the quantizer is the set of quantized wavelet coefficients represented in /// sign-magnitude notation (see below). /// ///

This class provides default implementation for most of the methods /// (wherever it makes sense), under the assumption that the image, component /// dimensions, and the tiles, are not modifed by the quantizer. If it is not /// the case for a particular implementation, then the methods should be /// overriden.

/// ///

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.

/// ///

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:

/// ///

M = G + Rq -1

/// ///

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).

/// ///

The blocks of data that are requested should not cross subband /// boundaries.

/// ///

NOTE: At the moment only quantizers that implement the /// 'CBlkQuantDataSrcEnc' interface are supported.

/// ///
/// /// /// public abstract class Quantizer:ImgDataAdapter, CBlkQuantDataSrcEnc { /// Returns the horizontal offset of the code-block partition. Allowable /// values are 0 and 1, nothing else. /// /// virtual public int CbULX { get { return src.CbULX; } } /// Returns the vertical offset of the code-block partition. Allowable /// values are 0 and 1, nothing else. /// /// virtual public int CbULY { get { return src.CbULY; } } /// Returns the parameters that are used in this class and implementing /// classes. It returns a 2D String array. Each of the 1D arrays is for a /// different option, and they have 3 elements. The first element is the /// option name, the second one is the synopsis, the third one is a long /// description of what the parameter is and the fourth is its default /// value. The synopsis or description may be 'null', in which case it is /// assumed that there is no synopsis or description of the option, /// respectively. Null may be returned if no options are supported. /// /// /// the options name, their synopsis and their explanation, /// or null if no options are supported. /// /// public static System.String[][] ParameterInfo { get { return pinfo; } } /// The prefix for quantizer options: 'Q' public const char OPT_PREFIX = 'Q'; /// The list of parameters that is accepted for quantization. Options /// for quantization start with 'Q'. /// //UPGRADE_NOTE: Final was removed from the declaration of 'pinfo'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" private static readonly System.String[][] pinfo = new System.String[][]{new System.String[]{"Qtype", "[] " + "[ [] ...]", "Specifies which quantization type to use for specified " + "tile-component. The default type is either 'reversible' or " + "'expounded' depending on whether or not the '-lossless' option " + " is specified.\n" + " : see general note.\n" + ": Supported quantization types specification are : " + "'reversible' " + "(no quantization), 'derived' (derived quantization step size) and " + "'expounded'.\n" + "Example: -Qtype reversible or -Qtype t2,4-8 c2 reversible t9 " + "derived.", null}, new System.String[]{"Qstep", "[] " + "[ [] ...]", "This option specifies the base normalized quantization step " + "size (bnss) for tile-components. It is normalized to a " + "dynamic range of 1 in the image domain. This parameter is " + "ignored in reversible coding. The default value is '1/128'" + " (i.e. 0.0078125).", "0.0078125"}, new System.String[]{"Qguard_bits", "[] " + "[ [] ...]", "The number of bits used for each tile-component in the quantizer" + " to avoid overflow (gb).", "2"}}; /// The source of wavelet transform coefficients protected internal CBlkWTDataSrc src; /// Initializes the source of wavelet transform coefficients. /// /// /// The source of wavelet transform coefficients. /// /// public Quantizer(CBlkWTDataSrc src):base(src) { this.src = src; } /// Returns the number of guard bits used by this quantizer in the /// given tile-component. /// /// /// Tile index /// /// /// Component index /// /// /// The number of guard bits /// /// public abstract int getNumGuardBits(int t, int c); /// Returns true if the quantizer of given tile-component uses derived /// quantization step sizes. /// /// /// Tile index /// /// /// Component index /// /// /// True if derived quantization is used. /// /// public abstract bool isDerived(int t, int c); /// Calculates the parameters of the SubbandAn objects that depend on the /// Quantizer. The 'stepWMSE' field is calculated for each subband which is /// a leaf in the tree rooted at 'sb', for the specified component. The /// subband tree 'sb' must be the one for the component 'n'. /// /// /// The root of the subband tree. /// /// /// The component index. /// /// /// /// /// protected internal abstract void calcSbParams(SubbandAn sb, int n); /// Returns a reference to the subband tree structure representing the /// subband decomposition for the specified tile-component. /// ///

This method gets the subband tree from the source and then /// calculates the magnitude bits for each leaf using the method /// calcSbParams(). /// ///

/// The index of the tile. /// /// /// The index of the component. /// /// /// The subband tree structure, see SubbandAn. /// /// /// /// /// /// /// /// /// /// /// public virtual SubbandAn getAnSubbandTree(int t, int c) { SubbandAn sbba; // Ask for the wavelet tree of the source sbba = src.getAnSubbandTree(t, c); // Calculate the stepWMSE calcSbParams(sbba, c); return sbba; } /// Creates a Quantizer object for the appropriate type of quantization /// specified in the options in the parameter list 'pl', and having 'src' /// as the source of data to be quantized. The 'rev' flag indicates if the /// quantization should be reversible. /// /// NOTE: At the moment only sources of wavelet data that implement the /// 'CBlkWTDataSrc' interface are supported. /// /// /// The source of data to be quantized /// /// /// Encoder specifications /// /// /// If an error occurs while parsing /// the options in 'pl' /// /// public static Quantizer createInstance(CBlkWTDataSrc src, EncoderSpecs encSpec) { // Instantiate quantizer return new StdQuantizer(src, encSpec); } /// Returns the maximum number of magnitude bits in any subband in the /// current tile. /// /// /// the component number /// /// /// The maximum number of magnitude bits in all subbands of the /// current tile. /// /// public abstract int getMaxMagBits(int c); public abstract CSJ2K.j2k.wavelet.analysis.CBlkWTData getNextInternCodeBlock(int param1, CSJ2K.j2k.wavelet.analysis.CBlkWTData param2); public abstract CSJ2K.j2k.wavelet.analysis.CBlkWTData getNextCodeBlock(int param1, CSJ2K.j2k.wavelet.analysis.CBlkWTData param2); public abstract bool isReversible(int param1, int param2); } }