corrade-vassal – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 /*
2 * CVS identifier:
3 *
4 * $Id: StringSpec.java,v 1.17 2000/11/30 13:14:07 grosbois Exp $
5 *
6 * Class: StringSpec
7 *
8 * Description: String specification for an option
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.util;
45 using CSJ2K.j2k;
46 namespace CSJ2K.j2k
47 {
48  
49 /// <summary> This class extends ModuleSpec class in order to hold tile-component
50 /// specifications using Strings.
51 ///
52 /// </summary>
53 /// <seealso cref="ModuleSpec">
54 ///
55 /// </seealso>
56 public class StringSpec:ModuleSpec
57 {
58  
59 /// <summary> Constructs an empty 'StringSpec' with specified number of
60 /// tile and components. This constructor is called by the decoder.
61 ///
62 /// </summary>
63 /// <param name="nt">Number of tiles
64 ///
65 /// </param>
66 /// <param name="nc">Number of components
67 ///
68 /// </param>
69 /// <param name="type">the type of the specification module i.e. tile specific,
70 /// component specific or both.
71 ///
72 /// </param>
73 public StringSpec(int nt, int nc, byte type):base(nt, nc, type)
74 {
75 }
76  
77 /// <summary> Constructs a new 'StringSpec' for the specified number of
78 /// components:tiles and the arguments of <tt>optName</tt>
79 /// option. This constructor is called by the encoder. It also
80 /// checks that the arguments belongs to the recognized arguments
81 /// list.
82 ///
83 /// <P><u>Note:</u> The arguments must not start with 't' or 'c'
84 /// since it is reserved for respectively tile and components
85 /// indexes specification.
86 ///
87 /// </summary>
88 /// <param name="nt">The number of tiles
89 ///
90 /// </param>
91 /// <param name="nc">The number of components
92 ///
93 /// </param>
94 /// <param name="type">the type of the specification module i.e. tile specific,
95 /// component specific or both.
96 ///
97 /// </param>
98 /// <param name="name">of the option using boolean spec.
99 ///
100 /// </param>
101 /// <param name="list">The list of all recognized argument in a String array
102 ///
103 /// </param>
104 /// <param name="pl">The ParameterList
105 ///
106 /// </param>
107 public StringSpec(int nt, int nc, byte type, System.String optName, System.String[] list, ParameterList pl):base(nt, nc, type)
108 {
109  
110 System.String param = pl.getParameter(optName);
111 bool recognized = false;
112  
113 if (param == null)
114 {
115 param = pl.DefaultParameterList.getParameter(optName);
116 for (int i = list.Length - 1; i >= 0; i--)
117 if (param.ToUpper().Equals(list[i].ToUpper()))
118 recognized = true;
119 if (!recognized)
120 throw new System.ArgumentException("Default parameter of " + "option -" + optName + " not" + " recognized: " + param);
121 setDefault(param);
122 return ;
123 }
124  
125 // Parse argument
126 SupportClass.Tokenizer stk = new SupportClass.Tokenizer(param);
127 System.String word; // current word
128 byte curSpecType = SPEC_DEF; // Specification type of the
129 // current parameter
130 bool[] tileSpec = null; // Tiles concerned by the
131 // specification
132 bool[] compSpec = null; // Components concerned by the specification
133 //System.Boolean value_Renamed;
134  
135 while (stk.HasMoreTokens())
136 {
137 word = stk.NextToken();
138  
139 switch (word[0])
140 {
141  
142 case 't': // Tiles specification
143 tileSpec = parseIdx(word, nTiles);
144 if (curSpecType == SPEC_COMP_DEF)
145 {
146 curSpecType = SPEC_TILE_COMP;
147 }
148 else
149 {
150 curSpecType = SPEC_TILE_DEF;
151 }
152 break;
153  
154 case 'c': // Components specification
155 compSpec = parseIdx(word, nComp);
156 if (curSpecType == SPEC_TILE_DEF)
157 {
158 curSpecType = SPEC_TILE_COMP;
159 }
160 else
161 curSpecType = SPEC_COMP_DEF;
162 break;
163  
164 default:
165 recognized = false;
166  
167 for (int i = list.Length - 1; i >= 0; i--)
168 if (word.ToUpper().Equals(list[i].ToUpper()))
169 recognized = true;
170 if (!recognized)
171 throw new System.ArgumentException("Default parameter of " + "option -" + optName + " not" + " recognized: " + word);
172  
173 if (curSpecType == SPEC_DEF)
174 {
175 setDefault(word);
176 }
177 else if (curSpecType == SPEC_TILE_DEF)
178 {
179 for (int i = tileSpec.Length - 1; i >= 0; i--)
180 if (tileSpec[i])
181 {
182 setTileDef(i, word);
183 }
184 }
185 else if (curSpecType == SPEC_COMP_DEF)
186 {
187 for (int i = compSpec.Length - 1; i >= 0; i--)
188 if (compSpec[i])
189 {
190 setCompDef(i, word);
191 }
192 }
193 else
194 {
195 for (int i = tileSpec.Length - 1; i >= 0; i--)
196 {
197 for (int j = compSpec.Length - 1; j >= 0; j--)
198 {
199 if (tileSpec[i] && compSpec[j])
200 {
201 setTileCompVal(i, j, word);
202 }
203 }
204 }
205 }
206  
207 // Re-initialize
208 curSpecType = SPEC_DEF;
209 tileSpec = null;
210 compSpec = null;
211 break;
212  
213 }
214 }
215  
216 // Check that default value has been specified
217 if (getDefault() == null)
218 {
219 int ndefspec = 0;
220 for (int t = nt - 1; t >= 0; t--)
221 {
222 for (int c = nc - 1; c >= 0; c--)
223 {
224 if (specValType[t][c] == SPEC_DEF)
225 {
226 ndefspec++;
227 }
228 }
229 }
230  
231 // If some tile-component have received no specification, it takes
232 // the default value defined in ParameterList
233 if (ndefspec != 0)
234 {
235 param = pl.DefaultParameterList.getParameter(optName);
236 for (int i = list.Length - 1; i >= 0; i--)
237 if (param.ToUpper().Equals(list[i].ToUpper()))
238 recognized = true;
239 if (!recognized)
240 throw new System.ArgumentException("Default parameter of " + "option -" + optName + " not" + " recognized: " + param);
241 setDefault(param);
242 }
243 else
244 {
245 // All tile-component have been specified, takes the first
246 // tile-component value as default.
247 setDefault(getSpec(0, 0));
248 switch (specValType[0][0])
249 {
250  
251 case SPEC_TILE_DEF:
252 for (int c = nc - 1; c >= 0; c--)
253 {
254 if (specValType[0][c] == SPEC_TILE_DEF)
255 specValType[0][c] = SPEC_DEF;
256 }
257 tileDef[0] = null;
258 break;
259  
260 case SPEC_COMP_DEF:
261 for (int t = nt - 1; t >= 0; t--)
262 {
263 if (specValType[t][0] == SPEC_COMP_DEF)
264 specValType[t][0] = SPEC_DEF;
265 }
266 compDef[0] = null;
267 break;
268  
269 case SPEC_TILE_COMP:
270 specValType[0][0] = SPEC_DEF;
271 tileCompVal["t0c0"] = null;
272 break;
273 }
274 }
275 }
276 }
277 }
278 }