001/* 002 * $RCSfile: ImgDataAdapter.java,v $ 003 * $Revision: 1.1 $ 004 * $Date: 2005/02/11 05:02:12 $ 005 * $State: Exp $ 006 * 007 * Class: ImgDataAdapter 008 * 009 * Description: A default implementation of the ImgData 010 * interface that has an ImgData source and just 011 * returns the values of the source. 012 * 013 * 014 * 015 * COPYRIGHT: 016 * 017 * This software module was originally developed by Raphaël Grosbois and 018 * Diego Santa Cruz (Swiss Federal Institute of Technology-EPFL); Joel 019 * Askelöf (Ericsson Radio Systems AB); and Bertrand Berthelot, David 020 * Bouchard, Félix Henry, Gerard Mozelle and Patrice Onno (Canon Research 021 * Centre France S.A) in the course of development of the JPEG2000 022 * standard as specified by ISO/IEC 15444 (JPEG 2000 Standard). This 023 * software module is an implementation of a part of the JPEG 2000 024 * Standard. Swiss Federal Institute of Technology-EPFL, Ericsson Radio 025 * Systems AB and Canon Research Centre France S.A (collectively JJ2000 026 * Partners) agree not to assert against ISO/IEC and users of the JPEG 027 * 2000 Standard (Users) any of their rights under the copyright, not 028 * including other intellectual property rights, for this software module 029 * with respect to the usage by ISO/IEC and Users of this software module 030 * or modifications thereof for use in hardware or software products 031 * claiming conformance to the JPEG 2000 Standard. Those intending to use 032 * this software module in hardware or software products are advised that 033 * their use may infringe existing patents. The original developers of 034 * this software module, JJ2000 Partners and ISO/IEC assume no liability 035 * for use of this software module or modifications thereof. No license 036 * or right to this software module is granted for non JPEG 2000 Standard 037 * conforming products. JJ2000 Partners have full right to use this 038 * software module for his/her own purpose, assign or donate this 039 * software module to any third party and to inhibit third parties from 040 * using this software module for non JPEG 2000 Standard conforming 041 * products. This copyright notice must be included in all copies or 042 * derivative works of this software module. 043 * 044 * Copyright (c) 1999/2000 JJ2000 Partners. 045 * 046 * 047 * 048 */ 049 050 051package jj2000.j2k.image; 052import java.awt.Point; 053 054/** 055 * This class provides a default implementation of the methods in the 056 * 'ImgData' interface. The default implementation is just to return the value 057 * of the source, where the source is another 'ImgData' object. 058 * 059 * <p>This abstract class can be used to facilitate the development of other 060 * classes that implement 'ImgData'. For example a YCbCr color transform can 061 * inherit from this class and all the trivial methods do not have to be 062 * re-implemented.</p> 063 * 064 * <p>If the default implementation of a method provided in this class does 065 * not suit a particular implementation of the 'ImgData' interface, the method 066 * can be overridden to implement the proper behavior.</p> 067 * 068 * @see ImgData 069 * */ 070public abstract class ImgDataAdapter implements ImgData { 071 072 /** Index of the current tile */ 073 protected int tIdx = 0; 074 075 /** The ImgData source */ 076 protected ImgData imgdatasrc; 077 078 /** 079 * Instantiates the ImgDataAdapter object specifying the ImgData source. 080 * 081 * @param src From where to obtain all the ImgData values. 082 * */ 083 protected ImgDataAdapter(ImgData src) { 084 imgdatasrc = src; 085 } 086 087 /** 088 * Returns the overall width of the current tile in pixels. This is the 089 * tile's width without accounting for any component subsampling. This is 090 * also referred as the reference grid width in the current tile. 091 * 092 * <p>This default implementation returns the value of the source.</p> 093 * 094 * @return The total current tile's width in pixels. 095 * */ 096 public int getTileWidth() { 097 return imgdatasrc.getTileWidth(); 098 } 099 100 /** 101 * Returns the overall height of the current tile in pixels. This is the 102 * tile's height without accounting for any component subsampling. This is 103 * also referred as the reference grid height in the current tile. 104 * 105 * <p>This default implementation returns the value of the source.</p> 106 * 107 * @return The total current tile's height in pixels. 108 * */ 109 public int getTileHeight() { 110 return imgdatasrc.getTileHeight(); 111 } 112 113 /** Returns the nominal tiles width */ 114 public int getNomTileWidth() { 115 return imgdatasrc.getNomTileWidth(); 116 } 117 118 /** Returns the nominal tiles height */ 119 public int getNomTileHeight() { 120 return imgdatasrc.getNomTileHeight(); 121 } 122 123 /** 124 * Returns the overall width of the image in pixels. This is the image's 125 * width without accounting for any component subsampling or tiling. 126 * 127 * <p>This default implementation returns the value of the source.</p> 128 * 129 * @return The total image's width in pixels. 130 * */ 131 public int getImgWidth() { 132 return imgdatasrc.getImgWidth(); 133 } 134 135 /** 136 * Returns the overall height of the image in pixels. This is the image's 137 * height without accounting for any component subsampling or tiling. 138 * 139 * <p>This default implementation returns the value of the source.</p> 140 * 141 * @return The total image's height in pixels. 142 * */ 143 public int getImgHeight() { 144 return imgdatasrc.getImgHeight(); 145 } 146 147 /** 148 * Returns the number of components in the image. 149 * 150 * <p>This default implementation returns the value of the source.</p> 151 * 152 * @return The number of components in the image. 153 * */ 154 public int getNumComps() { 155 return imgdatasrc.getNumComps(); 156 } 157 158 /** 159 * Returns the component subsampling factor in the horizontal direction, 160 * for the specified component. This is, approximately, the ratio of 161 * dimensions between the reference grid and the component itself, see the 162 * 'ImgData' interface desription for details. 163 * 164 * <p>This default implementation returns the value of the source.</p> 165 * 166 * @param c The index of the component (between 0 and N-1) 167 * 168 * @return The horizontal subsampling factor of component 'c' 169 * 170 * @see ImgData 171 * */ 172 public int getCompSubsX(int c) { 173 return imgdatasrc.getCompSubsX(c); 174 } 175 176 /** 177 * Returns the component subsampling factor in the vertical direction, for 178 * the specified component. This is, approximately, the ratio of 179 * dimensions between the reference grid and the component itself, see the 180 * 'ImgData' interface desription for details. 181 * 182 * <p>This default implementation returns the value of the source.</p> 183 * 184 * @param c The index of the component (between 0 and N-1) 185 * 186 * @return The vertical subsampling factor of component 'c' 187 * 188 * @see ImgData 189 * */ 190 public int getCompSubsY(int c) { 191 return imgdatasrc.getCompSubsY(c); 192 } 193 194 /** 195 * Returns the width in pixels of the specified tile-component 196 * tile. 197 * 198 * <p>This default implementation returns the value of the source.</p> 199 * 200 * @param t Tile index 201 * 202 * @param c The index of the component, from 0 to N-1. 203 * 204 * @return The width in pixels of component <tt>c</tt> in tile<tt>t</tt>. 205 * */ 206 public int getTileCompWidth(int t,int c) { 207 return imgdatasrc.getTileCompWidth(t,c); 208 } 209 210 /** 211 * Returns the height in pixels of the specified tile-component. 212 * 213 * <p>This default implementation returns the value of the source.</p> 214 * 215 * @param t The tile index. 216 * 217 * @param c The index of the component, from 0 to N-1. 218 * 219 * @return The height in pixels of component <tt>c</tt> in tile 220 * <tt>t</tt>. 221 * */ 222 public int getTileCompHeight(int t,int c) { 223 return imgdatasrc.getTileCompHeight(t,c); 224 } 225 226 /** 227 * Returns the width in pixels of the specified component in the overall 228 * image. 229 * 230 * <p>This default implementation returns the value of the source.</p> 231 * 232 * @param c The index of the component, from 0 to N-1. 233 * 234 * @return The width in pixels of component <tt>c</tt> in the overall 235 * image. 236 * */ 237 public int getCompImgWidth(int c) { 238 return imgdatasrc.getCompImgWidth(c); 239 } 240 241 /** 242 * Returns the height in pixels of the specified component in the overall 243 * image. 244 * 245 * <p>This default implementation returns the value of the source.</p> 246 * 247 * @param c The index of the component, from 0 to N-1. 248 * 249 * @return The height in pixels of component <tt>c</tt> in the overall 250 * image. 251 * */ 252 public int getCompImgHeight(int c) { 253 return imgdatasrc.getCompImgHeight(c); 254 } 255 256 /** 257 * Returns the number of bits, referred to as the "range bits", 258 * corresponding to the nominal range of the image data in the specified 259 * component. If this number is <i>n</b> then for unsigned data the 260 * nominal range is between 0 and 2^b-1, and for signed data it is between 261 * -2^(b-1) and 2^(b-1)-1. In the case of transformed data which is not in 262 * the image domain (e.g., wavelet coefficients), this method returns the 263 * "range bits" of the image data that generated the coefficients. 264 * 265 * <p>This default implementation returns the value of the source.</p> 266 * 267 * @param c The index of the component. 268 * 269 * @return The number of bits corresponding to the nominal range of the 270 * image data (in the image domain). 271 * */ 272 public int getNomRangeBits(int c) { 273 return imgdatasrc.getNomRangeBits(c); 274 } 275 276 /** 277 * Changes the current tile, given the new indexes. An 278 * IllegalArgumentException is thrown if the indexes do not correspond to 279 * a valid tile. 280 * 281 * <p>This default implementation just changes the tile in the source.</p> 282 * 283 * @param x The horizontal index of the tile. 284 * 285 * @param y The vertical index of the new tile. 286 * */ 287 public void setTile(int x, int y) { 288 imgdatasrc.setTile(x,y); 289 tIdx = getTileIdx(); 290 } 291 292 /** 293 * Advances to the next tile, in standard scan-line order (by rows then 294 * columns). An NoNextElementException is thrown if the current tile is 295 * the last one (i.e. there is no next tile). 296 * 297 * <p>This default implementation just advances to the next tile in the 298 * source.</p> 299 * */ 300 public void nextTile() { 301 imgdatasrc.nextTile(); 302 tIdx = getTileIdx(); 303 } 304 305 /** 306 * Returns the indexes of the current tile. These are the horizontal and 307 * vertical indexes of the current tile. 308 * 309 * <p>This default implementation returns the value of the source.</p> 310 * 311 * @param co If not null this object is used to return the information. If 312 * null a new one is created and returned. 313 * 314 * @return The current tile's indexes (vertical and horizontal indexes). 315 * */ 316 public Point getTile(Point co) { 317 return imgdatasrc.getTile(co); 318 } 319 320 /** 321 * Returns the index of the current tile, relative to a standard scan-line 322 * order. 323 * 324 * <p>This default implementation returns the value of the source.</p> 325 * 326 * @return The current tile's index (starts at 0). 327 * */ 328 public int getTileIdx() { 329 return imgdatasrc.getTileIdx(); 330 } 331 332 /** 333 * Returns the horizontal coordinate of the upper-left corner of the 334 * specified component in the current tile. 335 * 336 * <p>This default implementation returns the value of the source.</p> 337 * 338 * @param c The component index. 339 * */ 340 public int getCompULX(int c) { 341 return imgdatasrc.getCompULX(c); 342 } 343 344 /** 345 * Returns the vertical coordinate of the upper-left corner of the 346 * specified component in the current tile. 347 * 348 * <p>This default implementation returns the value of the source.</p> 349 * 350 * @param c The component index. 351 * */ 352 public int getCompULY(int c) { 353 return imgdatasrc.getCompULY(c); 354 } 355 356 /** Returns the horizontal tile partition offset in the reference grid */ 357 public int getTilePartULX() { 358 return imgdatasrc.getTilePartULX(); 359 } 360 361 /** Returns the vertical tile offset in the reference grid */ 362 public int getTilePartULY() { 363 return imgdatasrc.getTilePartULY(); 364 } 365 366 /** 367 * Returns the horizontal coordinate of the image origin, the top-left 368 * corner, in the canvas system, on the reference grid. 369 * 370 * <p>This default implementation returns the value of the source.</p> 371 * 372 * @return The horizontal coordinate of the image origin in the canvas 373 * system, on the reference grid. 374 * */ 375 public int getImgULX() { 376 return imgdatasrc.getImgULX(); 377 } 378 379 /** 380 * Returns the vertical coordinate of the image origin, the top-left 381 * corner, in the canvas system, on the reference grid. 382 * 383 * <p>This default implementation returns the value of the source.</p> 384 * 385 * @return The vertical coordinate of the image origin in the canvas 386 * system, on the reference grid. 387 * */ 388 public int getImgULY() { 389 return imgdatasrc.getImgULY(); 390 } 391 392 /** 393 * Returns the number of tiles in the horizontal and vertical directions. 394 * 395 * <p>This default implementation returns the value of the source.</p> 396 * 397 * @param co If not null this object is used to return the information. If 398 * null a new one is created and returned. 399 * 400 * @return The number of tiles in the horizontal (Point.x) and vertical 401 * (Point.y) directions. 402 * */ 403 public Point getNumTiles(Point co) { 404 return imgdatasrc.getNumTiles(co); 405 } 406 407 /** 408 * Returns the total number of tiles in the image. 409 * 410 * <p>This default implementation returns the value of the source.</p> 411 * 412 * @return The total number of tiles in the image. 413 * */ 414 public int getNumTiles() { 415 return imgdatasrc.getNumTiles(); 416 } 417}