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