corrade-vassal – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 /*
2 * CVS identifier:
3 *
4 * $Id: ImgWriter.java,v 1.12 2001/09/14 09:13:11 grosbois Exp $
5 *
6 * Class: ImgWriter
7 *
8 * Description: Generic interface for all image writer
9 * classes (to file or other resource)
10 *
11 *
12 *
13 * COPYRIGHT:
14 *
15 * This software module was originally developed by Raphaël Grosbois and
16 * Diego Santa Cruz (Swiss Federal Institute of Technology-EPFL); Joel
17 * Askelöf (Ericsson Radio Systems AB); and Bertrand Berthelot, David
18 * Bouchard, Félix Henry, Gerard Mozelle and Patrice Onno (Canon Research
19 * Centre France S.A) in the course of development of the JPEG2000
20 * standard as specified by ISO/IEC 15444 (JPEG 2000 Standard). This
21 * software module is an implementation of a part of the JPEG 2000
22 * Standard. Swiss Federal Institute of Technology-EPFL, Ericsson Radio
23 * Systems AB and Canon Research Centre France S.A (collectively JJ2000
24 * Partners) agree not to assert against ISO/IEC and users of the JPEG
25 * 2000 Standard (Users) any of their rights under the copyright, not
26 * including other intellectual property rights, for this software module
27 * with respect to the usage by ISO/IEC and Users of this software module
28 * or modifications thereof for use in hardware or software products
29 * claiming conformance to the JPEG 2000 Standard. Those intending to use
30 * this software module in hardware or software products are advised that
31 * their use may infringe existing patents. The original developers of
32 * this software module, JJ2000 Partners and ISO/IEC assume no liability
33 * for use of this software module or modifications thereof. No license
34 * or right to this software module is granted for non JPEG 2000 Standard
35 * conforming products. JJ2000 Partners have full right to use this
36 * software module for his/her own purpose, assign or donate this
37 * software module to any third party and to inhibit third parties from
38 * using this software module for non JPEG 2000 Standard conforming
39 * products. This copyright notice must be included in all copies or
40 * derivative works of this software module.
41 *
42 * Copyright (c) 1999/2000 JJ2000 Partners.
43 * */
44 using System;
45 using CSJ2K.j2k.image;
46 using CSJ2K.j2k.util;
47 using CSJ2K.j2k;
48 namespace CSJ2K.j2k.image.output
49 {
50  
51 /// <summary> This is the generic interface to be implemented by all image file (or other
52 /// resource) writers for different formats.
53 ///
54 /// <p>Each object inheriting from this class should have a source ImgData
55 /// object associated with it. The image data to write to the file is obtained
56 /// from the associated ImgData object. In general this object would be
57 /// specified at construction time.</p>
58 ///
59 /// <p>Depending on the actual type of file that is written a call to any
60 /// write() or writeAll() method will write data from one component, several
61 /// components or all components. For example, a PGM writer will write data
62 /// from only one component (defined in the constructor) while a PPM writer
63 /// will write 3 components (normally R,G,B).</p>
64 ///
65 /// </summary>
66 public abstract class ImgWriter
67 {
68  
69 /// <summary>The defaukt height used when writing strip by strip in the 'write()'
70 /// method. It is 64.
71 /// </summary>
72 public const int DEF_STRIP_HEIGHT = 64;
73  
74 /// <summary>The source ImagaData object, from where to get the image data </summary>
75 protected internal BlkImgDataSrc src;
76  
77 /// <summary>The width of the image </summary>
78 protected internal int w;
79  
80 /// <summary>The height of the image </summary>
81 protected internal int h;
82  
83 /// <summary> Closes the underlying file or netwrok connection to where the data is
84 /// written. The implementing class must write all buffered data before
85 /// closing the file or resource. Any call to other methods of the class
86 /// become illegal after a call to this one.
87 ///
88 /// </summary>
89 /// <exception cref="IOException">If an I/O error occurs.
90 ///
91 /// </exception>
92 public abstract void close();
93  
94 /// <summary> Writes all buffered data to the file or resource. If the implementing
95 /// class does onot use buffering nothing should be done.
96 ///
97 /// </summary>
98 /// <exception cref="IOException">If an I/O error occurs.
99 ///
100 /// </exception>
101 public abstract void flush();
102  
103 /// <summary> Flushes the buffered data before the object is garbage collected. If an
104 /// exception is thrown the object finalization is halted, but is otherwise
105 /// ignored.
106 ///
107 /// </summary>
108 /// <exception cref="IOException">If an I/O error occurs. It halts the
109 /// finalization of the object, but is otherwise ignored.
110 ///
111 /// </exception>
112 /// <seealso cref="Object.finalize">
113 ///
114 /// </seealso>
115 ~ImgWriter()
116 {
117 flush();
118 }
119  
120 /// <summary> Writes the source's current tile to the output. The requests of data
121 /// issued by the implementing class to the source ImgData object should be
122 /// done by blocks or strips, in order to reduce memory usage.
123 ///
124 /// <p>The implementing class should only write data that is not
125 /// "progressive" (in other words that it is final), see DataBlk for
126 /// details.</p>
127 ///
128 /// </summary>
129 /// <exception cref="IOException">If an I/O error occurs.
130 ///
131 /// </exception>
132 /// <seealso cref="DataBlk">
133 ///
134 /// </seealso>
135 public abstract void write();
136  
137 /// <summary> Writes the entire image or only specified tiles to the output. The
138 /// implementation in this class calls the write() method for each tile
139 /// starting with the upper-left one and proceding in standard scanline
140 /// order. It changes the current tile of the source data.
141 ///
142 /// </summary>
143 /// <exception cref="IOException">If an I/O error occurs.
144 ///
145 /// </exception>
146 /// <seealso cref="DataBlk">
147 ///
148 /// </seealso>
149 public virtual void writeAll()
150 {
151 // Find the list of tile to decode.
152 Coord nT = src.getNumTiles(null);
153  
154 // Loop on vertical tiles
155 for (int y = 0; y < nT.y; y++)
156 {
157 // Loop on horizontal tiles
158 for (int x = 0; x < nT.x; x++)
159 {
160 src.setTile(x, y);
161 write();
162 } // End loop on horizontal tiles
163 } // End loop on vertical tiles
164 }
165  
166 /// <summary> Writes the data of the specified area to the file, coordinates are
167 /// relative to the current tile of the source.
168 ///
169 /// <p>The implementing class should only write data that is not
170 /// "progressive" (in other words that is final), see DataBlk for
171 /// details.</p>
172 ///
173 /// </summary>
174 /// <param name="ulx">The horizontal coordinate of the upper-left corner of the
175 /// area to write, relative to the current tile.
176 ///
177 /// </param>
178 /// <param name="uly">The vertical coordinate of the upper-left corner of the area
179 /// to write, relative to the current tile.
180 ///
181 /// </param>
182 /// <param name="width">The width of the area to write.
183 ///
184 /// </param>
185 /// <param name="height">The height of the area to write.
186 ///
187 /// </param>
188 /// <exception cref="IOException">If an I/O error occurs.
189 ///
190 /// </exception>
191 public abstract void write(int ulx, int uly, int w, int h);
192 }
193 }