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