corrade-vassal – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 /// <summary>**************************************************************************
2 ///
3 /// $Id: SYccColorSpaceMapper.java,v 1.1 2002/07/25 14:52:01 grosbois Exp $
4 ///
5 /// Copyright Eastman Kodak Company, 343 State Street, Rochester, NY 14650
6 /// $Date $
7 /// ***************************************************************************
8 /// </summary>
9 using System;
10 using ParameterList = CSJ2K.j2k.util.ParameterList;
11 using BlkImgDataSrc = CSJ2K.j2k.image.BlkImgDataSrc;
12 using DataBlk = CSJ2K.j2k.image.DataBlk;
13 using DataBlkInt = CSJ2K.j2k.image.DataBlkInt;
14 using DataBlkFloat = CSJ2K.j2k.image.DataBlkFloat;
15 using ImgDataAdapter = CSJ2K.j2k.image.ImgDataAdapter;
16 using FacilityManager = CSJ2K.j2k.util.FacilityManager;
17 using MsgLogger = CSJ2K.j2k.util.MsgLogger;
18 namespace CSJ2K.Color
19 {
20  
21  
22 /// <summary> This decodes maps which are defined in the sYCC
23 /// colorspace into the sRGB colorspadce.
24 ///
25 /// </summary>
26 /// <seealso cref="jj2000.j2k.colorspace.ColorSpace">
27 /// </seealso>
28 /// <version> 1.0
29 /// </version>
30 /// <author> Bruce A. Kern
31 /// </author>
32 public class SYccColorSpaceMapper:ColorSpaceMapper
33 {
34 /// <summary>Matrix component for ycc transform. </summary>
35 /* sYCC colorspace matrix */
36  
37 protected internal static float Matrix00 = 1;
38 /// <summary>Matrix component for ycc transform. </summary>
39 protected internal static float Matrix01 = 0;
40 /// <summary>Matrix component for ycc transform. </summary>
41 protected internal static float Matrix02 = (float) 1.402;
42 /// <summary>Matrix component for ycc transform. </summary>
43 protected internal static float Matrix10 = 1;
44 /// <summary>Matrix component for ycc transform. </summary>
45 //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
46 protected internal static float Matrix11 = (float) (- 0.34413);
47 /// <summary>Matrix component for ycc transform. </summary>
48 //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
49 protected internal static float Matrix12 = (float) (- 0.71414);
50 /// <summary>Matrix component for ycc transform. </summary>
51 protected internal static float Matrix20 = 1;
52 /// <summary>Matrix component for ycc transform. </summary>
53 protected internal static float Matrix21 = (float) 1.772;
54 /// <summary>Matrix component for ycc transform. </summary>
55 protected internal static float Matrix22 = 0;
56  
57  
58 /// <summary> Factory method for creating instances of this class.</summary>
59 /// <param name="src">-- source of image data
60 /// </param>
61 /// <param name="csMap">-- provides colorspace info
62 /// </param>
63 /// <returns> SYccColorSpaceMapper instance
64 /// </returns>
65 public static new BlkImgDataSrc createInstance(BlkImgDataSrc src, ColorSpace csMap)
66 {
67 return new SYccColorSpaceMapper(src, csMap);
68 }
69  
70 /// <summary> Ctor which creates an ICCProfile for the image and initializes
71 /// all data objects (input, working, and output).
72 ///
73 /// </summary>
74 /// <param name="src">-- Source of image data
75 /// </param>
76 /// <param name="csm">-- provides colorspace info
77 /// </param>
78 protected internal SYccColorSpaceMapper(BlkImgDataSrc src, ColorSpace csMap):base(src, csMap)
79 {
80 initialize();
81 /* end SYccColorSpaceMapper ctor */
82 }
83  
84 /// <summary>General utility used by ctors </summary>
85 private void initialize()
86 {
87  
88 if (ncomps != 1 && ncomps != 3)
89 {
90 System.String msg = "SYccColorSpaceMapper: ycc transformation _not_ applied to " + ncomps + " component image";
91 FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.ERROR, msg);
92 throw new ColorSpaceException(msg);
93 }
94 }
95  
96  
97 /// <summary> Returns, in the blk argument, a block of image data containing the
98 /// specifed rectangular area, in the specified component. The data is
99 /// returned, as a copy of the internal data, therefore the returned data
100 /// can be modified "in place".
101 ///
102 /// <P>The rectangular area to return is specified by the 'ulx', 'uly', 'w'
103 /// and 'h' members of the 'blk' argument, relative to the current
104 /// tile. These members are not modified by this method. The 'offset' of
105 /// the returned data is 0, and the 'scanw' is the same as the block's
106 /// width. See the 'DataBlk' class.
107 ///
108 /// <P>If the data array in 'blk' is 'null', then a new one is created. If
109 /// the data array is not 'null' then it is reused, and it must be large
110 /// enough to contain the block's data. Otherwise an 'ArrayStoreException'
111 /// or an 'IndexOutOfBoundsException' is thrown by the Java system.
112 ///
113 /// <P>The returned data has its 'progressive' attribute set to that of the
114 /// input data.
115 ///
116 /// </summary>
117 /// <param name="blk">Its coordinates and dimensions specify the area to
118 /// return. If it contains a non-null data array, then it must have the
119 /// correct dimensions. If it contains a null data array a new one is
120 /// created. The fields in this object are modified to return the data.
121 ///
122 /// </param>
123 /// <param name="c">The index of the component from which to get the data. Only 0
124 /// and 3 are valid.
125 ///
126 /// </param>
127 /// <returns> The requested DataBlk
128 /// </returns>
129 /// <seealso cref="getInternCompData">
130 ///
131 /// </seealso>
132 public override DataBlk getCompData(DataBlk outblk, int c)
133 {
134  
135 int type = outblk.DataType;
136  
137 int i; // j removed
138  
139 // Calculate all components:
140 for (i = 0; i < ncomps; ++i)
141 {
142  
143 // Set up the working DataBlk geometry.
144 copyGeometry(workInt[i], outblk);
145 copyGeometry(workFloat[i], outblk);
146 copyGeometry(inInt[i], outblk);
147 copyGeometry(inFloat[i], outblk);
148  
149 // Request data from the source.
150 inInt[i] = (DataBlkInt) src.getInternCompData(inInt[i], i);
151 }
152  
153 if (type == DataBlk.TYPE_INT)
154 {
155 if (ncomps == 1)
156 workInt[c] = inInt[c];
157 else
158 workInt = mult(inInt);
159 outblk.progressive = inInt[c].progressive;
160 outblk.Data = workInt[c].Data;
161 }
162  
163 if (type == DataBlk.TYPE_FLOAT)
164 {
165 if (ncomps == 1)
166 workFloat[c] = inFloat[c];
167 else
168 workFloat = mult(inFloat);
169 outblk.progressive = inFloat[c].progressive;
170 outblk.Data = workFloat[c].Data;
171 }
172  
173  
174 // Initialize the output block geometry and set the profiled
175 // data into the output block.
176 outblk.offset = 0;
177 outblk.scanw = outblk.w;
178  
179 return outblk;
180 }
181  
182 /// <summary> Returns, in the blk argument, a block of image data containing the
183 /// specifed rectangular area, in the specified component. The data is
184 /// returned, as a reference to the internal data, if any, instead of as a
185 /// copy, therefore the returned data should not be modified.
186 ///
187 /// <P>The rectangular area to return is specified by the 'ulx', 'uly', 'w'
188 /// and 'h' members of the 'blk' argument, relative to the current
189 /// tile. These members are not modified by this method. The 'offset' and
190 /// 'scanw' of the returned data can be arbitrary. See the 'DataBlk' class.
191 ///
192 /// <P>This method, in general, is more efficient than the 'getCompData()'
193 /// method since it may not copy the data. However if the array of returned
194 /// data is to be modified by the caller then the other method is probably
195 /// preferable.
196 ///
197 /// <P>If possible, the data in the returned 'DataBlk' should be the
198 /// internal data itself, instead of a copy, in order to increase the data
199 /// transfer efficiency. However, this depends on the particular
200 /// implementation (it may be more convenient to just return a copy of the
201 /// data). This is the reason why the returned data should not be modified.
202 ///
203 /// <P>If the data array in <tt>blk</tt> is <tt>null</tt>, then a new one
204 /// is created if necessary. The implementation of this interface may
205 /// choose to return the same array or a new one, depending on what is more
206 /// efficient. Therefore, the data array in <tt>blk</tt> prior to the
207 /// method call should not be considered to contain the returned data, a
208 /// new array may have been created. Instead, get the array from
209 /// <tt>blk</tt> after the method has returned.
210 ///
211 /// <P>The returned data may have its 'progressive' attribute set. In this
212 /// case the returned data is only an approximation of the "final" data.
213 ///
214 /// </summary>
215 /// <param name="blk">Its coordinates and dimensions specify the area to return,
216 /// relative to the current tile. Some fields in this object are modified
217 /// to return the data.
218 ///
219 /// </param>
220 /// <param name="c">The index of the component from which to get the data.
221 ///
222 /// </param>
223 /// <returns> The requested DataBlk
224 ///
225 /// </returns>
226 /// <seealso cref="getCompData">
227 /// </seealso>
228 public override DataBlk getInternCompData(DataBlk out_Renamed, int c)
229 {
230 return getCompData(out_Renamed, c);
231 }
232  
233  
234 /// <summary> Output a DataBlkFloat array where each sample in each component
235 /// is the product of the YCC matrix * the vector of samples across
236 /// the input components.
237 /// </summary>
238 /// <param name="inblk">input DataBlkFloat array
239 /// </param>
240 /// <returns> output DataBlkFloat array
241 /// </returns>
242 private static DataBlkFloat[] mult(DataBlkFloat[] inblk)
243 {
244  
245 if (inblk.Length != 3)
246 throw new System.ArgumentException("bad input array size");
247  
248 int i, j;
249 int length = inblk[0].h * inblk[0].w;
250 DataBlkFloat[] outblk = new DataBlkFloat[3];
251 float[][] out_Renamed = new float[3][];
252 float[][] in_Renamed = new float[3][];
253  
254 for (i = 0; i < 3; ++i)
255 {
256 in_Renamed[i] = inblk[i].DataFloat;
257 outblk[i] = new DataBlkFloat();
258 copyGeometry(outblk[i], inblk[i]);
259 outblk[i].offset = inblk[i].offset;
260 out_Renamed[i] = new float[length];
261 outblk[i].Data = out_Renamed[i];
262 }
263  
264 for (j = 0; j < length; ++j)
265 {
266 out_Renamed[0][j] = (Matrix00 * in_Renamed[0][inblk[0].offset + j] + Matrix01 * in_Renamed[1][inblk[1].offset + j] + Matrix02 * in_Renamed[2][inblk[2].offset + j]);
267  
268 out_Renamed[1][j] = (Matrix10 * in_Renamed[0][inblk[0].offset + j] + Matrix11 * in_Renamed[1][inblk[1].offset + j] + Matrix12 * in_Renamed[2][inblk[2].offset + j]);
269  
270 out_Renamed[2][j] = (Matrix20 * in_Renamed[0][inblk[0].offset + j] + Matrix21 * in_Renamed[1][inblk[1].offset + j] + Matrix22 * in_Renamed[2][inblk[2].offset + j]);
271 }
272  
273 return outblk;
274 }
275  
276  
277  
278 /// <summary> Output a DataBlkInt array where each sample in each component
279 /// is the product of the YCC matrix * the vector of samples across
280 /// the input components.
281 /// </summary>
282 /// <param name="inblk">input DataBlkInt array
283 /// </param>
284 /// <returns> output DataBlkInt array
285 /// </returns>
286 private static DataBlkInt[] mult(DataBlkInt[] inblk)
287 {
288  
289 if (inblk.Length != 3)
290 throw new System.ArgumentException("bad input array size");
291  
292  
293 int i, j;
294 int length = inblk[0].h * inblk[0].w;
295 DataBlkInt[] outblk = new DataBlkInt[3];
296 int[][] out_Renamed = new int[3][];
297 int[][] in_Renamed = new int[3][];
298  
299 for (i = 0; i < 3; ++i)
300 {
301 in_Renamed[i] = inblk[i].DataInt;
302 outblk[i] = new DataBlkInt();
303 copyGeometry(outblk[i], inblk[i]);
304 outblk[i].offset = inblk[i].offset;
305 out_Renamed[i] = new int[length];
306 outblk[i].Data = out_Renamed[i];
307 }
308  
309 for (j = 0; j < length; ++j)
310 {
311 //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
312 out_Renamed[0][j] = (int) (Matrix00 * in_Renamed[0][inblk[0].offset + j] + Matrix01 * in_Renamed[1][inblk[1].offset + j] + Matrix02 * in_Renamed[2][inblk[2].offset + j]);
313  
314 //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
315 out_Renamed[1][j] = (int) (Matrix10 * in_Renamed[0][inblk[0].offset + j] + Matrix11 * in_Renamed[1][inblk[1].offset + j] + Matrix12 * in_Renamed[2][inblk[2].offset + j]);
316  
317 //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
318 out_Renamed[2][j] = (int) (Matrix20 * in_Renamed[0][inblk[0].offset + j] + Matrix21 * in_Renamed[1][inblk[1].offset + j] + Matrix22 * in_Renamed[2][inblk[2].offset + j]);
319 }
320  
321 return outblk;
322 }
323  
324  
325 /// <summary>Return a suitable String representation of the class instance. </summary>
326 public override System.String ToString()
327 {
328 int i;
329  
330 System.Text.StringBuilder rep_nComps = new System.Text.StringBuilder("ncomps= ").Append(System.Convert.ToString(ncomps));
331 System.Text.StringBuilder rep_comps = new System.Text.StringBuilder();
332  
333 for (i = 0; i < ncomps; ++i)
334 {
335 rep_comps.Append(" ").Append("component[").Append(System.Convert.ToString(i)).Append("] height, width = (").Append(src.getCompImgHeight(i)).Append(", ").Append(src.getCompImgWidth(i)).Append(")").Append(eol);
336 }
337  
338 System.Text.StringBuilder rep = new System.Text.StringBuilder("[SYccColorSpaceMapper ");
339 rep.Append(rep_nComps).Append(eol);
340 rep.Append(rep_comps).Append(" ");
341  
342 return rep.Append("]").ToString();
343 }
344  
345  
346 /* end class SYccColorSpaceMapper */
347 }
348 }