001/* 002 * $RCSfile: DataBlk.java,v $ 003 * $Revision: 1.1 $ 004 * $Date: 2005/02/11 05:02:12 $ 005 * $State: Exp $ 006 * 007 * Interface: DataBlk 008 * 009 * Description: A generic interface to hold 2D blocks of 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 * 044 * 045 * 046 */ 047 048package jj2000.j2k.image; 049 050/** 051 * This is a generic abstract class to store data from a block of an 052 * image. This class does not have the notion of components. Therefore, it 053 * should be used for data from a single component. Subclasses should 054 * implement the different types of storage (<tt>int</tt>, 055 * <tt>float</tt>, etc.). 056 * 057 * <P>The data is always stored in one array, of the type matching the data 058 * type (i.e. for 'int' it's an 'int[]'). The data should be stored in the 059 * array in standard scan-line order. That is the samples go from the top-left 060 * corner of the code-block to the lower-right corner by line and then column. 061 * 062 * <P>The member variable 'offset' gives the index in the array of the first 063 * data element (i.e. the top-left coefficient (ulx,uly)). The member variable 064 * 'scanw' gives the width of the scan that is used to store the data, that 065 * can be different from the width of the block. Element '(x,y)' of the 066 * code-block (i.e. '(ulx,uly)' is the top-left coefficient), will appear at 067 * position 'offset+(y-uly)*scanw+(x-ulx)' in the array of data. 068 * 069 * <P>A block of data can have the <i>progressive</i> attribute 070 * set. Data is progressive when it is obtained by successive 071 * refinement and the values in this block are approximations of the 072 * "final" values. When the final values are returned the progressive 073 * attribute must be turned off. 074 * 075 * <P>The classes <tt>DataBlkInt</tt> and <tt>DataBlkFloat</tt> 076 * provide implementations for <tt>int</tt> and <tt>float</tt> types 077 * respectively. 078 * 079 * @see DataBlkInt 080 * 081 * @see DataBlkFloat 082 * */ 083public abstract class DataBlk { 084 085 /** The identifier for the <tt>byte</tt> data type, as signed 8 086 bits. */ 087 public final static int TYPE_BYTE = 0; 088 089 /** The identifier for the <tt>short</tt> data type, as signed 16 090 bits. */ 091 public final static int TYPE_SHORT = 1; 092 093 /** The identifier for the <tt>int</tt> data type, as signed 32 094 bits. */ 095 public final static int TYPE_INT = 3; 096 097 /** The identifier for the <tt>float</tt> data type */ 098 public final static int TYPE_FLOAT = 4; 099 100 /** The horizontal coordinate (in pixels) of the upper-left corner 101 * of the block of data. This is relative to the component of the 102 * image from where this block was filled or is to be filled. 103 */ 104 public int ulx; 105 106 /** The vertical coordinate of the upper-left corner of the block 107 * of data. This is relative to the component of the image from where 108 * this block was filled or is to be filled. 109 */ 110 public int uly; 111 112 /** The width of the block, in pixels. */ 113 public int w; 114 115 /** The height of the block, in pixels. */ 116 public int h; 117 118 /** The offset in the array of the top-left coefficient */ 119 public int offset; 120 121 /** The width of the scanlines used to store the data in the array */ 122 public int scanw; 123 124 /** The progressive attribute (<tt>false</tt> by default) */ 125 public boolean progressive; 126 127 /** 128 * Returns the size in bits, given the data type. The data type 129 * must be one defined in this class. An 130 * <tt>IllegalArgumentException</tt> is thrown if <tt>type</tt> is 131 * not defined in this class. 132 * 133 * @param type The data type. 134 * 135 * @return The size in bits of the data type. 136 * 137 * 138 * 139 */ 140 public static int getSize(int type) { 141 switch (type) { 142 case TYPE_BYTE: 143 return 8; 144 case TYPE_SHORT: 145 return 16; 146 case TYPE_INT: 147 case TYPE_FLOAT: 148 return 32; 149 default: 150 throw new IllegalArgumentException(); 151 } 152 } 153 154 /** 155 * Returns the data type of the <tt>DataBlk</tt> object, as 156 * defined in this class. 157 * 158 * @return The data type of the object, as defined in thsi class. 159 * 160 * 161 * 162 */ 163 public abstract int getDataType(); 164 165 /** 166 * Returns the array containing the data, or null if there is no 167 * data. The returned array is of the type returned by 168 * <tt>getDataType()</tt> (e.g., for <tt>TYPE_INT</tt>, it is a 169 * <tt>int[]</tt>). 170 * 171 * <P>Each implementing class should provide a type specific 172 * equivalent method (e.g., <tt>getDataInt()</tt> in 173 * <tt>DataBlkInt</tt>) which returns an array of the correct 174 * type explicetely and not through an <tt>Object</tt>. 175 * 176 * @return The array containing the data, or <tt>null</tt> if 177 * there is no data. 178 * 179 * 180 * 181 * @see #getDataType 182 * 183 */ 184 public abstract Object getData(); 185 186 /** 187 * Sets the data array to the specified one. The type of the 188 * specified data array must match the one returned by 189 * <tt>getDataType()</tt> (e.g., for <tt>TYPE_INT</tt>, it should 190 * be a <tt>int[]</tt>). If the wrong type of array is given a 191 * <tt>ClassCastException</tt> will be thrown. 192 * 193 * <P>The size of the array is not necessarily checked for 194 * consistency with <tt>w</tt> and <tt>h</tt> or any other fields. 195 * 196 * <P>Each implementing class should provide a type specific 197 * equivalent method (e.g., <tt>setDataInt()</tt> in 198 * <tt>DataBlkInt</tt>) which takes an array of the correct 199 * type explicetely and not through an <tt>Object</tt>. 200 * 201 * @param arr The new data array to use 202 * 203 * 204 * 205 * @see #getDataType 206 * */ 207 public abstract void setData(Object arr); 208 209 /** 210 * Returns a string of informations about the DataBlk 211 * 212 * @return Block dimensions and progressiveness in a string 213 * 214 * 215 */ 216 public String toString(){ 217 String typeString = ""; 218 switch(getDataType()){ 219 case TYPE_BYTE: 220 typeString = "Unsigned Byte"; 221 break; 222 case TYPE_SHORT: 223 typeString = "Short"; 224 break; 225 case TYPE_INT: 226 typeString = "Integer"; 227 break; 228 case TYPE_FLOAT: 229 typeString = "Float"; 230 break; 231 } 232 233 return 234 "DataBlk: "+ 235 "upper-left("+ulx+","+uly+"), width= "+w+ 236 ", height= "+h+", progressive= "+progressive+ 237 ", offset= "+offset+", scanw= "+scanw+ 238 ", type= "+typeString; 239 } 240}