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: */
047: package jj2000.j2k.wavelet.synthesis;
048:
049: import java.awt.Point;
050:
051: import jj2000.j2k.decoder.*;
052: import 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: * */
075: public 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(
127: "Resolution level index " + "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)
152: rl = mrl;
153: }
154: return mressrc.getTileWidth(rl);
155: }
156:
157: /**
158: * Returns the overall height of the current tile in pixels. This
159: * is the tile's height without accounting for any component
160: * subsampling. This is also referred as the reference grid height
161: * in the current tile.
162: *
163: * <p>This default implementation returns the value of the source at the
164: * current reconstruction resolution level.</p>
165: *
166: * @return The total current tile's height in pixels.
167: * */
168: public int getTileHeight() {
169: // Retrieves the tile maximum resolution level index and request the
170: // height from the source module.
171: int tIdx = getTileIdx();
172: int rl = 10000;
173: int mrl;
174: int nc = mressrc.getNumComps();
175: for (int c = 0; c < nc; c++) {
176: mrl = mressrc.getSynSubbandTree(tIdx, c).resLvl;
177: if (mrl < rl)
178: rl = mrl;
179: }
180: return mressrc.getTileHeight(rl);
181: }
182:
183: /** Returns the nominal width of tiles */
184: public int getNomTileWidth() {
185: return mressrc.getNomTileWidth();
186: }
187:
188: /** Returns the nominal height of tiles */
189: public int getNomTileHeight() {
190: return mressrc.getNomTileHeight();
191: }
192:
193: /**
194: * Returns the overall width of the image in pixels. This is the
195: * image's width without accounting for any component subsampling
196: * or tiling.
197: *
198: * @return The total image's width in pixels.
199: * */
200: public int getImgWidth() {
201: return mressrc.getImgWidth(reslvl);
202: }
203:
204: /**
205: * Returns the overall height of the image in pixels. This is the
206: * image's height without accounting for any component subsampling
207: * or tiling.
208: *
209: * @return The total image's height in pixels.
210: * */
211: public int getImgHeight() {
212: return mressrc.getImgHeight(reslvl);
213: }
214:
215: /**
216: * Returns the number of components in the image.
217: *
218: * @return The number of components in the image.
219: * */
220: public int getNumComps() {
221: return mressrc.getNumComps();
222: }
223:
224: /**
225: * Returns the component subsampling factor in the horizontal
226: * direction, for the specified component. This is, approximately,
227: * the ratio of dimensions between the reference grid and the
228: * component itself, see the 'ImgData' interface desription for
229: * details.
230: *
231: * @param c The index of the component (between 0 and N-1).
232: *
233: * @return The horizontal subsampling factor of component 'c'.
234: *
235: * @see jj2000.j2k.image.ImgData
236: * */
237: public int getCompSubsX(int c) {
238: return mressrc.getCompSubsX(c);
239: }
240:
241: /**
242: * Returns the component subsampling factor in the vertical
243: * direction, for the specified component. This is, approximately,
244: * the ratio of dimensions between the reference grid and the
245: * component itself, see the 'ImgData' interface desription for
246: * details.
247: *
248: * @param c The index of the component (between 0 and N-1).
249: *
250: * @return The vertical subsampling factor of component 'c'.
251: *
252: * @see jj2000.j2k.image.ImgData
253: * */
254: public int getCompSubsY(int c) {
255: return mressrc.getCompSubsY(c);
256: }
257:
258: /**
259: * Returns the width in pixels of the specified tile-component
260: *
261: * @param t Tile index
262: *
263: * @param c The index of the component, from 0 to N-1.
264: *
265: * @return The width in pixels of component <tt>n</tt> in tile <tt>t</tt>.
266: * */
267: public int getTileCompWidth(int t, int c) {
268: // Retrieves the tile-component maximum resolution index and gets the
269: // width from the source.
270: int rl = mressrc.getSynSubbandTree(t, c).resLvl;
271: return mressrc.getTileCompWidth(t, c, rl);
272: }
273:
274: /**
275: * Returns the height in pixels of the specified tile-component.
276: *
277: * <p>This default implementation returns the value of the source at the
278: * current reconstruction resolution level.</p>
279: *
280: * @param t The tile index.
281: *
282: * @param c The index of the component, from 0 to N-1.
283: *
284: * @return The height in pixels of component <tt>n</tt> in tile
285: * <tt>t</tt>.
286: * */
287: public int getTileCompHeight(int t, int c) {
288: // Retrieves the tile-component maximum resolution index and gets the
289: // height from the source.
290: int rl = mressrc.getSynSubbandTree(t, c).resLvl;
291: return mressrc.getTileCompHeight(t, c, rl);
292: }
293:
294: /**
295: * Returns the width in pixels of the specified component in the overall
296: * image.
297: *
298: * @param c The index of the component, from 0 to N-1.
299: *
300: * @return The width in pixels of component <tt>c</tt> in the overall
301: * image.
302: * */
303: public int getCompImgWidth(int c) {
304: // Retrieves the component maximum resolution index and gets the width
305: // from the source module.
306: int rl = decSpec.dls.getMinInComp(c);
307: return mressrc.getCompImgWidth(c, rl);
308: }
309:
310: /**
311: * Returns the height in pixels of the specified component in the overall
312: * image.
313: *
314: * <p>This default implementation returns the value of the source at the
315: * current reconstruction resolution level.</p>
316: *
317: * @param c The index of the component, from 0 to N-1.
318: *
319: * @return The height in pixels of component <tt>n</tt> in the overall
320: * image.
321: * */
322: public int getCompImgHeight(int c) {
323: // Retrieves the component maximum resolution index and gets the
324: // height from the source module.
325: int rl = decSpec.dls.getMinInComp(c);
326: return mressrc.getCompImgHeight(c, rl);
327: }
328:
329: /**
330: * Changes the current tile, given the new indices. An
331: * IllegalArgumentException is thrown if the coordinates do not correspond
332: * to a valid tile.
333: *
334: * <p>This default implementation calls the same method on the source.</p>
335: *
336: * @param x The horizontal index of the tile.
337: *
338: * @param y The vertical index of the new tile.
339: * */
340: public void setTile(int x, int y) {
341: mressrc.setTile(x, y);
342: }
343:
344: /**
345: * Advances to the next tile, in standard scan-line order (by rows then
346: * columns). An NoNextElementException is thrown if the current tile is
347: * the last one (i.e. there is no next tile).
348: *
349: * <p>This default implementation calls the same method on the source.</p>
350: * */
351: public void nextTile() {
352: mressrc.nextTile();
353: }
354:
355: /**
356: * Returns the indixes of the current tile. These are the horizontal and
357: * vertical indexes of the current tile.
358: *
359: * <p>This default implementation returns the value of the source.</p>
360: *
361: * @param co If not null this object is used to return the information. If
362: * null a new one is created and returned.
363: *
364: * @return The current tile's indices (vertical and horizontal indexes).
365: * */
366: public Point getTile(Point co) {
367: return mressrc.getTile(co);
368: }
369:
370: /**
371: * Returns the index of the current tile, relative to a standard scan-line
372: * order.
373: *
374: * <p>This default implementation returns the value of the source.</p>
375: *
376: * @return The current tile's index (starts at 0).
377: * */
378: public int getTileIdx() {
379: return mressrc.getTileIdx();
380: }
381:
382: /**
383: * Returns the horizontal coordinate of the upper-left corner of the
384: * specified component in the current tile.
385: *
386: * @param c The component index.
387: * */
388: public int getCompULX(int c) {
389: // Find tile-component maximum resolution index and gets information
390: // from the source module.
391: int tIdx = getTileIdx();
392: int rl = mressrc.getSynSubbandTree(tIdx, c).resLvl;
393: return mressrc.getResULX(c, rl);
394: }
395:
396: /**
397: * Returns the vertical coordinate of the upper-left corner of the
398: * specified component in the current tile.
399: *
400: * @param c The component index.
401: * */
402: public int getCompULY(int c) {
403: // Find tile-component maximum resolution index and gets information
404: // from the source module.
405: int tIdx = getTileIdx();
406: int rl = mressrc.getSynSubbandTree(tIdx, c).resLvl;
407: return mressrc.getResULY(c, rl);
408: }
409:
410: /**
411: * Returns the horizontal coordinate of the image origin, the top-left
412: * corner, in the canvas system, on the reference grid.
413: *
414: * <p>This default implementation returns the value of the source at the
415: * current reconstruction resolution level.</p>
416: *
417: * @return The horizontal coordinate of the image origin in the canvas
418: * system, on the reference grid.
419: * */
420: public int getImgULX() {
421: return mressrc.getImgULX(reslvl);
422: }
423:
424: /**
425: * Returns the vertical coordinate of the image origin, the top-left
426: * corner, in the canvas system, on the reference grid.
427: *
428: * <p>This default implementation returns the value of the source at the
429: * current reconstruction resolution level.</p>
430: *
431: * @return The vertical coordinate of the image origin in the canvas
432: * system, on the reference grid.
433: * */
434: public int getImgULY() {
435: return mressrc.getImgULY(reslvl);
436: }
437:
438: /** Returns the horizontal tile partition offset in the reference grid */
439: public int getTilePartULX() {
440: return mressrc.getTilePartULX();
441: }
442:
443: /** Returns the vertical tile partition offset in the reference grid */
444: public int getTilePartULY() {
445: return mressrc.getTilePartULY();
446: }
447:
448: /**
449: * Returns the number of tiles in the horizontal and vertical directions.
450: *
451: * <p>This default implementation returns the value of the source.</p>
452: *
453: * @param co If not null this object is used to return the information. If
454: * null a new one is created and returned.
455: *
456: * @return The number of tiles in the horizontal (Point.x) and vertical
457: * (Point.y) directions.
458: * */
459: public Point getNumTiles(Point co) {
460: return mressrc.getNumTiles(co);
461: }
462:
463: /**
464: * Returns the total number of tiles in the image.
465: *
466: * <p>This default implementation returns the value of the source.</p>
467: *
468: * @return The total number of tiles in the image.
469: * */
470: public int getNumTiles() {
471: return mressrc.getNumTiles();
472: }
473:
474: /**
475: * Returns the specified synthesis subband tree
476: *
477: * @param t Tile index.
478: *
479: * @param c Component index.
480: * */
481: public SubbandSyn getSynSubbandTree(int t, int c) {
482: return mressrc.getSynSubbandTree(t, c);
483: }
484: }
|