corrade-vassal – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 /*
2 * CVS identifier:
3 *
4 * $Id: ROIDeScaler.java,v 1.39 2001/10/24 12:02:51 grosbois Exp $
5 *
6 *
7 * Class: ROIDeScaler
8 *
9 * Description: The class taking care of de-scaling ROI coeffs.
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.quantization.dequantizer;
46 using CSJ2K.j2k.codestream.reader;
47 using CSJ2K.j2k.wavelet.synthesis;
48 using CSJ2K.j2k.codestream;
49 using CSJ2K.j2k.entropy;
50 using CSJ2K.j2k.decoder;
51 using CSJ2K.j2k.image;
52 using CSJ2K.j2k.util;
53 using CSJ2K.j2k.io;
54 using CSJ2K.j2k;
55 namespace CSJ2K.j2k.roi
56 {
57  
58 /// <summary> This class takes care of the de-scaling of ROI coefficients. The de-scaler
59 /// works on a tile basis and any mask that is generated is for the current
60 /// mask only
61 ///
62 /// <p>Default implementations of the methods in 'MultiResImgData' are provided
63 /// through the 'MultiResImgDataAdapter' abstract class.</p>
64 ///
65 /// <p>Sign-magnitude representation is used (instead of two's complement) for
66 /// the output data. The most significant bit is used for the sign (0 if
67 /// positive, 1 if negative). Then the magnitude of the quantized coefficient
68 /// is stored in the next most significat bits. The most significant magnitude
69 /// bit corresponds to the most significant bit-plane and so on.</p>
70 ///
71 /// </summary>
72 public class ROIDeScaler:MultiResImgDataAdapter, CBlkQuantDataSrcDec
73 {
74 /// <summary> Returns the horizontal code-block partition origin. Allowable values
75 /// are 0 and 1, nothing else.
76 ///
77 /// </summary>
78 virtual public int CbULX
79 {
80 get
81 {
82 return src.CbULX;
83 }
84  
85 }
86 /// <summary> Returns the vertical code-block partition origin. Allowable values are
87 /// 0 and 1, nothing else.
88 ///
89 /// </summary>
90 virtual public int CbULY
91 {
92 get
93 {
94 return src.CbULY;
95 }
96  
97 }
98 /// <summary> Returns the parameters that are used in this class and implementing
99 /// classes. It returns a 2D String array. Each of the 1D arrays is for a
100 /// different option, and they have 3 elements. The first element is the
101 /// option name, the second one is the synopsis and the third one is a long
102 /// description of what the parameter is. The synopsis or description may
103 /// be 'null', in which case it is assumed that there is no synopsis or
104 /// description of the option, respectively. Null may be returned if no
105 /// options are supported.
106 ///
107 /// </summary>
108 /// <returns> the options name, their synopsis and their explanation, or null
109 /// if no options are supported.
110 ///
111 /// </returns>
112 public static System.String[][] ParameterInfo
113 {
114 get
115 {
116 return pinfo;
117 }
118  
119 }
120  
121 /// <summary>The MaxShiftSpec containing the scaling values for all tile-components
122 ///
123 /// </summary>
124 private MaxShiftSpec mss;
125  
126 /// <summary>The prefix for ROI decoder options: 'R' </summary>
127 public const char OPT_PREFIX = 'R';
128  
129 /// <summary>The list of parameters that is accepted by the entropy decoders. They
130 /// start with 'R'.
131 /// </summary>
132 //UPGRADE_NOTE: Final was removed from the declaration of 'pinfo'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
133 private static readonly System.String[][] pinfo = new System.String[][]{new System.String[]{"Rno_roi", null, "This argument makes sure that the no ROI de-scaling is performed. " + "Decompression is done like there is no ROI in the image", null}};
134  
135 /// <summary>The entropy decoder from where to get the compressed data (the source)
136 ///
137 /// </summary>
138 private CBlkQuantDataSrcDec src;
139  
140 /// <summary> Constructor of the ROI descaler, takes EntropyDEcoder as source of data
141 /// to de-scale.
142 ///
143 /// </summary>
144 /// <param name="src">The EntropyDecoder that is the source of data.
145 ///
146 /// </param>
147 /// <param name="mss">The MaxShiftSpec containing the scaling values for all
148 /// tile-components
149 ///
150 /// </param>
151 public ROIDeScaler(CBlkQuantDataSrcDec src, MaxShiftSpec mss):base(src)
152 {
153 this.src = src;
154 this.mss = mss;
155 }
156  
157 /// <summary> Returns the subband tree, for the specified tile-component. This method
158 /// returns the root element of the subband tree structure, see Subband and
159 /// SubbandSyn. The tree comprises all the available resolution levels.
160 ///
161 /// <P>The number of magnitude bits ('magBits' member variable) for each
162 /// subband is not initialized.
163 ///
164 /// </summary>
165 /// <param name="t">The index of the tile, from 0 to T-1.
166 ///
167 /// </param>
168 /// <param name="c">The index of the component, from 0 to C-1.
169 ///
170 /// </param>
171 /// <returns> The root of the tree structure.
172 ///
173 /// </returns>
174 public override SubbandSyn getSynSubbandTree(int t, int c)
175 {
176 return src.getSynSubbandTree(t, c);
177 }
178  
179 /// <summary> Returns the specified code-block in the current tile for the specified
180 /// component, as a copy (see below).
181 ///
182 /// <p>The returned code-block may be progressive, which is indicated by
183 /// the 'progressive' variable of the returned 'DataBlk' object. If a
184 /// code-block is progressive it means that in a later request to this
185 /// method for the same code-block it is possible to retrieve data which is
186 /// a better approximation, since meanwhile more data to decode for the
187 /// code-block could have been received. If the code-block is not
188 /// progressive then later calls to this method for the same code-block
189 /// will return the exact same data values.</p>
190 ///
191 /// <p>The data returned by this method is always a copy of the internal
192 /// data of this object, if any, and it can be modified "in place" without
193 /// any problems after being returned. The 'offset' of the returned data is
194 /// 0, and the 'scanw' is the same as the code-block width. See the
195 /// 'DataBlk' class.</p>
196 ///
197 /// <p>The 'ulx' and 'uly' members of the returned 'DataBlk' object contain
198 /// the coordinates of the top-left corner of the block, with respect to
199 /// the tile, not the subband.</p>
200 ///
201 /// </summary>
202 /// <param name="c">The component for which to return the next code-block.
203 ///
204 /// </param>
205 /// <param name="m">The vertical index of the code-block to return, in the
206 /// specified subband.
207 ///
208 /// </param>
209 /// <param name="n">The horizontal index of the code-block to return, in the
210 /// specified subband.
211 ///
212 /// </param>
213 /// <param name="sb">The subband in which the code-block to return is.
214 ///
215 /// </param>
216 /// <param name="cblk">If non-null this object will be used to return the new
217 /// code-block. If null a new one will be allocated and returned. If the
218 /// "data" array of the object is non-null it will be reused, if possible,
219 /// to return the data.
220 ///
221 /// </param>
222 /// <returns> The next code-block in the current tile for component 'c', or
223 /// null if all code-blocks for the current tile have been returned.
224 ///
225 /// </returns>
226 /// <seealso cref="DataBlk">
227 ///
228 /// </seealso>
229 public virtual DataBlk getCodeBlock(int c, int m, int n, SubbandSyn sb, DataBlk cblk)
230 {
231 return getInternCodeBlock(c, m, n, sb, cblk);
232 }
233  
234 /// <summary> Returns the specified code-block in the current tile for the specified
235 /// component (as a reference or copy).
236 ///
237 /// <p>The returned code-block may be progressive, which is indicated by
238 /// the 'progressive' variable of the returned 'DataBlk' object. If a
239 /// code-block is progressive it means that in a later request to this
240 /// method for the same code-block it is possible to retrieve data which is
241 /// a better approximation, since meanwhile more data to decode for the
242 /// code-block could have been received. If the code-block is not
243 /// progressive then later calls to this method for the same code-block
244 /// will return the exact same data values.</p>
245 ///
246 /// <p>The data returned by this method can be the data in the internal
247 /// buffer of this object, if any, and thus can not be modified by the
248 /// caller. The 'offset' and 'scanw' of the returned data can be
249 /// arbitrary. See the 'DataBlk' class.</p>
250 ///
251 /// <p>The 'ulx' and 'uly' members of the returned 'DataBlk' object contain
252 /// the coordinates of the top-left corner of the block, with respect to
253 /// the tile, not the subband.</p>
254 ///
255 /// </summary>
256 /// <param name="c">The component for which to return the next code-block.
257 ///
258 /// </param>
259 /// <param name="m">The vertical index of the code-block to return, in the
260 /// specified subband.
261 ///
262 /// </param>
263 /// <param name="n">The horizontal index of the code-block to return, in the
264 /// specified subband.
265 ///
266 /// </param>
267 /// <param name="sb">The subband in which the code-block to return is.
268 ///
269 /// </param>
270 /// <param name="cblk">If non-null this object will be used to return the new
271 /// code-block. If null a new one will be allocated and returned. If the
272 /// "data" array of the object is non-null it will be reused, if possible,
273 /// to return the data.
274 ///
275 /// </param>
276 /// <returns> The requested code-block in the current tile for component 'c'.
277 ///
278 /// </returns>
279 /// <seealso cref="DataBlk">
280 ///
281 /// </seealso>
282 public virtual DataBlk getInternCodeBlock(int c, int m, int n, SubbandSyn sb, DataBlk cblk)
283 {
284 int i, j, k, wrap; // mi removed
285 int ulx, uly, w, h;
286 int[] data; // local copy of quantized data
287 int tmp;
288 //int limit;
289  
290 // Get data block from entropy decoder
291 cblk = src.getInternCodeBlock(c, m, n, sb, cblk);
292  
293 // If there are no ROIs in the tile, Or if we already got all blocks
294 bool noRoiInTile = false;
295 if (mss == null || mss.getTileCompVal(TileIdx, c) == null)
296 noRoiInTile = true;
297  
298 if (noRoiInTile || cblk == null)
299 {
300 return cblk;
301 }
302 data = (int[]) cblk.Data;
303 ulx = cblk.ulx;
304 uly = cblk.uly;
305 w = cblk.w;
306 h = cblk.h;
307  
308 // Scale coefficients according to magnitude. If the magnitude of a
309 // coefficient is lower than 2 pow 31-magbits then it is a background
310 // coeff and should be up-scaled
311 int boost = ((System.Int32) mss.getTileCompVal(TileIdx, c));
312 int mask = ((1 << sb.magbits) - 1) << (31 - sb.magbits);
313 int mask2 = (~ mask) & 0x7FFFFFFF;
314  
315 wrap = cblk.scanw - w;
316 i = cblk.offset + cblk.scanw * (h - 1) + w - 1;
317 for (j = h; j > 0; j--)
318 {
319 for (k = w; k > 0; k--, i--)
320 {
321 tmp = data[i];
322 if ((tmp & mask) == 0)
323 {
324 // BG
325 data[i] = (tmp & unchecked((int) 0x80000000)) | (tmp << boost);
326 }
327 else
328 {
329 // ROI
330 if ((tmp & mask2) != 0)
331 {
332 // decoded more than magbits bit-planes, set
333 // quantization mid-interval approx. bit just after
334 // the magbits.
335 data[i] = (tmp & (~ mask2)) | (1 << (30 - sb.magbits));
336 }
337 }
338 }
339 i -= wrap;
340 }
341 return cblk;
342 }
343  
344 /// <summary> Creates a ROIDeScaler object. The information needed to create the
345 /// object is the Entropy decoder used and the parameters.
346 ///
347 /// </summary>
348 /// <param name="src">The source of data that is to be descaled
349 ///
350 /// </param>
351 /// <param name="pl">The parameter list (or options).
352 ///
353 /// </param>
354 /// <param name="decSpec">The decoding specifications
355 ///
356 /// </param>
357 /// <exception cref="IllegalArgumentException">If an error occurs while parsing
358 /// the options in 'pl'
359 ///
360 /// </exception>
361 public static ROIDeScaler createInstance(CBlkQuantDataSrcDec src, ParameterList pl, DecoderSpecs decSpec)
362 {
363 System.String noRoi;
364 //int i;
365  
366 // Check parameters
367 pl.checkList(OPT_PREFIX, CSJ2K.j2k.util.ParameterList.toNameArray(pinfo));
368  
369 // Check if no_roi specified in command line or no roi signalled
370 // in bit stream
371 noRoi = pl.getParameter("Rno_roi");
372 if (noRoi != null || decSpec.rois == null)
373 {
374 // no_roi specified in commandline!
375 return new ROIDeScaler(src, null);
376 }
377  
378 return new ROIDeScaler(src, decSpec.rois);
379 }
380 }
381 }