001/* 002 * $RCSfile: CBlkWTData.java,v $ 003 * $Revision: 1.1 $ 004 * $Date: 2005/02/11 05:02:30 $ 005 * $State: Exp $ 006 * 007 * Class: CBlkWTData 008 * 009 * Description: Storage for code-blocks of WT data. 010 * 011 * 012 * 013 * COPYRIGHT: 014 * 015 * This software module was originally developed by Raphaël Grosbois and 016 * Diego Santa Cruz (Swiss Federal Institute of Technology-EPFL); Joel 017 * Askelöf (Ericsson Radio Systems AB); and Bertrand Berthelot, David 018 * Bouchard, Félix Henry, Gerard Mozelle and Patrice Onno (Canon Research 019 * Centre France S.A) in the course of development of the JPEG2000 020 * standard as specified by ISO/IEC 15444 (JPEG 2000 Standard). This 021 * software module is an implementation of a part of the JPEG 2000 022 * Standard. Swiss Federal Institute of Technology-EPFL, Ericsson Radio 023 * Systems AB and Canon Research Centre France S.A (collectively JJ2000 024 * Partners) agree not to assert against ISO/IEC and users of the JPEG 025 * 2000 Standard (Users) any of their rights under the copyright, not 026 * including other intellectual property rights, for this software module 027 * with respect to the usage by ISO/IEC and Users of this software module 028 * or modifications thereof for use in hardware or software products 029 * claiming conformance to the JPEG 2000 Standard. Those intending to use 030 * this software module in hardware or software products are advised that 031 * their use may infringe existing patents. The original developers of 032 * this software module, JJ2000 Partners and ISO/IEC assume no liability 033 * for use of this software module or modifications thereof. No license 034 * or right to this software module is granted for non JPEG 2000 Standard 035 * conforming products. JJ2000 Partners have full right to use this 036 * software module for his/her own purpose, assign or donate this 037 * software module to any third party and to inhibit third parties from 038 * using this software module for non JPEG 2000 Standard conforming 039 * products. This copyright notice must be included in all copies or 040 * derivative works of this software module. 041 * 042 * Copyright (c) 1999/2000 JJ2000 Partners. 043 * */ 044package jj2000.j2k.wavelet.analysis; 045 046import jj2000.j2k.image.*; 047 048/** 049 * This is a generic abstract class to store a code-block of wavelet data, be 050 * it quantized or not. This class does not have the notion of 051 * components. Therefore, it should be used for data from a single 052 * component. Subclasses should implement the different types of storage 053 * (<tt>int</tt>, <tt>float</tt>, etc.). 054 * 055 * <P>The data is always stored in one array, of the type matching the data 056 * type (i.e. for 'int' it's an 'int[]'). The data should be stored in the 057 * array in standard scan-line order. That is the samples go from the top-left 058 * corner of the code-block to the lower-right corner by line and then column. 059 * 060 * <P>The member variable 'offset' gives the index in the array of the first 061 * data element (i.e. the top-left coefficient). The member variable 'scanw' 062 * gives the width of the scan that is used to store the data, that can be 063 * different from the width of the block. Element '(x,y)' of the code-block 064 * (i.e. '(0,0)' is the top-left coefficient), will appear at position 065 * 'offset+y*scanw+x' in the array of data. 066 * 067 * <P>The classes <tt>CBlkWTDataInt</tt> and <tt>CBlkWTDataFloat</tt> 068 * provide implementations for <tt>int</tt> and <tt>float</tt> types 069 * respectively. 070 * 071 * <P>The types of data are the same as those defined by the 'DataBlk' class. 072 * 073 * @see CBlkWTDataSrc 074 * 075 * @see jj2000.j2k.quantization.quantizer.CBlkQuantDataSrcEnc 076 * 077 * @see DataBlk 078 * 079 * @see CBlkWTDataInt 080 * 081 * @see CBlkWTDataFloat 082 * */ 083public abstract class CBlkWTData { 084 085 /** The horizontal coordinate of the upper-left corner of the code-block */ 086 public int ulx; 087 088 /** The vertical coordinate of the upper left corner of the code-block */ 089 public int uly; 090 091 /** The horizontal index of the code-block, within the subband */ 092 public int n; 093 094 /** The vertical index of the code-block, within the subband */ 095 public int m; 096 097 /** The subband in which this code-block is found */ 098 public SubbandAn sb; 099 100 /** The width of the code-block */ 101 public int w; 102 103 /** The height of the code-block */ 104 public int h; 105 106 /** The offset in the array of the top-left coefficient */ 107 public int offset; 108 109 /** The width of the scanlines used to store the data in the array */ 110 public int scanw; 111 112 /** The number of magnitude bits in the integer representation. This is 113 * only used for quantized wavelet data. */ 114 public int magbits; 115 116 /** The WMSE scaling factor (multiplicative) to apply to the distortion 117 * measures of the data of this code-block. By default it is 1.*/ 118 public float wmseScaling = 1f; 119 120 /** The value by which the absolute value of the data has to be divided in 121 * order to get the real absolute value. This value is useful to obtain 122 * the complement of 2 representation of a coefficient that is currently 123 * using the sign-magnitude representation. */ 124 public double convertFactor = 1.0; 125 126 /** 127 * The quantization step size of the code-block. The value is updated by 128 * the quantizer module 129 * */ 130 public double stepSize = 1.0; 131 132 /** 133 * Number of ROI coefficients in the code-block 134 * */ 135 public int nROIcoeff = 0; 136 137 /** Number of ROI magnitude bit-planes */ 138 public int nROIbp = 0; 139 140 /** 141 * Returns the data type of the <tt>CBlkWTData</tt> object, as 142 * defined in the DataBlk class. 143 * 144 * @return The data type of the object, as defined in the DataBlk class. 145 * 146 * @see DataBlk 147 * */ 148 public abstract int getDataType(); 149 150 /** 151 * Returns the array containing the data, or null if there is no data. The 152 * returned array is of the type returned by <tt>getDataType()</tt> (e.g., 153 * for <tt>TYPE_INT</tt>, it is a <tt>int[]</tt>). 154 * 155 * <P>Each implementing class should provide a type specific equivalent 156 * method (e.g., <tt>getDataInt()</tt> in <tt>DataBlkInt</tt>) which 157 * returns an array of the correct type explicitely and not through an 158 * <tt>Object</tt>. 159 * 160 * @return The array containing the data, or <tt>null</tt> if there is no 161 * data. 162 * 163 * @see #getDataType 164 * */ 165 public abstract Object getData(); 166 167 /** 168 * Sets the data array to the specified one. The type of the specified 169 * data array must match the one returned by <tt>getDataType()</tt> (e.g., 170 * for <tt>TYPE_INT</tt>, it should be a <tt>int[]</tt>). If the wrong 171 * type of array is given a <tt>ClassCastException</tt> will be thrown. 172 * 173 * <P>The size of the array is not necessarily checked for consistency 174 * with <tt>w</tt> and <tt>h</tt> or any other fields. 175 * 176 * <P>Each implementing class should provide a type specific equivalent 177 * method (e.g., <tt>setDataInt()</tt> in <tt>DataBlkInt</tt>) which takes 178 * an array of the correct type explicetely and not through an 179 * <tt>Object</tt>. 180 * 181 * @param arr The new data array to use 182 * 183 * @see #getDataType 184 * */ 185 public abstract void setData(Object arr); 186 187 /** 188 * Returns a string of informations about the DataBlk 189 * 190 * @return Block dimensions and progressiveness in a string 191 * */ 192 public String toString(){ 193 String typeString = ""; 194 switch(getDataType()){ 195 case DataBlk.TYPE_BYTE: 196 typeString = "Unsigned Byte"; 197 break; 198 case DataBlk.TYPE_SHORT: 199 typeString = "Short"; 200 break; 201 case DataBlk.TYPE_INT: 202 typeString = "Integer"; 203 break; 204 case DataBlk.TYPE_FLOAT: 205 typeString = "Float"; 206 break; 207 } 208 209 return 210 "CBlkWTData: "+ 211 "ulx= " + ulx + ", uly= " + uly + 212 ", code-block("+m+","+n+"), width= "+w+ 213 ", height= "+h+", offset= "+offset+", scan-width="+scanw+ 214 ", type= "+typeString + ", sb= "+sb+", num. ROI coeff="+ 215 nROIcoeff+", num. ROI bit-planes="+nROIbp; 216 } 217}