corrade-vassal – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 /*
2 * CVS identifier:
3 *
4 * $Id: ForwCompTransfSpec.java,v 1.7 2001/05/08 16:10:18 grosbois Exp $
5 *
6 * Class: ForwCompTransfSpec
7 *
8 * Description: Component Transformation specification for encoder
9 *
10 *
11 *
12 * COPYRIGHT:
13 *
14 * This software module was originally developed by Raphaël Grosbois and
15 * Diego Santa Cruz (Swiss Federal Institute of Technology-EPFL); Joel
16 * Askelöf (Ericsson Radio Systems AB); and Bertrand Berthelot, David
17 * Bouchard, Félix Henry, Gerard Mozelle and Patrice Onno (Canon Research
18 * Centre France S.A) in the course of development of the JPEG2000
19 * standard as specified by ISO/IEC 15444 (JPEG 2000 Standard). This
20 * software module is an implementation of a part of the JPEG 2000
21 * Standard. Swiss Federal Institute of Technology-EPFL, Ericsson Radio
22 * Systems AB and Canon Research Centre France S.A (collectively JJ2000
23 * Partners) agree not to assert against ISO/IEC and users of the JPEG
24 * 2000 Standard (Users) any of their rights under the copyright, not
25 * including other intellectual property rights, for this software module
26 * with respect to the usage by ISO/IEC and Users of this software module
27 * or modifications thereof for use in hardware or software products
28 * claiming conformance to the JPEG 2000 Standard. Those intending to use
29 * this software module in hardware or software products are advised that
30 * their use may infringe existing patents. The original developers of
31 * this software module, JJ2000 Partners and ISO/IEC assume no liability
32 * for use of this software module or modifications thereof. No license
33 * or right to this software module is granted for non JPEG 2000 Standard
34 * conforming products. JJ2000 Partners have full right to use this
35 * software module for his/her own purpose, assign or donate this
36 * software module to any third party and to inhibit third parties from
37 * using this software module for non JPEG 2000 Standard conforming
38 * products. This copyright notice must be included in all copies or
39 * derivative works of this software module.
40 *
41 * Copyright (c) 1999/2000 JJ2000 Partners.
42 * */
43 using System;
44 using CSJ2K.j2k.wavelet.analysis;
45 using CSJ2K.j2k.wavelet;
46 using CSJ2K.j2k.image;
47 using CSJ2K.j2k.util;
48 using CSJ2K.j2k;
49 namespace CSJ2K.j2k.image.forwcomptransf
50 {
51  
52 /// <summary> This class extends CompTransfSpec class in order to hold encoder specific
53 /// aspects of CompTransfSpec.
54 ///
55 /// </summary>
56 /// <seealso cref="CompTransfSpec">
57 ///
58 /// </seealso>
59 public class ForwCompTransfSpec:CompTransfSpec, FilterTypes
60 {
61 /// <summary> Constructs a new 'ForwCompTransfSpec' for the specified number of
62 /// components and tiles, the wavelet filters type and the parameter of the
63 /// option 'Mct'. This constructor is called by the encoder. It also checks
64 /// that the arguments belong to the recognized arguments list.
65 ///
66 /// <p>This constructor chose the component transformation type depending
67 /// on the wavelet filters : RCT with w5x3 filter and ICT with w9x7
68 /// filter. Note: All filters must use the same data type.</p>
69 ///
70 /// </summary>
71 /// <param name="nt">The number of tiles
72 ///
73 /// </param>
74 /// <param name="nc">The number of components
75 ///
76 /// </param>
77 /// <param name="type">the type of the specification module i.e. tile specific,
78 /// component specific or both.
79 ///
80 /// </param>
81 /// <param name="wfs">The wavelet filter specifications
82 ///
83 /// </param>
84 /// <param name="pl">The ParameterList
85 ///
86 /// </param>
87 public ForwCompTransfSpec(int nt, int nc, byte type, AnWTFilterSpec wfs, ParameterList pl):base(nt, nc, type)
88 {
89  
90 System.String param = pl.getParameter("Mct");
91  
92 if (param == null)
93 {
94 // The option has not been specified
95  
96 // If less than three component, do not use any component
97 // transformation
98 if (nc < 3)
99 {
100 setDefault("none");
101 return ;
102 }
103 // If the compression is lossless, uses RCT
104 else if (pl.getBooleanParameter("lossless"))
105 {
106 setDefault("rct");
107 return ;
108 }
109 else
110 {
111 AnWTFilter[][] anfilt;
112 int[] filtType = new int[nComp];
113 for (int c = 0; c < 3; c++)
114 {
115 anfilt = (AnWTFilter[][]) wfs.getCompDef(c);
116 filtType[c] = anfilt[0][0].FilterType;
117 }
118  
119 // Check that the three first components use the same filters
120 bool reject = false;
121 for (int c = 1; c < 3; c++)
122 {
123 if (filtType[c] != filtType[0])
124 reject = true;
125 }
126  
127 if (reject)
128 {
129 setDefault("none");
130 }
131 else
132 {
133 anfilt = (AnWTFilter[][]) wfs.getCompDef(0);
134 if (anfilt[0][0].FilterType == CSJ2K.j2k.wavelet.FilterTypes_Fields.W9X7)
135 {
136 setDefault("ict");
137 }
138 else
139 {
140 setDefault("rct");
141 }
142 }
143 }
144  
145 // Each tile receives a component transform specification
146 // according the type of wavelet filters that are used by the
147 // three first components
148 for (int t = 0; t < nt; t++)
149 {
150 AnWTFilter[][] anfilt;
151 int[] filtType = new int[nComp];
152 for (int c = 0; c < 3; c++)
153 {
154 anfilt = (AnWTFilter[][]) wfs.getTileCompVal(t, c);
155 filtType[c] = anfilt[0][0].FilterType;
156 }
157  
158 // Check that the three components use the same filters
159 bool reject = false;
160 for (int c = 1; c < nComp; c++)
161 {
162 if (filtType[c] != filtType[0])
163 reject = true;
164 }
165  
166 if (reject)
167 {
168 setTileDef(t, "none");
169 }
170 else
171 {
172 anfilt = (AnWTFilter[][]) wfs.getTileCompVal(t, 0);
173 if (anfilt[0][0].FilterType == CSJ2K.j2k.wavelet.FilterTypes_Fields.W9X7)
174 {
175 setTileDef(t, "ict");
176 }
177 else
178 {
179 setTileDef(t, "rct");
180 }
181 }
182 }
183 return ;
184 }
185  
186 // Parse argument
187 SupportClass.Tokenizer stk = new SupportClass.Tokenizer(param);
188 System.String word; // current word
189 byte curSpecType = SPEC_DEF; // Specification type of the
190 // current parameter
191 bool[] tileSpec = null; // Tiles concerned by the
192 // specification
193 //System.Boolean value_Renamed;
194  
195 while (stk.HasMoreTokens())
196 {
197 word = stk.NextToken();
198  
199 switch (word[0])
200 {
201  
202 case 't': // Tiles specification
203 tileSpec = parseIdx(word, nTiles);
204 if (curSpecType == SPEC_COMP_DEF)
205 {
206 curSpecType = SPEC_TILE_COMP;
207 }
208 else
209 {
210 curSpecType = SPEC_TILE_DEF;
211 }
212 break;
213  
214 case 'c': // Components specification
215 throw new System.ArgumentException("Component specific " + " parameters" + " not allowed with " + "'-Mct' option");
216  
217 default:
218 if (word.Equals("off"))
219 {
220 if (curSpecType == SPEC_DEF)
221 {
222 setDefault("none");
223 }
224 else if (curSpecType == SPEC_TILE_DEF)
225 {
226 for (int i = tileSpec.Length - 1; i >= 0; i--)
227 if (tileSpec[i])
228 {
229 setTileDef(i, "none");
230 }
231 }
232 }
233 else if (word.Equals("on"))
234 {
235 if (nc < 3)
236 {
237 throw new System.ArgumentException("Cannot use component" + " transformation on a " + "image with less than " + "three components");
238 }
239  
240 if (curSpecType == SPEC_DEF)
241 {
242 // Set arbitrarily the default
243 // value to RCT (later will be found the suitable
244 // component transform for each tile)
245 setDefault("rct");
246 }
247 else if (curSpecType == SPEC_TILE_DEF)
248 {
249 for (int i = tileSpec.Length - 1; i >= 0; i--)
250 {
251 if (tileSpec[i])
252 {
253 if (getFilterType(i, wfs) == CSJ2K.j2k.wavelet.FilterTypes_Fields.W5X3)
254 {
255 setTileDef(i, "rct");
256 }
257 else
258 {
259 setTileDef(i, "ict");
260 }
261 }
262 }
263 }
264 }
265 else
266 {
267 throw new System.ArgumentException("Default parameter of " + "option Mct not" + " recognized: " + param);
268 }
269  
270 // Re-initialize
271 curSpecType = SPEC_DEF;
272 tileSpec = null;
273 break;
274  
275 }
276 }
277  
278 // Check that default value has been specified
279 if (getDefault() == null)
280 {
281 // If not, set arbitrarily the default value to 'none' but
282 // specifies explicitely a default value for each tile depending
283 // on the wavelet transform that is used
284 setDefault("none");
285  
286 for (int t = 0; t < nt; t++)
287 {
288 if (isTileSpecified(t))
289 {
290 continue;
291 }
292  
293 AnWTFilter[][] anfilt;
294 int[] filtType = new int[nComp];
295 for (int c = 0; c < 3; c++)
296 {
297 anfilt = (AnWTFilter[][]) wfs.getTileCompVal(t, c);
298 filtType[c] = anfilt[0][0].FilterType;
299 }
300  
301 // Check that the three components use the same filters
302 bool reject = false;
303 for (int c = 1; c < nComp; c++)
304 {
305 if (filtType[c] != filtType[0])
306 reject = true;
307 }
308  
309 if (reject)
310 {
311 setTileDef(t, "none");
312 }
313 else
314 {
315 anfilt = (AnWTFilter[][]) wfs.getTileCompVal(t, 0);
316 if (anfilt[0][0].FilterType == CSJ2K.j2k.wavelet.FilterTypes_Fields.W9X7)
317 {
318 setTileDef(t, "ict");
319 }
320 else
321 {
322 setTileDef(t, "rct");
323 }
324 }
325 }
326 }
327  
328 // Check validity of component transformation of each tile compared to
329 // the filter used.
330 for (int t = nt - 1; t >= 0; t--)
331 {
332  
333 if (((System.String) getTileDef(t)).Equals("none"))
334 {
335 // No comp. transf is used. No check is needed
336 continue;
337 }
338 else if (((System.String) getTileDef(t)).Equals("rct"))
339 {
340 // Tile is using Reversible component transform
341 int filterType = getFilterType(t, wfs);
342 switch (filterType)
343 {
344  
345 case CSJ2K.j2k.wavelet.FilterTypes_Fields.W5X3: // OK
346 break;
347  
348 case CSJ2K.j2k.wavelet.FilterTypes_Fields.W9X7: // Must use ICT
349 if (isTileSpecified(t))
350 {
351 // User has requested RCT -> Error
352 throw new System.ArgumentException("Cannot use RCT " + "with 9x7 filter " + "in tile " + t);
353 }
354 else
355 {
356 // Specify ICT for this tile
357 setTileDef(t, "ict");
358 }
359 break;
360  
361 default:
362 throw new System.ArgumentException("Default filter is " + "not JPEG 2000 part" + " I compliant");
363  
364 }
365 }
366 else
367 {
368 // ICT
369 int filterType = getFilterType(t, wfs);
370 switch (filterType)
371 {
372  
373 case CSJ2K.j2k.wavelet.FilterTypes_Fields.W5X3: // Must use RCT
374 if (isTileSpecified(t))
375 {
376 // User has requested ICT -> Error
377 throw new System.ArgumentException("Cannot use ICT " + "with filter 5x3 " + "in tile " + t);
378 }
379 else
380 {
381 setTileDef(t, "rct");
382 }
383 break;
384  
385 case CSJ2K.j2k.wavelet.FilterTypes_Fields.W9X7: // OK
386 break;
387  
388 default:
389 throw new System.ArgumentException("Default filter is " + "not JPEG 2000 part" + " I compliant");
390  
391 }
392 }
393 }
394 }
395  
396 /// <summary> Get the filter type common to all component of a given tile. If the
397 /// tile index is -1, it searches common filter type of default
398 /// specifications.
399 ///
400 /// </summary>
401 /// <param name="t">The tile index
402 ///
403 /// </param>
404 /// <param name="wfs">The analysis filters specifications
405 ///
406 /// </param>
407 /// <returns> The filter type common to all the components
408 ///
409 /// </returns>
410 private int getFilterType(int t, AnWTFilterSpec wfs)
411 {
412 AnWTFilter[][] anfilt;
413 int[] filtType = new int[nComp];
414 for (int c = 0; c < nComp; c++)
415 {
416 if (t == - 1)
417 {
418 anfilt = (AnWTFilter[][]) wfs.getCompDef(c);
419 }
420 else
421 {
422 anfilt = (AnWTFilter[][]) wfs.getTileCompVal(t, c);
423 }
424 filtType[c] = anfilt[0][0].FilterType;
425 }
426  
427 // Check that all filters are the same one
428 bool reject = false;
429 for (int c = 1; c < nComp; c++)
430 {
431 if (filtType[c] != filtType[0])
432 reject = true;
433 }
434 if (reject)
435 {
436 throw new System.ArgumentException("Can not use component" + " transformation when " + "components do not use " + "the same filters");
437 }
438 return filtType[0];
439 }
440 }
441 }