001/* 002 * $RCSfile: InvWTAdapter.java,v $ 003 * $Revision: 1.1 $ 004 * $Date: 2005/02/11 05:02:32 $ 005 * $State: Exp $ 006 * 007 * Class: InvWTAdapter 008 * 009 * Description: <short description of class> 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 */ 047package jj2000.j2k.wavelet.synthesis; 048 049import java.awt.Point; 050 051import jj2000.j2k.decoder.*; 052import jj2000.j2k.image.*; 053 054/** 055 * This class provides default implementation of the methods in the 'InvWT' 056 * interface. The source is always a 'MultiResImgData', which is a 057 * multi-resolution image. The default implementation is just to return the 058 * value of the source at the current image resolution level, which is set by 059 * the 'setImgResLevel()' method. 060 * 061 * <p>This abstract class can be used to facilitate the development of other 062 * classes that implement the 'InvWT' interface, because most of the trivial 063 * methods are already implemented.</p> 064 * 065 * <p>If the default implementation of a method provided in this class does 066 * not suit a particular implementation of the 'InvWT' interface, the method 067 * can be overriden to implement the proper behaviour.</p> 068 * 069 * <p>If the 'setImgResLevel()' method is overriden then it is very important 070 * that the one of this class is called from the overriding method, so that 071 * the other methods in this class return the correct values.</p> 072 * 073 * @see InvWT 074 * */ 075public abstract class InvWTAdapter implements InvWT { 076 077 /** The decoder specifications */ 078 protected DecoderSpecs decSpec; 079 080 /** The 'MultiResImgData' source */ 081 protected MultiResImgData mressrc; 082 083 /** The resquested image resolution level for reconstruction. */ 084 protected int reslvl; 085 086 /** The maximum available image resolution level */ 087 protected int maxImgRes; 088 089 /** 090 * Instantiates the 'InvWTAdapter' object using the specified 091 * 'MultiResImgData' source. The reconstruction resolution level is set to 092 * full resolution (i.e. the maximum resolution level). 093 * 094 * @param src From where to obtain the values to return 095 * 096 * @param decSpec The decoder specifications 097 * */ 098 protected InvWTAdapter(MultiResImgData src,DecoderSpecs decSpec) { 099 mressrc = src; 100 this.decSpec = decSpec; 101 maxImgRes = decSpec.dls.getMin(); 102 } 103 104 /** 105 * Sets the image reconstruction resolution level. A value of 0 means 106 * reconstruction of an image with the lowest resolution (dimension) 107 * available. 108 * 109 * <p>Note: Image resolution level indexes may differ from tile-component 110 * resolution index. They are indeed indexed starting from the lowest 111 * number of decomposition levels of each component of each tile.</p> 112 * 113 * <p>Example: For an image (1 tile) with 2 components (component 0 having 114 * 2 decomposition levels and component 1 having 3 decomposition levels), 115 * the first (tile-) component has 3 resolution levels and the second one 116 * has 4 resolution levels, whereas the image has only 3 resolution levels 117 * available.</p> 118 * 119 * @param rl The image resolution level. 120 * 121 * @return The vertical coordinate of the image origin in the canvas 122 * system, on the reference grid. 123 * */ 124 public void setImgResLevel(int rl) { 125 if(rl<0) { 126 throw new IllegalArgumentException("Resolution level index "+ 127 "cannot be negative."); 128 } 129 reslvl = rl; 130 } 131 132 /** 133 * Returns the overall width of the current tile in pixels. This is the 134 * tile's width without accounting for any component subsampling. This is 135 * also referred as the reference grid width in the current tile. 136 * 137 * <p>This default implementation returns the value of the source at the 138 * current reconstruction resolution level.</p> 139 * 140 * @return The total current tile's width in pixels. 141 * */ 142 public int getTileWidth() { 143 // Retrieves the tile maximum resolution level index and request the 144 // width from the source module. 145 int tIdx = getTileIdx(); 146 int rl = 10000; 147 int mrl; 148 int nc = mressrc.getNumComps(); 149 for(int c=0; c<nc; c++) { 150 mrl = mressrc.getSynSubbandTree(tIdx,c).resLvl; 151 if(mrl<rl) rl = mrl; 152 } 153 return mressrc.getTileWidth(rl); 154 } 155 156 /** 157 * Returns the overall height of the current tile in pixels. This 158 * is the tile's height without accounting for any component 159 * subsampling. This is also referred as the reference grid height 160 * in the current tile. 161 * 162 * <p>This default implementation returns the value of the source at the 163 * current reconstruction resolution level.</p> 164 * 165 * @return The total current tile's height in pixels. 166 * */ 167 public int getTileHeight() { 168 // Retrieves the tile maximum resolution level index and request the 169 // height from the source module. 170 int tIdx = getTileIdx(); 171 int rl = 10000; 172 int mrl; 173 int nc = mressrc.getNumComps(); 174 for(int c=0; c<nc; c++) { 175 mrl = mressrc.getSynSubbandTree(tIdx,c).resLvl; 176 if(mrl<rl) rl = mrl; 177 } 178 return mressrc.getTileHeight(rl); 179 } 180 181 /** Returns the nominal width of tiles */ 182 public int getNomTileWidth() { 183 return mressrc.getNomTileWidth(); 184 } 185 186 /** Returns the nominal height of tiles */ 187 public int getNomTileHeight() { 188 return mressrc.getNomTileHeight(); 189 } 190 191 /** 192 * Returns the overall width of the image in pixels. This is the 193 * image's width without accounting for any component subsampling 194 * or tiling. 195 * 196 * @return The total image's width in pixels. 197 * */ 198 public int getImgWidth() { 199 return mressrc.getImgWidth(reslvl); 200 } 201 202 /** 203 * Returns the overall height of the image in pixels. This is the 204 * image's height without accounting for any component subsampling 205 * or tiling. 206 * 207 * @return The total image's height in pixels. 208 * */ 209 public int getImgHeight() { 210 return mressrc.getImgHeight(reslvl); 211 } 212 213 /** 214 * Returns the number of components in the image. 215 * 216 * @return The number of components in the image. 217 * */ 218 public int getNumComps() { 219 return mressrc.getNumComps(); 220 } 221 222 /** 223 * Returns the component subsampling factor in the horizontal 224 * direction, for the specified component. This is, approximately, 225 * the ratio of dimensions between the reference grid and the 226 * component itself, see the 'ImgData' interface desription for 227 * details. 228 * 229 * @param c The index of the component (between 0 and N-1). 230 * 231 * @return The horizontal subsampling factor of component 'c'. 232 * 233 * @see jj2000.j2k.image.ImgData 234 * */ 235 public int getCompSubsX(int c) { 236 return mressrc.getCompSubsX(c); 237 } 238 239 /** 240 * Returns the component subsampling factor in the vertical 241 * direction, for the specified component. This is, approximately, 242 * the ratio of dimensions between the reference grid and the 243 * component itself, see the 'ImgData' interface desription for 244 * details. 245 * 246 * @param c The index of the component (between 0 and N-1). 247 * 248 * @return The vertical subsampling factor of component 'c'. 249 * 250 * @see jj2000.j2k.image.ImgData 251 * */ 252 public int getCompSubsY(int c) { 253 return mressrc.getCompSubsY(c); 254 } 255 256 /** 257 * Returns the width in pixels of the specified tile-component 258 * 259 * @param t Tile index 260 * 261 * @param c The index of the component, from 0 to N-1. 262 * 263 * @return The width in pixels of component <tt>n</tt> in tile <tt>t</tt>. 264 * */ 265 public int getTileCompWidth(int t,int c) { 266 // Retrieves the tile-component maximum resolution index and gets the 267 // width from the source. 268 int rl = mressrc.getSynSubbandTree(t,c).resLvl; 269 return mressrc.getTileCompWidth(t,c,rl); 270 } 271 272 /** 273 * Returns the height in pixels of the specified tile-component. 274 * 275 * <p>This default implementation returns the value of the source at the 276 * current reconstruction resolution level.</p> 277 * 278 * @param t The tile index. 279 * 280 * @param c The index of the component, from 0 to N-1. 281 * 282 * @return The height in pixels of component <tt>n</tt> in tile 283 * <tt>t</tt>. 284 * */ 285 public int getTileCompHeight(int t,int c) { 286 // Retrieves the tile-component maximum resolution index and gets the 287 // height from the source. 288 int rl = mressrc.getSynSubbandTree(t,c).resLvl; 289 return mressrc.getTileCompHeight(t,c,rl); 290 } 291 292 /** 293 * Returns the width in pixels of the specified component in the overall 294 * image. 295 * 296 * @param c The index of the component, from 0 to N-1. 297 * 298 * @return The width in pixels of component <tt>c</tt> in the overall 299 * image. 300 * */ 301 public int getCompImgWidth(int c) { 302 // Retrieves the component maximum resolution index and gets the width 303 // from the source module. 304 int rl = decSpec.dls.getMinInComp(c); 305 return mressrc.getCompImgWidth(c,rl); 306 } 307 308 /** 309 * Returns the height in pixels of the specified component in the overall 310 * image. 311 * 312 * <p>This default implementation returns the value of the source at the 313 * current reconstruction resolution level.</p> 314 * 315 * @param c The index of the component, from 0 to N-1. 316 * 317 * @return The height in pixels of component <tt>n</tt> in the overall 318 * image. 319 * */ 320 public int getCompImgHeight(int c) { 321 // Retrieves the component maximum resolution index and gets the 322 // height from the source module. 323 int rl = decSpec.dls.getMinInComp(c); 324 return mressrc.getCompImgHeight(c,rl); 325 } 326 327 /** 328 * Changes the current tile, given the new indices. An 329 * IllegalArgumentException is thrown if the coordinates do not correspond 330 * to a valid tile. 331 * 332 * <p>This default implementation calls the same method on the source.</p> 333 * 334 * @param x The horizontal index of the tile. 335 * 336 * @param y The vertical index of the new tile. 337 * */ 338 public void setTile(int x, int y) { 339 mressrc.setTile(x,y); 340 } 341 342 /** 343 * Advances to the next tile, in standard scan-line order (by rows then 344 * columns). An NoNextElementException is thrown if the current tile is 345 * the last one (i.e. there is no next tile). 346 * 347 * <p>This default implementation calls the same method on the source.</p> 348 * */ 349 public void nextTile() { 350 mressrc.nextTile(); 351 } 352 353 /** 354 * Returns the indixes of the current tile. These are the horizontal and 355 * vertical indexes of the current tile. 356 * 357 * <p>This default implementation returns the value of the source.</p> 358 * 359 * @param co If not null this object is used to return the information. If 360 * null a new one is created and returned. 361 * 362 * @return The current tile's indices (vertical and horizontal indexes). 363 * */ 364 public Point getTile(Point co) { 365 return mressrc.getTile(co); 366 } 367 368 /** 369 * Returns the index of the current tile, relative to a standard scan-line 370 * order. 371 * 372 * <p>This default implementation returns the value of the source.</p> 373 * 374 * @return The current tile's index (starts at 0). 375 * */ 376 public int getTileIdx() { 377 return mressrc.getTileIdx(); 378 } 379 380 /** 381 * Returns the horizontal coordinate of the upper-left corner of the 382 * specified component in the current tile. 383 * 384 * @param c The component index. 385 * */ 386 public int getCompULX(int c) { 387 // Find tile-component maximum resolution index and gets information 388 // from the source module. 389 int tIdx = getTileIdx(); 390 int rl = mressrc.getSynSubbandTree(tIdx,c).resLvl; 391 return mressrc.getResULX(c,rl); 392 } 393 394 /** 395 * Returns the vertical coordinate of the upper-left corner of the 396 * specified component in the current tile. 397 * 398 * @param c The component index. 399 * */ 400 public int getCompULY(int c) { 401 // Find tile-component maximum resolution index and gets information 402 // from the source module. 403 int tIdx = getTileIdx(); 404 int rl = mressrc.getSynSubbandTree(tIdx,c).resLvl; 405 return mressrc.getResULY(c,rl); 406 } 407 408 /** 409 * Returns the horizontal coordinate of the image origin, the top-left 410 * corner, in the canvas system, on the reference grid. 411 * 412 * <p>This default implementation returns the value of the source at the 413 * current reconstruction resolution level.</p> 414 * 415 * @return The horizontal coordinate of the image origin in the canvas 416 * system, on the reference grid. 417 * */ 418 public int getImgULX() { 419 return mressrc.getImgULX(reslvl); 420 } 421 422 /** 423 * Returns the vertical coordinate of the image origin, the top-left 424 * corner, in the canvas system, on the reference grid. 425 * 426 * <p>This default implementation returns the value of the source at the 427 * current reconstruction resolution level.</p> 428 * 429 * @return The vertical coordinate of the image origin in the canvas 430 * system, on the reference grid. 431 * */ 432 public int getImgULY() { 433 return mressrc.getImgULY(reslvl); 434 } 435 436 /** Returns the horizontal tile partition offset in the reference grid */ 437 public int getTilePartULX() { 438 return mressrc.getTilePartULX(); 439 } 440 441 /** Returns the vertical tile partition offset in the reference grid */ 442 public int getTilePartULY() { 443 return mressrc.getTilePartULY(); 444 } 445 446 /** 447 * Returns the number of tiles in the horizontal and vertical directions. 448 * 449 * <p>This default implementation returns the value of the source.</p> 450 * 451 * @param co If not null this object is used to return the information. If 452 * null a new one is created and returned. 453 * 454 * @return The number of tiles in the horizontal (Point.x) and vertical 455 * (Point.y) directions. 456 * */ 457 public Point getNumTiles(Point co) { 458 return mressrc.getNumTiles(co); 459 } 460 461 /** 462 * Returns the total number of tiles in the image. 463 * 464 * <p>This default implementation returns the value of the source.</p> 465 * 466 * @return The total number of tiles in the image. 467 * */ 468 public int getNumTiles() { 469 return mressrc.getNumTiles(); 470 } 471 472 /** 473 * Returns the specified synthesis subband tree 474 * 475 * @param t Tile index. 476 * 477 * @param c Component index. 478 * */ 479 public SubbandSyn getSynSubbandTree(int t,int c) { 480 return mressrc.getSynSubbandTree(t,c); 481 } 482}