001/*
002 * $RCSfile: MultiResImgDataAdapter.java,v $
003 * $Revision: 1.1 $
004 * $Date: 2005/02/11 05:02:33 $
005 * $State: Exp $
006 *
007 * Class:                   MultiResImgDataAdapter
008 *
009 * Description:             A default implementation of the MultiResImgData
010 *                          interface that has and MultiResImgData source
011 *                          and just 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.wavelet.synthesis;
052import java.awt.Point;
053import jj2000.j2k.image.*;
054
055/**
056 * This class provides a default implementation for the methods of the
057 * 'MultiResImgData' interface. The default implementation consists just in
058 * returning the value of the source, where the source is another
059 * 'MultiResImgData' object.
060 *
061 * <p>This abstract class can be used to facilitate the development of other
062 * classes that implement 'MultiResImgData'. For example a dequantizer can
063 * inherit from this class and all the trivial methods do not have to be
064 * reimplemented.</p>
065 *
066 * <p>If the default implementation of a method provided in this class does
067 * not suit a particular implementation of the 'MultiResImgData' interface,
068 * the method can be overriden to implement the proper behaviour.</p>
069 *
070 * @see MultiResImgData
071 * */
072public abstract class MultiResImgDataAdapter implements MultiResImgData {
073
074    /** Index of the current tile */
075    protected int tIdx = 0;
076
077    /** The MultiResImgData source */
078    protected MultiResImgData mressrc;
079
080    /**
081     * Instantiates the MultiResImgDataAdapter object specifying the
082     * MultiResImgData source.
083     *
084     * @param src From where to obrtain the MultiResImgData values.
085     * */
086    protected MultiResImgDataAdapter(MultiResImgData src) {
087        mressrc = src;
088    }
089
090    /**
091     * Returns the overall width of the current tile in pixels, for the given
092     * resolution level. This is the tile's width without accounting for any
093     * component subsampling.
094     *
095     * <p>This default implementation returns the value of the source.</p>
096     *
097     * @param rl The resolution level, from 0 to L.
098     *
099     * @return The total current tile's width in pixels.
100     * */
101    public int getTileWidth(int rl) {
102        return mressrc.getTileWidth(rl);
103    }
104
105    /**
106     * Returns the overall height of the current tile in pixels, for the given
107     * resolution level. This is the tile's height without accounting for any
108     * component subsampling.
109     *
110     * <p>This default implementation returns the value of the source.</p>
111     *
112     * @param rl The resolution level, from 0 to L.
113     *
114     * @return The total current tile's height in pixels.
115     * */
116    public int getTileHeight(int rl) {
117        return mressrc.getTileHeight(rl);
118    }
119
120    /** Returns the nominal tiles width */
121    public int getNomTileWidth() {
122        return mressrc.getNomTileWidth();
123    }
124
125    /** Returns the nominal tiles height */
126    public int getNomTileHeight() {
127        return mressrc.getNomTileHeight();
128    }
129
130    /**
131     * Returns the overall width of the image in pixels, for the given
132     * resolution level. This is the image's width without accounting for any
133     * component subsampling or tiling.
134     *
135     * <p>This default implementation returns the value of the source.</p>
136     *
137     * @param rl The resolution level, from 0 to L.
138     *
139     * @return The total image's width in pixels.
140     * */
141    public int getImgWidth(int rl) {
142        return mressrc.getImgWidth(rl);
143    }
144
145    /**
146     * Returns the overall height of the image in pixels, for the given
147     * resolution level. This is the image's height without accounting for any
148     * component subsampling or tiling.
149     *
150     * <p>This default implementation returns the value of the source.</p>
151     *
152     * @param rl The resolution level, from 0 to L.
153     *
154     * @return The total image's height in pixels.
155     * */
156    public int getImgHeight(int rl) {
157        return mressrc.getImgHeight(rl);
158    }
159    
160    /**
161     * Returns the number of components in the image.
162     *
163     * <p>This default implementation returns the value of the source.</p>
164     *
165     * @return The number of components in the image.
166     * */
167    public int getNumComps() {
168        return mressrc.getNumComps();
169    }
170
171    /**
172     * Returns the component subsampling factor in the horizontal direction,
173     * for the specified component. This is, approximately, the ratio of
174     * dimensions between the reference grid and the component itself, see the
175     * 'ImgData' interface desription for details.
176     *
177     * <p>This default implementation returns the value of the source.</p>
178     *
179     * @param c The index of the component (between 0 and N-1)
180     *
181     * @return The horizontal subsampling factor of component 'c'
182     *
183     * @see jj2000.j2k.image.ImgData
184     * */
185    public int getCompSubsX(int c) {
186        return mressrc.getCompSubsX(c);
187    }
188
189    /**
190     * Returns the component subsampling factor in the vertical direction, for
191     * the specified component. This is, approximately, the ratio of
192     * dimensions between the reference grid and the component itself, see the
193     * 'ImgData' interface desription for details.
194     *
195     * <p>This default implementation returns the value of the source.</p>
196     *
197     * @param c The index of the component (between 0 and N-1)
198     *
199     * @return The vertical subsampling factor of component 'c'
200     *
201     * @see jj2000.j2k.image.ImgData
202     * */
203    public int getCompSubsY(int c) {
204        return mressrc.getCompSubsY(c);
205    }
206
207    /**
208     * Returns the width in pixels of the specified tile-component for the
209     * given resolution level.
210     *
211     * <p>This default implementation returns the value of the source.</p>
212     *
213     * @param t Tile index.
214     *
215     * @param c The index of the component, from 0 to N-1.
216     *
217     * @param rl The resolution level, from 0 to L.
218     *
219     * @return The width in pixels of component <tt>c</tt> in tile <tt>t</tt>
220     * for resolution level <tt>rl</tt>.
221     * */
222    public int getTileCompWidth(int t,int c,int rl) {
223        return mressrc.getTileCompWidth(t,c,rl);
224    }
225
226    /**
227     * Returns the height in pixels of the specified tile-component for the
228     * given resolution level.
229     *
230     * <p>This default implementation returns the value of the source.</p>
231     *
232     * @param t The tile index.
233     *
234     * @param c The index of the component, from 0 to N-1.
235     *
236     * @param rl The resolution level, from 0 to L.
237     *
238     * @return The height in pixels of component <tt>c</tt> in tile
239     * <tt>t</tt>. 
240     * */
241    public int getTileCompHeight(int t,int c,int rl) {
242        return mressrc.getTileCompHeight(t,c,rl);
243    }
244
245    /**
246     * Returns the width in pixels of the specified component in the overall
247     * image, for the given resolution level.
248     *
249     * <p>This default implementation returns the value of the source.</p>
250     *
251     * @param c The index of the component, from 0 to N-1.
252     *
253     * @param rl The resolution level, from 0 to L.
254     *
255     * @return The width in pixels of component <tt>c</tt> in the overall
256     * image.
257     * */
258    public int getCompImgWidth(int c,int rl) {
259        return mressrc.getCompImgWidth(c,rl);
260    }
261    
262    /**
263     * Returns the height in pixels of the specified component in the overall
264     * image, for the given resolution level.
265     *
266     * <P>This default implementation returns the value of the source.
267     *
268     * @param c The index of the component, from 0 to N-1.
269     *
270     * @param rl The resolution level, from 0 to L.
271     *
272     * @return The height in pixels of component <tt>c</tt> in the overall
273     * image.
274     * */
275    public int getCompImgHeight(int c,int rl) {
276        return mressrc.getCompImgHeight(c,rl);
277    }
278
279    /**
280     * Changes the current tile, given the new indexes. An
281     * IllegalArgumentException is thrown if the indexes do not correspond to
282     * a valid tile.
283     *
284     * <p>This default implementation just changes the tile in the source.</p>
285     *
286     * @param x The horizontal indexes the tile.
287     *
288     * @param y The vertical indexes of the new tile.
289     * */
290    public void setTile(int x,int y) {
291        mressrc.setTile(x,y);
292        tIdx = getTileIdx();
293    }
294
295    /**
296     * Advances to the next tile, in standard scan-line order (by rows then
297     * columns). An NoNextElementException is thrown if the current tile is
298     * the last one (i.e. there is no next tile).
299     *
300     * <p>This default implementation just changes the tile in the source.</p>
301     * */
302    public void nextTile() {
303        mressrc.nextTile();
304        tIdx = getTileIdx();
305    }
306
307    /**
308     * Returns the indexes of the current tile. These are the horizontal and
309     * vertical indexes of the current tile.
310     *
311     * <p>This default implementation returns the value of the source.</p>
312     *
313     * @param co If not null this object is used to return the information. If
314     * null a new one is created and returned.
315     *
316     * @return The current tile's indexes (vertical and horizontal indexes).
317     * */
318    public Point getTile(Point co) {
319        return mressrc.getTile(co);
320    }
321
322    /**
323     * Returns the index of the current tile, relative to a standard scan-line
324     * order.
325     *
326     * <p>This default implementation returns the value of the source.</p>
327     *
328     * @return The current tile's index (starts at 0).
329     * */
330    public int getTileIdx() {
331        return mressrc.getTileIdx();
332    }
333
334    /**
335     * Returns the horizontal coordinate of the upper-left corner of the
336     * specified resolution level in the given component of the current tile. 
337     *
338     * <p>This default implementation returns the value of the source.</p>
339     *
340     * @param c The component index.
341     *
342     * @param rl The resolution level index.
343     * */
344    public int getResULX(int c,int rl) {
345        return mressrc.getResULX(c,rl);
346    }
347
348    /**
349     * Returns the vertical coordinate of the upper-left corner of the
350     * specified resolution in the given component of the current tile. 
351     *
352     * <p>This default implementation returns the value of the source.</p>
353     *
354     * @param c The component index.
355     *
356     * @param rl The resolution level index.
357     * */
358    public int getResULY(int c,int rl) {
359        return mressrc.getResULY(c,rl);
360    }
361
362    /** Returns the horizontal tile partition offset in the reference grid */
363    public int getTilePartULX() {
364        return mressrc.getTilePartULX();
365    }
366
367    /** Returns the vertical tile partition offset in the reference grid */
368    public int getTilePartULY() {
369        return mressrc.getTilePartULY();
370    }
371
372    /**
373     * Returns the horizontal coordinate of the image origin, the top-left
374     * corner, in the canvas system, on the reference grid at the specified
375     * resolution level.
376     *
377     * <p>This default implementation returns the value of the source.</p>
378     *
379     * @param rl The resolution level, from 0 to L.
380     *
381     * @return The horizontal coordinate of the image origin in the canvas
382     * system, on the reference grid.
383     * */
384    public int getImgULX(int rl) {
385        return mressrc.getImgULX(rl);
386    }
387
388    /**
389     * Returns the vertical coordinate of the image origin, the top-left
390     * corner, in the canvas system, on the reference grid at the specified
391     * resolution level.
392     *
393     * <p>This default implementation returns the value of the source.</p>
394     *
395     * @param rl The resolution level, from 0 to L.
396     *
397     * @return The vertical coordinate of the image origin in the canvas
398     * system, on the reference grid.
399     * */
400    public int getImgULY(int rl) {
401        return mressrc.getImgULY(rl);
402    }
403
404    /**
405     * Returns the number of tiles in the horizontal and vertical directions.
406     *
407     * <p>This default implementation returns the value of the source.</p>
408     *
409     * @param co If not null this object is used to return the information. If
410     * null a new one is created and returned.
411     *
412     * @return The number of tiles in the horizontal (Point.x) and vertical
413     * (Point.y) directions.
414     * */
415    public Point getNumTiles(Point co) {
416        return mressrc.getNumTiles(co);
417    }
418
419    /**
420     * Returns the total number of tiles in the image.
421     *
422     * <p>This default implementation returns the value of the source.</p>
423     *
424     * @return The total number of tiles in the image.
425     * */
426    public int getNumTiles() {
427        return mressrc.getNumTiles();
428    }
429}