corrade-vassal – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 1 | /// <summary>************************************************************************** |
2 | /// |
||
3 | /// $Id: ColorSpaceMapper.java,v 1.2 2002/07/25 16:30:55 grosbois Exp $ |
||
4 | /// |
||
5 | /// Copyright Eastman Kodak Company, 343 State Street, Rochester, NY 14650 |
||
6 | /// $Date $ |
||
7 | /// *************************************************************************** |
||
8 | /// </summary> |
||
9 | using System; |
||
10 | using CSJ2K.j2k.image; |
||
11 | using CSJ2K.j2k.util; |
||
12 | using CSJ2K.Icc; |
||
13 | namespace CSJ2K.Color |
||
14 | { |
||
15 | |||
16 | /// <summary> This is the base class for all modules in the colorspace and icc |
||
17 | /// profiling steps of the decoding chain. It is responsible for the |
||
18 | /// allocation and iniitialization of all working storage. It provides |
||
19 | /// several utilities which are of generic use in preparing DataBlks |
||
20 | /// for use and provides default implementations for the getCompData |
||
21 | /// and getInternCompData methods. |
||
22 | /// |
||
23 | /// </summary> |
||
24 | /// <seealso cref="jj2000.j2k.colorspace.ColorSpace"> |
||
25 | /// </seealso> |
||
26 | /// <version> 1.0 |
||
27 | /// </version> |
||
28 | /// <author> Bruce A. Kern |
||
29 | /// </author> |
||
30 | public abstract class ColorSpaceMapper:ImgDataAdapter, BlkImgDataSrc |
||
31 | { |
||
32 | private void InitBlock() |
||
33 | { |
||
34 | computed = new ComputedComponents(this); |
||
35 | } |
||
36 | /// <summary> Returns the parameters that are used in this class and implementing |
||
37 | /// classes. It returns a 2D String array. Each of the 1D arrays is for a |
||
38 | /// different option, and they have 3 elements. The first element is the |
||
39 | /// option name, the second one is the synopsis and the third one is a long |
||
40 | /// description of what the parameter is. The synopsis or description may |
||
41 | /// be 'null', in which case it is assumed that there is no synopsis or |
||
42 | /// description of the option, respectively. Null may be returned if no |
||
43 | /// options are supported. |
||
44 | /// |
||
45 | /// </summary> |
||
46 | /// <returns> the options name, their synopsis and their explanation, or null |
||
47 | /// if no options are supported. |
||
48 | /// |
||
49 | /// </returns> |
||
50 | public static System.String[][] ParameterInfo |
||
51 | { |
||
52 | get |
||
53 | { |
||
54 | return pinfo; |
||
55 | } |
||
56 | |||
57 | } |
||
58 | /// <summary> Arrange for the input DataBlk to receive an |
||
59 | /// appropriately sized and typed data buffer |
||
60 | /// </summary> |
||
61 | /// <param name="db">input DataBlk |
||
62 | /// </param> |
||
63 | /// <seealso cref="jj2000.j2k.image.DataBlk"> |
||
64 | /// </seealso> |
||
65 | protected internal static DataBlk InternalBuffer |
||
66 | { |
||
67 | set |
||
68 | { |
||
69 | switch (value.DataType) |
||
70 | { |
||
71 | |||
72 | |||
73 | case DataBlk.TYPE_INT: |
||
74 | if (value.Data == null || ((int[]) value.Data).Length < value.w * value.h) |
||
75 | value.Data = new int[value.w * value.h]; |
||
76 | break; |
||
77 | |||
78 | |||
79 | case DataBlk.TYPE_FLOAT: |
||
80 | if (value.Data == null || ((float[]) value.Data).Length < value.w * value.h) |
||
81 | { |
||
82 | value.Data = new float[value.w * value.h]; |
||
83 | } |
||
84 | break; |
||
85 | |||
86 | |||
87 | default: |
||
88 | throw new System.ArgumentException("Invalid output datablock" + " type"); |
||
89 | |||
90 | } |
||
91 | } |
||
92 | |||
93 | } |
||
94 | |||
95 | /// <summary>The prefix for ICC Profiler options </summary> |
||
96 | public const char OPT_PREFIX = 'I'; |
||
97 | |||
98 | /// <summary>Platform dependant end of line String. </summary> |
||
99 | //UPGRADE_NOTE: Final was removed from the declaration of 'eol '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" |
||
100 | protected internal static readonly System.String eol = System.Environment.NewLine; |
||
101 | |||
102 | // Temporary data buffers needed during profiling. |
||
103 | protected internal DataBlkInt[] inInt; // Integer input data. |
||
104 | protected internal DataBlkFloat[] inFloat; // Floating point input data. |
||
105 | protected internal DataBlkInt[] workInt; // Input data shifted to zero-offset |
||
106 | protected internal DataBlkFloat[] workFloat; // Input data shifted to zero-offset. |
||
107 | protected internal int[][] dataInt; // Points to input data. |
||
108 | protected internal float[][] dataFloat; // Points to input data. |
||
109 | protected internal float[][] workDataFloat; // References working data pixels. |
||
110 | protected internal int[][] workDataInt; // References working data pixels. |
||
111 | |||
112 | |||
113 | /* input data parameters by component */ |
||
114 | protected internal int[] shiftValueArray = null; |
||
115 | protected internal int[] maxValueArray = null; |
||
116 | protected internal int[] fixedPtBitsArray = null; |
||
117 | |||
118 | /// <summary>The list of parameters that are accepted for ICC profiling.</summary> |
||
119 | //UPGRADE_NOTE: Final was removed from the declaration of 'pinfo'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" |
||
120 | private static readonly System.String[][] pinfo = new System.String[][]{new System.String[]{"IcolorSpacedebug", null, "Print debugging messages during colorspace mapping.", "off"}}; |
||
121 | |||
122 | /// <summary>Parameter Specs </summary> |
||
123 | protected internal ParameterList pl = null; |
||
124 | |||
125 | /// <summary>ColorSpace info </summary> |
||
126 | protected internal ColorSpace csMap = null; |
||
127 | |||
128 | /// <summary>Number of image components </summary> |
||
129 | protected internal int ncomps = 0; |
||
130 | |||
131 | /// <summary>The image source. </summary> |
||
132 | protected internal BlkImgDataSrc src = null; |
||
133 | |||
134 | /// <summary>The image source data per component. </summary> |
||
135 | protected internal DataBlk[] srcBlk = null; |
||
136 | |||
137 | |||
138 | //UPGRADE_NOTE: Field 'EnclosingInstance' was added to class 'ComputedComponents' to access its enclosing instance. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1019'" |
||
139 | protected internal class ComputedComponents |
||
140 | { |
||
141 | private void InitBlock(ColorSpaceMapper enclosingInstance) |
||
142 | { |
||
143 | this.enclosingInstance = enclosingInstance; |
||
144 | } |
||
145 | private ColorSpaceMapper enclosingInstance; |
||
146 | public ColorSpaceMapper Enclosing_Instance |
||
147 | { |
||
148 | get |
||
149 | { |
||
150 | return enclosingInstance; |
||
151 | } |
||
152 | |||
153 | } |
||
154 | //private int tIdx = - 1; |
||
155 | private int h = - 1; |
||
156 | private int w = - 1; |
||
157 | private int ulx = - 1; |
||
158 | private int uly = - 1; |
||
159 | private int offset = - 1; |
||
160 | private int scanw = - 1; |
||
161 | |||
162 | public ComputedComponents(ColorSpaceMapper enclosingInstance) |
||
163 | { |
||
164 | InitBlock(enclosingInstance); |
||
165 | clear(); |
||
166 | } |
||
167 | |||
168 | public ComputedComponents(ColorSpaceMapper enclosingInstance, DataBlk db) |
||
169 | { |
||
170 | InitBlock(enclosingInstance); |
||
171 | set_Renamed(db); |
||
172 | } |
||
173 | |||
174 | public virtual void set_Renamed(DataBlk db) |
||
175 | { |
||
176 | h = db.h; |
||
177 | w = db.w; |
||
178 | ulx = db.ulx; |
||
179 | uly = db.uly; |
||
180 | offset = db.offset; |
||
181 | scanw = db.scanw; |
||
182 | } |
||
183 | |||
184 | public virtual void clear() |
||
185 | { |
||
186 | h = w = ulx = uly = offset = scanw = - 1; |
||
187 | } |
||
188 | |||
189 | public bool Equals(ComputedComponents cc) |
||
190 | { |
||
191 | return (h == cc.h && w == cc.w && ulx == cc.ulx && uly == cc.uly && offset == cc.offset && scanw == cc.scanw); |
||
192 | } |
||
193 | |||
194 | /* end class ComputedComponents */ |
||
195 | } |
||
196 | |||
197 | //UPGRADE_NOTE: The initialization of 'computed' was moved to method 'InitBlock'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1005'" |
||
198 | protected internal ComputedComponents computed; |
||
199 | |||
200 | /// <summary> Copy the DataBlk geometry from source to target |
||
201 | /// DataBlk and assure that the target has an appropriate |
||
202 | /// data buffer. |
||
203 | /// </summary> |
||
204 | /// <param name="tgt">has its geometry set. |
||
205 | /// </param> |
||
206 | /// <param name="src">used to get the new geometric parameters. |
||
207 | /// </param> |
||
208 | protected internal static void copyGeometry(DataBlk tgt, DataBlk src) |
||
209 | { |
||
210 | tgt.offset = 0; |
||
211 | tgt.h = src.h; |
||
212 | tgt.w = src.w; |
||
213 | tgt.ulx = src.ulx; |
||
214 | tgt.uly = src.uly; |
||
215 | tgt.scanw = src.w; |
||
216 | |||
217 | // Create data array if necessary |
||
218 | |||
219 | InternalBuffer = tgt; |
||
220 | } |
||
221 | |||
222 | |||
223 | /// <summary> Factory method for creating instances of this class.</summary> |
||
224 | /// <param name="src">-- source of image data |
||
225 | /// </param> |
||
226 | /// <param name="csMap">-- provides colorspace info |
||
227 | /// </param> |
||
228 | /// <returns> ColorSpaceMapper instance |
||
229 | /// </returns> |
||
230 | /// <exception cref="IOException">profile access exception |
||
231 | /// </exception> |
||
232 | public static BlkImgDataSrc createInstance(BlkImgDataSrc src, ColorSpace csMap) |
||
233 | { |
||
234 | |||
235 | // Check parameters |
||
236 | csMap.pl.checkList(OPT_PREFIX, CSJ2K.j2k.util.ParameterList.toNameArray(pinfo)); |
||
237 | |||
238 | // Perform ICCProfiling or ColorSpace tranfsormation. |
||
239 | if (csMap.Method == ColorSpace.MethodEnum.ICC_PROFILED) |
||
240 | { |
||
241 | return ICCProfiler.createInstance(src, csMap); |
||
242 | } |
||
243 | else |
||
244 | { |
||
245 | ColorSpace.CSEnum colorspace = csMap.getColorSpace(); |
||
246 | |||
247 | if (colorspace == ColorSpace.CSEnum.sRGB) |
||
248 | { |
||
249 | return EnumeratedColorSpaceMapper.createInstance(src, csMap); |
||
250 | } |
||
251 | else if (colorspace == ColorSpace.CSEnum.GreyScale) |
||
252 | { |
||
253 | return EnumeratedColorSpaceMapper.createInstance(src, csMap); |
||
254 | } |
||
255 | else if (colorspace == ColorSpace.CSEnum.sYCC) |
||
256 | { |
||
257 | return SYccColorSpaceMapper.createInstance(src, csMap); |
||
258 | } |
||
259 | if (colorspace == ColorSpace.CSEnum.esRGB) |
||
260 | { |
||
261 | return EsRgbColorSpaceMapper.createInstance(src, csMap); |
||
262 | } |
||
263 | else if (colorspace == ColorSpace.CSEnum.Unknown) |
||
264 | { |
||
265 | return null; |
||
266 | } |
||
267 | else |
||
268 | { |
||
269 | throw new ColorSpaceException("Bad color space specification in image"); |
||
270 | } |
||
271 | } |
||
272 | } |
||
273 | |||
274 | /// <summary> Ctor which creates an ICCProfile for the image and initializes |
||
275 | /// all data objects (input, working, and output). |
||
276 | /// |
||
277 | /// </summary> |
||
278 | /// <param name="src">-- Source of image data |
||
279 | /// </param> |
||
280 | /// <param name="csm">-- provides colorspace info |
||
281 | /// |
||
282 | /// </param> |
||
283 | protected internal ColorSpaceMapper(BlkImgDataSrc src, ColorSpace csMap):base(src) |
||
284 | { |
||
285 | InitBlock(); |
||
286 | this.src = src; |
||
287 | this.csMap = csMap; |
||
288 | initialize(); |
||
289 | /* end ColorSpaceMapper ctor */ |
||
290 | } |
||
291 | |||
292 | /// <summary>General utility used by ctors </summary> |
||
293 | private void initialize() |
||
294 | { |
||
295 | |||
296 | this.pl = csMap.pl; |
||
297 | this.ncomps = src.NumComps; |
||
298 | |||
299 | shiftValueArray = new int[ncomps]; |
||
300 | maxValueArray = new int[ncomps]; |
||
301 | fixedPtBitsArray = new int[ncomps]; |
||
302 | |||
303 | srcBlk = new DataBlk[ncomps]; |
||
304 | inInt = new DataBlkInt[ncomps]; |
||
305 | inFloat = new DataBlkFloat[ncomps]; |
||
306 | workInt = new DataBlkInt[ncomps]; |
||
307 | workFloat = new DataBlkFloat[ncomps]; |
||
308 | dataInt = new int[ncomps][]; |
||
309 | dataFloat = new float[ncomps][]; |
||
310 | workDataInt = new int[ncomps][]; |
||
311 | workDataFloat = new float[ncomps][]; |
||
312 | dataInt = new int[ncomps][]; |
||
313 | dataFloat = new float[ncomps][]; |
||
314 | |||
315 | |||
316 | /* For each component, get a reference to the pixel data and |
||
317 | * set up working DataBlks for both integer and float output. |
||
318 | */ |
||
319 | for (int i = 0; i < ncomps; ++i) |
||
320 | { |
||
321 | |||
322 | shiftValueArray[i] = 1 << (src.getNomRangeBits(i) - 1); |
||
323 | maxValueArray[i] = (1 << src.getNomRangeBits(i)) - 1; |
||
324 | fixedPtBitsArray[i] = src.getFixedPoint(i); |
||
325 | |||
326 | inInt[i] = new DataBlkInt(); |
||
327 | inFloat[i] = new DataBlkFloat(); |
||
328 | workInt[i] = new DataBlkInt(); |
||
329 | workInt[i].progressive = inInt[i].progressive; |
||
330 | workFloat[i] = new DataBlkFloat(); |
||
331 | workFloat[i].progressive = inFloat[i].progressive; |
||
332 | } |
||
333 | } |
||
334 | |||
335 | /// <summary> Returns the number of bits, referred to as the "range bits", |
||
336 | /// corresponding to the nominal range of the data in the specified |
||
337 | /// component. If this number is <i>b</b> then for unsigned data the |
||
338 | /// nominal range is between 0 and 2^b-1, and for signed data it is between |
||
339 | /// -2^(b-1) and 2^(b-1)-1. For floating point data this value is not |
||
340 | /// applicable. |
||
341 | /// |
||
342 | /// </summary> |
||
343 | /// <param name="c">The index of the component. |
||
344 | /// |
||
345 | /// </param> |
||
346 | /// <returns> The number of bits corresponding to the nominal range of the |
||
347 | /// data. Fro floating-point data this value is not applicable and the |
||
348 | /// return value is undefined. |
||
349 | /// </returns> |
||
350 | public virtual int getFixedPoint(int c) |
||
351 | { |
||
352 | return src.getFixedPoint(c); |
||
353 | } |
||
354 | |||
355 | /// <summary> Returns, in the blk argument, a block of image data containing the |
||
356 | /// specifed rectangular area, in the specified component. The data is |
||
357 | /// returned, as a copy of the internal data, therefore the returned data |
||
358 | /// can be modified "in place". |
||
359 | /// |
||
360 | /// <P>The rectangular area to return is specified by the 'ulx', 'uly', 'w' |
||
361 | /// and 'h' members of the 'blk' argument, relative to the current |
||
362 | /// tile. These members are not modified by this method. The 'offset' of |
||
363 | /// the returned data is 0, and the 'scanw' is the same as the block's |
||
364 | /// width. See the 'DataBlk' class. |
||
365 | /// |
||
366 | /// <P>This method, in general, is less efficient than the |
||
367 | /// 'getInternCompData()' method since, in general, it copies the |
||
368 | /// data. However if the array of returned data is to be modified by the |
||
369 | /// caller then this method is preferable. |
||
370 | /// |
||
371 | /// <P>If the data array in 'blk' is 'null', then a new one is created. If |
||
372 | /// the data array is not 'null' then it is reused, and it must be large |
||
373 | /// enough to contain the block's data. Otherwise an 'ArrayStoreException' |
||
374 | /// or an 'IndexOutOfBoundsException' is thrown by the Java system. |
||
375 | /// |
||
376 | /// <P>The returned data may have its 'progressive' attribute set. In this |
||
377 | /// case the returned data is only an approximation of the "final" data. |
||
378 | /// |
||
379 | /// </summary> |
||
380 | /// <param name="blk">Its coordinates and dimensions specify the area to return, |
||
381 | /// relative to the current tile. If it contains a non-null data array, |
||
382 | /// then it must be large enough. If it contains a null data array a new |
||
383 | /// one is created. Some fields in this object are modified to return the |
||
384 | /// data. |
||
385 | /// |
||
386 | /// </param> |
||
387 | /// <param name="c">The index of the component from which to get the data. |
||
388 | /// |
||
389 | /// </param> |
||
390 | /// <seealso cref="getInternCompData"> |
||
391 | /// |
||
392 | /// </seealso> |
||
393 | public virtual DataBlk getCompData(DataBlk out_Renamed, int c) |
||
394 | { |
||
395 | return src.getCompData(out_Renamed, c); |
||
396 | } |
||
397 | |||
398 | /// <summary> Returns, in the blk argument, a block of image data containing the |
||
399 | /// specifed rectangular area, in the specified component. The data is |
||
400 | /// returned, as a reference to the internal data, if any, instead of as a |
||
401 | /// copy, therefore the returned data should not be modified. |
||
402 | /// |
||
403 | /// <P>The rectangular area to return is specified by the 'ulx', 'uly', 'w' |
||
404 | /// and 'h' members of the 'blk' argument, relative to the current |
||
405 | /// tile. These members are not modified by this method. The 'offset' and |
||
406 | /// 'scanw' of the returned data can be arbitrary. See the 'DataBlk' class. |
||
407 | /// |
||
408 | /// <P>This method, in general, is more efficient than the 'getCompData()' |
||
409 | /// method since it may not copy the data. However if the array of returned |
||
410 | /// data is to be modified by the caller then the other method is probably |
||
411 | /// preferable. |
||
412 | /// |
||
413 | /// <P>If possible, the data in the returned 'DataBlk' should be the |
||
414 | /// internal data itself, instead of a copy, in order to increase the data |
||
415 | /// transfer efficiency. However, this depends on the particular |
||
416 | /// implementation (it may be more convenient to just return a copy of the |
||
417 | /// data). This is the reason why the returned data should not be modified. |
||
418 | /// |
||
419 | /// <P>If the data array in <tt>blk</tt> is <tt>null</tt>, then a new one |
||
420 | /// is created if necessary. The implementation of this interface may |
||
421 | /// choose to return the same array or a new one, depending on what is more |
||
422 | /// efficient. Therefore, the data array in <tt>blk</tt> prior to the |
||
423 | /// method call should not be considered to contain the returned data, a |
||
424 | /// new array may have been created. Instead, get the array from |
||
425 | /// <tt>blk</tt> after the method has returned. |
||
426 | /// |
||
427 | /// <P>The returned data may have its 'progressive' attribute set. In this |
||
428 | /// case the returned data is only an approximation of the "final" data. |
||
429 | /// |
||
430 | /// </summary> |
||
431 | /// <param name="blk">Its coordinates and dimensions specify the area to return, |
||
432 | /// relative to the current tile. Some fields in this object are modified |
||
433 | /// to return the data. |
||
434 | /// |
||
435 | /// </param> |
||
436 | /// <param name="c">The index of the component from which to get the data. |
||
437 | /// |
||
438 | /// </param> |
||
439 | /// <returns> The requested DataBlk |
||
440 | /// |
||
441 | /// </returns> |
||
442 | /// <seealso cref="getCompData"> |
||
443 | /// |
||
444 | /// </seealso> |
||
445 | public virtual DataBlk getInternCompData(DataBlk out_Renamed, int c) |
||
446 | { |
||
447 | return src.getInternCompData(out_Renamed, c); |
||
448 | } |
||
449 | |||
450 | /* end class ColorSpaceMapper */ |
||
451 | } |
||
452 | } |