corrade-vassal – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 1 | /// <summary>************************************************************************** |
2 | /// |
||
3 | /// $Id: ICCProfile.java,v 1.1 2002/07/25 14:56: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 System.Text; |
||
11 | using ParameterList = CSJ2K.j2k.util.ParameterList; |
||
12 | using DecoderSpecs = CSJ2K.j2k.decoder.DecoderSpecs; |
||
13 | using BitstreamReaderAgent = CSJ2K.j2k.codestream.reader.BitstreamReaderAgent; |
||
14 | using ColorSpace = CSJ2K.Color.ColorSpace; |
||
15 | using ColorSpaceException = CSJ2K.Color.ColorSpaceException; |
||
16 | using ICCProfileHeader = CSJ2K.Icc.Types.ICCProfileHeader; |
||
17 | using ICCTag = CSJ2K.Icc.Tags.ICCTag; |
||
18 | using ICCTagTable = CSJ2K.Icc.Tags.ICCTagTable; |
||
19 | using ICCCurveType = CSJ2K.Icc.Tags.ICCCurveType; |
||
20 | using ICCXYZType = CSJ2K.Icc.Tags.ICCXYZType; |
||
21 | using XYZNumber = CSJ2K.Icc.Types.XYZNumber; |
||
22 | using ICCProfileVersion = CSJ2K.Icc.Types.ICCProfileVersion; |
||
23 | using ICCDateTime = CSJ2K.Icc.Types.ICCDateTime; |
||
24 | using FileFormatBoxes = CSJ2K.j2k.fileformat.FileFormatBoxes; |
||
25 | using RandomAccessIO = CSJ2K.j2k.io.RandomAccessIO; |
||
26 | using FacilityManager = CSJ2K.j2k.util.FacilityManager; |
||
27 | using MsgLogger = CSJ2K.j2k.util.MsgLogger; |
||
28 | namespace CSJ2K.Icc |
||
29 | { |
||
30 | |||
31 | /// <summary> This class models the ICCProfile file. This file is a binary file which is divided |
||
32 | /// into two parts, an ICCProfileHeader followed by an ICCTagTable. The header is a |
||
33 | /// straightforward list of descriptive parameters such as profile size, version, date and various |
||
34 | /// more esoteric parameters. The tag table is a structured list of more complexly aggragated data |
||
35 | /// describing things such as ICC curves, copyright information, descriptive text blocks, etc. |
||
36 | /// |
||
37 | /// Classes exist to model the header and tag table and their various constituent parts the developer |
||
38 | /// is refered to these for further information on the structure and contents of the header and tag table. |
||
39 | /// |
||
40 | /// </summary> |
||
41 | /// <seealso cref="jj2000.j2k.icc.types.ICCProfileHeader"> |
||
42 | /// </seealso> |
||
43 | /// <seealso cref="jj2000.j2k.icc.tags.ICCTagTable"> |
||
44 | /// </seealso> |
||
45 | /// <version> 1.0 |
||
46 | /// </version> |
||
47 | /// <author> Bruce A. Kern |
||
48 | /// </author> |
||
49 | |||
50 | public abstract class ICCProfile |
||
51 | { |
||
52 | private int ProfileSize |
||
53 | { |
||
54 | get |
||
55 | { |
||
56 | return header.dwProfileSize; |
||
57 | } |
||
58 | |||
59 | set |
||
60 | { |
||
61 | header.dwProfileSize = value; |
||
62 | } |
||
63 | |||
64 | } |
||
65 | private int CMMTypeSignature |
||
66 | { |
||
67 | get |
||
68 | { |
||
69 | return header.dwCMMTypeSignature; |
||
70 | } |
||
71 | |||
72 | set |
||
73 | { |
||
74 | header.dwCMMTypeSignature = value; |
||
75 | } |
||
76 | |||
77 | } |
||
78 | private int ProfileClass |
||
79 | { |
||
80 | get |
||
81 | { |
||
82 | return header.dwProfileClass; |
||
83 | } |
||
84 | |||
85 | set |
||
86 | { |
||
87 | header.dwProfileClass = value; |
||
88 | } |
||
89 | |||
90 | } |
||
91 | private int ColorSpaceType |
||
92 | { |
||
93 | get |
||
94 | { |
||
95 | return header.dwColorSpaceType; |
||
96 | } |
||
97 | |||
98 | set |
||
99 | { |
||
100 | header.dwColorSpaceType = value; |
||
101 | } |
||
102 | |||
103 | } |
||
104 | private int PCSType |
||
105 | { |
||
106 | get |
||
107 | { |
||
108 | return header.dwPCSType; |
||
109 | } |
||
110 | |||
111 | set |
||
112 | { |
||
113 | header.dwPCSType = value; |
||
114 | } |
||
115 | |||
116 | } |
||
117 | private int ProfileSignature |
||
118 | { |
||
119 | get |
||
120 | { |
||
121 | return header.dwProfileSignature; |
||
122 | } |
||
123 | |||
124 | set |
||
125 | { |
||
126 | header.dwProfileSignature = value; |
||
127 | } |
||
128 | |||
129 | } |
||
130 | private int PlatformSignature |
||
131 | { |
||
132 | get |
||
133 | { |
||
134 | return header.dwPlatformSignature; |
||
135 | } |
||
136 | |||
137 | set |
||
138 | { |
||
139 | header.dwPlatformSignature = value; |
||
140 | } |
||
141 | |||
142 | } |
||
143 | private int CMMFlags |
||
144 | { |
||
145 | get |
||
146 | { |
||
147 | return header.dwCMMFlags; |
||
148 | } |
||
149 | |||
150 | set |
||
151 | { |
||
152 | header.dwCMMFlags = value; |
||
153 | } |
||
154 | |||
155 | } |
||
156 | private int DeviceManufacturer |
||
157 | { |
||
158 | get |
||
159 | { |
||
160 | return header.dwDeviceManufacturer; |
||
161 | } |
||
162 | |||
163 | set |
||
164 | { |
||
165 | header.dwDeviceManufacturer = value; |
||
166 | } |
||
167 | |||
168 | } |
||
169 | private int DeviceModel |
||
170 | { |
||
171 | get |
||
172 | { |
||
173 | return header.dwDeviceModel; |
||
174 | } |
||
175 | |||
176 | set |
||
177 | { |
||
178 | header.dwDeviceModel = value; |
||
179 | } |
||
180 | |||
181 | } |
||
182 | private int DeviceAttributes1 |
||
183 | { |
||
184 | get |
||
185 | { |
||
186 | return header.dwDeviceAttributes1; |
||
187 | } |
||
188 | |||
189 | set |
||
190 | { |
||
191 | header.dwDeviceAttributes1 = value; |
||
192 | } |
||
193 | |||
194 | } |
||
195 | private int DeviceAttributesReserved |
||
196 | { |
||
197 | get |
||
198 | { |
||
199 | return header.dwDeviceAttributesReserved; |
||
200 | } |
||
201 | |||
202 | set |
||
203 | { |
||
204 | header.dwDeviceAttributesReserved = value; |
||
205 | } |
||
206 | |||
207 | } |
||
208 | private int RenderingIntent |
||
209 | { |
||
210 | get |
||
211 | { |
||
212 | return header.dwRenderingIntent; |
||
213 | } |
||
214 | |||
215 | set |
||
216 | { |
||
217 | header.dwRenderingIntent = value; |
||
218 | } |
||
219 | |||
220 | } |
||
221 | private int CreatorSig |
||
222 | { |
||
223 | get |
||
224 | { |
||
225 | return header.dwCreatorSig; |
||
226 | } |
||
227 | |||
228 | set |
||
229 | { |
||
230 | header.dwCreatorSig = value; |
||
231 | } |
||
232 | |||
233 | } |
||
234 | private ICCProfileVersion ProfileVersion |
||
235 | { |
||
236 | get |
||
237 | { |
||
238 | return header.profileVersion; |
||
239 | } |
||
240 | |||
241 | set |
||
242 | { |
||
243 | header.profileVersion = value; |
||
244 | } |
||
245 | |||
246 | } |
||
247 | private XYZNumber PCSIlluminant |
||
248 | { |
||
249 | set |
||
250 | { |
||
251 | header.PCSIlluminant = value; |
||
252 | } |
||
253 | |||
254 | } |
||
255 | private ICCDateTime DateTime |
||
256 | { |
||
257 | set |
||
258 | { |
||
259 | header.dateTime = value; |
||
260 | } |
||
261 | |||
262 | } |
||
263 | /// <summary> Access the profile header</summary> |
||
264 | /// <returns> ICCProfileHeader |
||
265 | /// </returns> |
||
266 | virtual public ICCProfileHeader Header |
||
267 | { |
||
268 | get |
||
269 | { |
||
270 | return header; |
||
271 | } |
||
272 | |||
273 | } |
||
274 | /// <summary> Access the profile tag table</summary> |
||
275 | /// <returns> ICCTagTable |
||
276 | /// </returns> |
||
277 | virtual public ICCTagTable TagTable |
||
278 | { |
||
279 | get |
||
280 | { |
||
281 | return tags; |
||
282 | } |
||
283 | |||
284 | } |
||
285 | |||
286 | //UPGRADE_NOTE: Final was removed from the declaration of 'eol '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" |
||
287 | private static readonly System.String eol = System.Environment.NewLine; |
||
288 | |||
289 | /// <summary>Gray index. </summary> |
||
290 | // Renamed for convenience: |
||
291 | public const int GRAY = 0; |
||
292 | /// <summary>RGB index. </summary> |
||
293 | public const int RED = 0; |
||
294 | /// <summary>RGB index. </summary> |
||
295 | public const int GREEN = 1; |
||
296 | /// <summary>RGB index. </summary> |
||
297 | public const int BLUE = 2; |
||
298 | |||
299 | /// <summary>Size of native type </summary> |
||
300 | public const int boolean_size = 1; |
||
301 | /// <summary>Size of native type </summary> |
||
302 | public const int byte_size = 1; |
||
303 | /// <summary>Size of native type </summary> |
||
304 | public const int char_size = 2; |
||
305 | /// <summary>Size of native type </summary> |
||
306 | public const int short_size = 2; |
||
307 | /// <summary>Size of native type </summary> |
||
308 | public const int int_size = 4; |
||
309 | /// <summary>Size of native type </summary> |
||
310 | public const int float_size = 4; |
||
311 | /// <summary>Size of native type </summary> |
||
312 | public const int long_size = 8; |
||
313 | /// <summary>Size of native type </summary> |
||
314 | public const int double_size = 8; |
||
315 | |||
316 | /* Bit twiddling constant for integral types. */ public const int BITS_PER_BYTE = 8; |
||
317 | /* Bit twiddling constant for integral types. */ public const int BITS_PER_SHORT = 16; |
||
318 | /* Bit twiddling constant for integral types. */ public const int BITS_PER_INT = 32; |
||
319 | /* Bit twiddling constant for integral types. */ public const int BITS_PER_LONG = 64; |
||
320 | /* Bit twiddling constant for integral types. */ public const int BYTES_PER_SHORT = 2; |
||
321 | /* Bit twiddling constant for integral types. */ public const int BYTES_PER_INT = 4; |
||
322 | /* Bit twiddling constant for integral types. */ public const int BYTES_PER_LONG = 8; |
||
323 | |||
324 | /* JP2 Box structure analysis help */ |
||
325 | |||
326 | [Serializable] |
||
327 | private class BoxType:System.Collections.Hashtable |
||
328 | { |
||
329 | |||
330 | private static System.Collections.Hashtable map = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable()); |
||
331 | |||
332 | public static void put(int type, System.String desc) |
||
333 | { |
||
334 | map[(System.Int32) type] = desc; |
||
335 | } |
||
336 | |||
337 | public static System.String get_Renamed(int type) |
||
338 | { |
||
339 | return (System.String) map[(System.Int32) type]; |
||
340 | } |
||
341 | |||
342 | public static System.String colorSpecMethod(int meth) |
||
343 | { |
||
344 | switch (meth) |
||
345 | { |
||
346 | |||
347 | case 2: return "Restricted ICC Profile"; |
||
348 | |||
349 | case 1: return "Enumerated Color Space"; |
||
350 | |||
351 | default: return "Undefined Color Spec Method"; |
||
352 | |||
353 | } |
||
354 | } |
||
355 | static BoxType() |
||
356 | { |
||
357 | { |
||
358 | put(CSJ2K.j2k.fileformat.FileFormatBoxes.BITS_PER_COMPONENT_BOX, "BITS_PER_COMPONENT_BOX"); |
||
359 | put(CSJ2K.j2k.fileformat.FileFormatBoxes.CAPTURE_RESOLUTION_BOX, "CAPTURE_RESOLUTION_BOX"); |
||
360 | put(CSJ2K.j2k.fileformat.FileFormatBoxes.CHANNEL_DEFINITION_BOX, "CHANNEL_DEFINITION_BOX"); |
||
361 | put(CSJ2K.j2k.fileformat.FileFormatBoxes.COLOUR_SPECIFICATION_BOX, "COLOUR_SPECIFICATION_BOX"); |
||
362 | put(CSJ2K.j2k.fileformat.FileFormatBoxes.COMPONENT_MAPPING_BOX, "COMPONENT_MAPPING_BOX"); |
||
363 | put(CSJ2K.j2k.fileformat.FileFormatBoxes.CONTIGUOUS_CODESTREAM_BOX, "CONTIGUOUS_CODESTREAM_BOX"); |
||
364 | put(CSJ2K.j2k.fileformat.FileFormatBoxes.DEFAULT_DISPLAY_RESOLUTION_BOX, "DEFAULT_DISPLAY_RESOLUTION_BOX"); |
||
365 | put(CSJ2K.j2k.fileformat.FileFormatBoxes.FILE_TYPE_BOX, "FILE_TYPE_BOX"); |
||
366 | put(CSJ2K.j2k.fileformat.FileFormatBoxes.IMAGE_HEADER_BOX, "IMAGE_HEADER_BOX"); |
||
367 | put(CSJ2K.j2k.fileformat.FileFormatBoxes.INTELLECTUAL_PROPERTY_BOX, "INTELLECTUAL_PROPERTY_BOX"); |
||
368 | put(CSJ2K.j2k.fileformat.FileFormatBoxes.JP2_HEADER_BOX, "JP2_HEADER_BOX"); |
||
369 | put(CSJ2K.j2k.fileformat.FileFormatBoxes.JP2_SIGNATURE_BOX, "JP2_SIGNATURE_BOX"); |
||
370 | put(CSJ2K.j2k.fileformat.FileFormatBoxes.PALETTE_BOX, "PALETTE_BOX"); |
||
371 | put(CSJ2K.j2k.fileformat.FileFormatBoxes.RESOLUTION_BOX, "RESOLUTION_BOX"); |
||
372 | put(CSJ2K.j2k.fileformat.FileFormatBoxes.URL_BOX, "URL_BOX"); |
||
373 | put(CSJ2K.j2k.fileformat.FileFormatBoxes.UUID_BOX, "UUID_BOX"); |
||
374 | put(CSJ2K.j2k.fileformat.FileFormatBoxes.UUID_INFO_BOX, "UUID_INFO_BOX"); |
||
375 | put(CSJ2K.j2k.fileformat.FileFormatBoxes.UUID_LIST_BOX, "UUID_LIST_BOX"); |
||
376 | put(CSJ2K.j2k.fileformat.FileFormatBoxes.XML_BOX, "XML_BOX"); |
||
377 | } |
||
378 | } |
||
379 | } |
||
380 | |||
381 | |||
382 | /// <summary> Creates an int from a 4 character String</summary> |
||
383 | /// <param name="fourChar">string representation of an integer |
||
384 | /// </param> |
||
385 | /// <returns> the integer which is denoted by the input String. |
||
386 | /// </returns> |
||
387 | public static int getIntFromString(System.String fourChar) |
||
388 | { |
||
389 | byte[] bytes = SupportClass.ToByteArray(fourChar); |
||
390 | return getInt(bytes, 0); |
||
391 | } |
||
392 | /// <summary> Create an XYZNumber from byte [] input</summary> |
||
393 | /// <param name="data">array containing the XYZNumber representation |
||
394 | /// </param> |
||
395 | /// <param name="offset">start of the rep in the array |
||
396 | /// </param> |
||
397 | /// <returns> the created XYZNumber |
||
398 | /// </returns> |
||
399 | public static XYZNumber getXYZNumber(byte[] data, int offset) |
||
400 | { |
||
401 | int x, y, z; |
||
402 | x = ICCProfile.getInt(data, offset); |
||
403 | y = ICCProfile.getInt(data, offset + int_size); |
||
404 | z = ICCProfile.getInt(data, offset + 2 * int_size); |
||
405 | return new XYZNumber(x, y, z); |
||
406 | } |
||
407 | |||
408 | /// <summary> Create an ICCProfileVersion from byte [] input</summary> |
||
409 | /// <param name="data">array containing the ICCProfileVersion representation |
||
410 | /// </param> |
||
411 | /// <param name="offset">start of the rep in the array |
||
412 | /// </param> |
||
413 | /// <returns> the created ICCProfileVersion |
||
414 | /// </returns> |
||
415 | public static ICCProfileVersion getICCProfileVersion(byte[] data, int offset) |
||
416 | { |
||
417 | byte major = data[offset]; |
||
418 | byte minor = data[offset + byte_size]; |
||
419 | byte resv1 = data[offset + 2 * byte_size]; |
||
420 | byte resv2 = data[offset + 3 * byte_size]; |
||
421 | return new ICCProfileVersion(major, minor, resv1, resv2); |
||
422 | } |
||
423 | |||
424 | /// <summary> Create an ICCDateTime from byte [] input</summary> |
||
425 | /// <param name="data">array containing the ICCProfileVersion representation |
||
426 | /// </param> |
||
427 | /// <param name="offset">start of the rep in the array |
||
428 | /// </param> |
||
429 | /// <returns> the created ICCProfileVersion |
||
430 | /// </returns> |
||
431 | public static ICCDateTime getICCDateTime(byte[] data, int offset) |
||
432 | { |
||
433 | short wYear = ICCProfile.getShort(data, offset); // Number of the actual year (i.e. 1994) |
||
434 | short wMonth = ICCProfile.getShort(data, offset + ICCProfile.short_size); // Number of the month (1-12) |
||
435 | short wDay = ICCProfile.getShort(data, offset + 2 * ICCProfile.short_size); // Number of the day |
||
436 | short wHours = ICCProfile.getShort(data, offset + 3 * ICCProfile.short_size); // Number of hours (0-23) |
||
437 | short wMinutes = ICCProfile.getShort(data, offset + 4 * ICCProfile.short_size); // Number of minutes (0-59) |
||
438 | short wSeconds = ICCProfile.getShort(data, offset + 5 * ICCProfile.short_size); // Number of seconds (0-59) |
||
439 | return new ICCDateTime(wYear, wMonth, wDay, wHours, wMinutes, wSeconds); |
||
440 | } |
||
441 | |||
442 | |||
443 | /// <summary> Create a String from a byte []. Optionally swap adjacent byte |
||
444 | /// pairs. Intended to be used to create integer String representations |
||
445 | /// allowing for endian translations. |
||
446 | /// </summary> |
||
447 | /// <param name="bfr">data array |
||
448 | /// </param> |
||
449 | /// <param name="offset">start of data in array |
||
450 | /// </param> |
||
451 | /// <param name="length">length of data in array |
||
452 | /// </param> |
||
453 | /// <param name="swap">swap adjacent bytes? |
||
454 | /// </param> |
||
455 | /// <returns> String rep of data |
||
456 | /// </returns> |
||
457 | public static System.String getString(byte[] bfr, int offset, int length, bool swap) |
||
458 | { |
||
459 | |||
460 | byte[] result = new byte[length]; |
||
461 | int incr = swap?- 1:1; |
||
462 | int start = swap?offset + length - 1:offset; |
||
463 | for (int i = 0, j = start; i < length; ++i) |
||
464 | { |
||
465 | result[i] = bfr[j]; |
||
466 | j += incr; |
||
467 | } |
||
468 | return new System.String(SupportClass.ToCharArray(result)); |
||
469 | } |
||
470 | |||
471 | /// <summary> Create a short from a two byte [], with optional byte swapping.</summary> |
||
472 | /// <param name="bfr">data array |
||
473 | /// </param> |
||
474 | /// <param name="off">start of data in array |
||
475 | /// </param> |
||
476 | /// <param name="swap">swap bytes? |
||
477 | /// </param> |
||
478 | /// <returns> native type from representation. |
||
479 | /// </returns> |
||
480 | public static short getShort(byte[] bfr, int off, bool swap) |
||
481 | { |
||
482 | |||
483 | int tmp0 = bfr[off] & 0xff; // Clear the sign extended bits in the int. |
||
484 | int tmp1 = bfr[off + 1] & 0xff; |
||
485 | |||
486 | |||
487 | return (short) (swap?(tmp1 << BITS_PER_BYTE | tmp0):(tmp0 << BITS_PER_BYTE | tmp1)); |
||
488 | } |
||
489 | |||
490 | /// <summary> Create a short from a two byte [].</summary> |
||
491 | /// <param name="bfr">data array |
||
492 | /// </param> |
||
493 | /// <param name="off">start of data in array |
||
494 | /// </param> |
||
495 | /// <returns> native type from representation. |
||
496 | /// </returns> |
||
497 | public static short getShort(byte[] bfr, int off) |
||
498 | { |
||
499 | int tmp0 = bfr[off] & 0xff; // Clear the sign extended bits in the int. |
||
500 | int tmp1 = bfr[off + 1] & 0xff; |
||
501 | return (short) (tmp0 << BITS_PER_BYTE | tmp1); |
||
502 | } |
||
503 | |||
504 | /// <summary> Separate bytes in an int into a byte array lsb to msb order.</summary> |
||
505 | /// <param name="d">integer to separate |
||
506 | /// </param> |
||
507 | /// <returns> byte [] containing separated int. |
||
508 | /// </returns> |
||
509 | public static byte[] setInt(int d) |
||
510 | { |
||
511 | return setInt(d, new byte[BYTES_PER_INT]); |
||
512 | } |
||
513 | |||
514 | /// <summary> Separate bytes in an int into a byte array lsb to msb order. |
||
515 | /// Return the result in the provided array |
||
516 | /// </summary> |
||
517 | /// <param name="d">integer to separate |
||
518 | /// </param> |
||
519 | /// <param name="b">return output here. |
||
520 | /// </param> |
||
521 | /// <returns> reference to output. |
||
522 | /// </returns> |
||
523 | public static byte[] setInt(int d, byte[] b) |
||
524 | { |
||
525 | if (b == null) |
||
526 | b = new byte[BYTES_PER_INT]; |
||
527 | for (int i = 0; i < BYTES_PER_INT; ++i) |
||
528 | { |
||
529 | b[i] = (byte) (d & 0x0ff); |
||
530 | d = d >> BITS_PER_BYTE; |
||
531 | } |
||
532 | return b; |
||
533 | } |
||
534 | |||
535 | /// <summary> Separate bytes in a long into a byte array lsb to msb order.</summary> |
||
536 | /// <param name="d">long to separate |
||
537 | /// </param> |
||
538 | /// <returns> byte [] containing separated int. |
||
539 | /// </returns> |
||
540 | public static byte[] setLong(long d) |
||
541 | { |
||
542 | return setLong(d, new byte[BYTES_PER_INT]); |
||
543 | } |
||
544 | |||
545 | /// <summary> Separate bytes in a long into a byte array lsb to msb order. |
||
546 | /// Return the result in the provided array |
||
547 | /// </summary> |
||
548 | /// <param name="d">long to separate |
||
549 | /// </param> |
||
550 | /// <param name="b">return output here. |
||
551 | /// </param> |
||
552 | /// <returns> reference to output. |
||
553 | /// </returns> |
||
554 | public static byte[] setLong(long d, byte[] b) |
||
555 | { |
||
556 | if (b == null) |
||
557 | b = new byte[BYTES_PER_LONG]; |
||
558 | for (int i = 0; i < BYTES_PER_LONG; ++i) |
||
559 | { |
||
560 | b[i] = (byte) (d & 0x0ff); |
||
561 | d = d >> BITS_PER_BYTE; |
||
562 | } |
||
563 | return b; |
||
564 | } |
||
565 | |||
566 | |||
567 | /// <summary> Create an int from a byte [4], with optional byte swapping.</summary> |
||
568 | /// <param name="bfr">data array |
||
569 | /// </param> |
||
570 | /// <param name="off">start of data in array |
||
571 | /// </param> |
||
572 | /// <param name="swap">swap bytes? |
||
573 | /// </param> |
||
574 | /// <returns> native type from representation. |
||
575 | /// </returns> |
||
576 | public static int getInt(byte[] bfr, int off, bool swap) |
||
577 | { |
||
578 | |||
579 | int tmp0 = getShort(bfr, off, swap) & 0xffff; // Clear the sign extended bits in the int. |
||
580 | int tmp1 = getShort(bfr, off + 2, swap) & 0xffff; |
||
581 | |||
582 | return (int) (swap?(tmp1 << BITS_PER_SHORT | tmp0):(tmp0 << BITS_PER_SHORT | tmp1)); |
||
583 | } |
||
584 | |||
585 | /// <summary> Create an int from a byte [4].</summary> |
||
586 | /// <param name="bfr">data array |
||
587 | /// </param> |
||
588 | /// <param name="off">start of data in array |
||
589 | /// </param> |
||
590 | /// <returns> native type from representation. |
||
591 | /// </returns> |
||
592 | public static int getInt(byte[] bfr, int off) |
||
593 | { |
||
594 | |||
595 | int tmp0 = getShort(bfr, off) & 0xffff; // Clear the sign extended bits in the int. |
||
596 | int tmp1 = getShort(bfr, off + 2) & 0xffff; |
||
597 | |||
598 | return (int) (tmp0 << BITS_PER_SHORT | tmp1); |
||
599 | } |
||
600 | |||
601 | /// <summary> Create an long from a byte [8].</summary> |
||
602 | /// <param name="bfr">data array |
||
603 | /// </param> |
||
604 | /// <param name="off">start of data in array |
||
605 | /// </param> |
||
606 | /// <returns> native type from representation. |
||
607 | /// </returns> |
||
608 | public static long getLong(byte[] bfr, int off) |
||
609 | { |
||
610 | |||
611 | long tmp0 = getInt(bfr, off) & unchecked((int) 0xffffffff); // Clear the sign extended bits in the int. |
||
612 | long tmp1 = getInt(bfr, off + 4) & unchecked((int) 0xffffffff); |
||
613 | |||
614 | return (long) (tmp0 << BITS_PER_INT | tmp1); |
||
615 | } |
||
616 | |||
617 | |||
618 | /// <summary>signature </summary> |
||
619 | // Define the set of standard signature and type values |
||
620 | // Because of the endian issues and byte swapping, the profile codes must |
||
621 | // be stored in memory and be addressed by address. As such, only those |
||
622 | // codes required for Restricted ICC use are defined here |
||
623 | |||
624 | //UPGRADE_NOTE: Final was removed from the declaration of 'kdwProfileSignature '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" |
||
625 | public static readonly int kdwProfileSignature; |
||
626 | /// <summary>signature </summary> |
||
627 | //UPGRADE_NOTE: Final was removed from the declaration of 'kdwProfileSigReverse '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" |
||
628 | public static readonly int kdwProfileSigReverse; |
||
629 | /// <summary>profile type </summary> |
||
630 | //UPGRADE_NOTE: Final was removed from the declaration of 'kdwInputProfile '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" |
||
631 | public static readonly int kdwInputProfile; |
||
632 | /// <summary>tag type </summary> |
||
633 | //UPGRADE_NOTE: Final was removed from the declaration of 'kdwDisplayProfile '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" |
||
634 | public static readonly int kdwDisplayProfile; |
||
635 | /// <summary>tag type </summary> |
||
636 | //UPGRADE_NOTE: Final was removed from the declaration of 'kdwRGBData '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" |
||
637 | public static readonly int kdwRGBData; |
||
638 | /// <summary>tag type </summary> |
||
639 | //UPGRADE_NOTE: Final was removed from the declaration of 'kdwGrayData '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" |
||
640 | public static readonly int kdwGrayData; |
||
641 | /// <summary>tag type </summary> |
||
642 | //UPGRADE_NOTE: Final was removed from the declaration of 'kdwXYZData '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" |
||
643 | public static readonly int kdwXYZData; |
||
644 | /// <summary>input type </summary> |
||
645 | public const int kMonochromeInput = 0; |
||
646 | /// <summary>input type </summary> |
||
647 | public const int kThreeCompInput = 1; |
||
648 | |||
649 | /// <summary>tag signature </summary> |
||
650 | //UPGRADE_NOTE: Final was removed from the declaration of 'kdwGrayTRCTag '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" |
||
651 | public static readonly int kdwGrayTRCTag; |
||
652 | /// <summary>tag signature </summary> |
||
653 | //UPGRADE_NOTE: Final was removed from the declaration of 'kdwRedColorantTag '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" |
||
654 | public static readonly int kdwRedColorantTag; |
||
655 | /// <summary>tag signature </summary> |
||
656 | //UPGRADE_NOTE: Final was removed from the declaration of 'kdwGreenColorantTag '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" |
||
657 | public static readonly int kdwGreenColorantTag; |
||
658 | /// <summary>tag signature </summary> |
||
659 | //UPGRADE_NOTE: Final was removed from the declaration of 'kdwBlueColorantTag '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" |
||
660 | public static readonly int kdwBlueColorantTag; |
||
661 | /// <summary>tag signature </summary> |
||
662 | //UPGRADE_NOTE: Final was removed from the declaration of 'kdwRedTRCTag '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" |
||
663 | public static readonly int kdwRedTRCTag; |
||
664 | /// <summary>tag signature </summary> |
||
665 | //UPGRADE_NOTE: Final was removed from the declaration of 'kdwGreenTRCTag '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" |
||
666 | public static readonly int kdwGreenTRCTag; |
||
667 | /// <summary>tag signature </summary> |
||
668 | //UPGRADE_NOTE: Final was removed from the declaration of 'kdwBlueTRCTag '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" |
||
669 | public static readonly int kdwBlueTRCTag; |
||
670 | /// <summary>tag signature </summary> |
||
671 | //UPGRADE_NOTE: Final was removed from the declaration of 'kdwCopyrightTag '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" |
||
672 | public static readonly int kdwCopyrightTag; |
||
673 | /// <summary>tag signature </summary> |
||
674 | //UPGRADE_NOTE: Final was removed from the declaration of 'kdwMediaWhiteTag '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" |
||
675 | public static readonly int kdwMediaWhiteTag; |
||
676 | /// <summary>tag signature </summary> |
||
677 | //UPGRADE_NOTE: Final was removed from the declaration of 'kdwProfileDescTag '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" |
||
678 | public static readonly int kdwProfileDescTag; |
||
679 | |||
680 | |||
681 | private ICCProfileHeader header = null; |
||
682 | private ICCTagTable tags = null; |
||
683 | private byte[] profile = null; |
||
684 | |||
685 | //private byte[] data = null; |
||
686 | private ParameterList pl = null; |
||
687 | |||
688 | private ICCProfile() |
||
689 | { |
||
690 | throw new ICCProfileException("illegal to invoke empty constructor"); |
||
691 | } |
||
692 | |||
693 | /// <summary> ParameterList constructor </summary> |
||
694 | /// <param name="csb">provides colorspace information |
||
695 | /// </param> |
||
696 | protected internal ICCProfile(ColorSpace csm) |
||
697 | { |
||
698 | this.pl = csm.pl; |
||
699 | profile = csm.ICCProfile; |
||
700 | initProfile(profile); |
||
701 | } |
||
702 | |||
703 | /// <summary> Read the header and tags into memory and verify |
||
704 | /// that the correct type of profile is being used. for encoding. |
||
705 | /// </summary> |
||
706 | /// <param name="data">ICCProfile |
||
707 | /// </param> |
||
708 | /// <exception cref="ICCProfileInvalidException">for bad signature and class and bad type |
||
709 | /// </exception> |
||
710 | private void initProfile(byte[] data) |
||
711 | { |
||
712 | header = new ICCProfileHeader(data); |
||
713 | tags = ICCTagTable.createInstance(data); |
||
714 | |||
715 | |||
716 | // Verify that the data pointed to by icc is indeed a valid profile |
||
717 | // and that it is possibly of one of the Restricted ICC types. The simplest way to check |
||
718 | // this is to verify that the profile signature is correct, that it is an input profile, |
||
719 | // and that the PCS used is XYX. |
||
720 | |||
721 | // However, a common error in profiles will be to create Monitor profiles rather |
||
722 | // than input profiles. If this is the only error found, it's still useful to let this |
||
723 | // go through with an error written to stderr. |
||
724 | |||
725 | if (ProfileClass == kdwDisplayProfile) |
||
726 | { |
||
727 | System.String message = "NOTE!! Technically, this profile is a Display profile, not an" + " Input Profile, and thus is not a valid Restricted ICC profile." + " However, it is quite possible that this profile is usable as" + " a Restricted ICC profile, so this code will ignore this state" + " and proceed with processing."; |
||
728 | |||
729 | FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING, message); |
||
730 | } |
||
731 | |||
732 | if ((ProfileSignature != kdwProfileSignature) || ((ProfileClass != kdwInputProfile) && (ProfileClass != kdwDisplayProfile)) || (PCSType != kdwXYZData)) |
||
733 | { |
||
734 | throw new ICCProfileInvalidException(); |
||
735 | } |
||
736 | } |
||
737 | |||
738 | |||
739 | /// <summary>Provide a suitable string representation for the class </summary> |
||
740 | public override System.String ToString() |
||
741 | { |
||
742 | System.Text.StringBuilder rep = new System.Text.StringBuilder("[ICCProfile:"); |
||
743 | System.Text.StringBuilder body = new System.Text.StringBuilder(); |
||
744 | body.Append(eol).Append(header); |
||
745 | body.Append(eol).Append(eol).Append(tags); |
||
746 | rep.Append(ColorSpace.indent(" ", body)); |
||
747 | return rep.Append("]").ToString(); |
||
748 | } |
||
749 | |||
750 | |||
751 | /// <summary> Create a two character hex representation of a byte</summary> |
||
752 | /// <param name="i">byte to represent |
||
753 | /// </param> |
||
754 | /// <returns> representation |
||
755 | /// </returns> |
||
756 | public static System.String toHexString(byte i) |
||
757 | { |
||
758 | System.String rep = (i >= 0 && i < 16?"0":"") + System.Convert.ToString((int) i, 16); |
||
759 | if (rep.Length > 2) |
||
760 | rep = rep.Substring(rep.Length - 2); |
||
761 | return rep; |
||
762 | } |
||
763 | |||
764 | /// <summary> Create a 4 character hex representation of a short</summary> |
||
765 | /// <param name="i">short to represent |
||
766 | /// </param> |
||
767 | /// <returns> representation |
||
768 | /// </returns> |
||
769 | public static System.String toHexString(short i) |
||
770 | { |
||
771 | System.String rep; |
||
772 | |||
773 | if (i >= 0 && i < 0x10) |
||
774 | rep = "000" + System.Convert.ToString((int) i, 16); |
||
775 | else if (i >= 0 && i < 0x100) |
||
776 | rep = "00" + System.Convert.ToString((int) i, 16); |
||
777 | else if (i >= 0 && i < 0x1000) |
||
778 | rep = "0" + System.Convert.ToString((int) i, 16); |
||
779 | else |
||
780 | rep = "" + System.Convert.ToString((int) i, 16); |
||
781 | |||
782 | if (rep.Length > 4) |
||
783 | rep = rep.Substring(rep.Length - 4); |
||
784 | return rep; |
||
785 | } |
||
786 | |||
787 | |||
788 | /// <summary> Create a 8 character hex representation of a int</summary> |
||
789 | /// <param name="i">int to represent |
||
790 | /// </param> |
||
791 | /// <returns> representation |
||
792 | /// </returns> |
||
793 | public static System.String toHexString(int i) |
||
794 | { |
||
795 | System.String rep; |
||
796 | |||
797 | if (i >= 0 && i < 0x10) |
||
798 | rep = "0000000" + System.Convert.ToString((int) i, 16); |
||
799 | else if (i >= 0 && i < 0x100) |
||
800 | rep = "000000" + System.Convert.ToString((int) i, 16); |
||
801 | else if (i >= 0 && i < 0x1000) |
||
802 | rep = "00000" + System.Convert.ToString((int) i, 16); |
||
803 | else if (i >= 0 && i < 0x10000) |
||
804 | rep = "0000" + System.Convert.ToString((int) i, 16); |
||
805 | else if (i >= 0 && i < 0x100000) |
||
806 | rep = "000" + System.Convert.ToString((int) i, 16); |
||
807 | else if (i >= 0 && i < 0x1000000) |
||
808 | rep = "00" + System.Convert.ToString((int) i, 16); |
||
809 | else if (i >= 0 && i < 0x10000000) |
||
810 | rep = "0" + System.Convert.ToString((int) i, 16); |
||
811 | else |
||
812 | rep = "" + System.Convert.ToString((int) i, 16); |
||
813 | |||
814 | if (rep.Length > 8) |
||
815 | rep = rep.Substring(rep.Length - 8); |
||
816 | return rep; |
||
817 | } |
||
818 | |||
819 | public static System.String ToString(byte[] data) |
||
820 | { |
||
821 | |||
822 | int i, row, col, rem, rows, cols; |
||
823 | |||
824 | System.Text.StringBuilder rep = new System.Text.StringBuilder(); |
||
825 | System.Text.StringBuilder rep0 = null; |
||
826 | System.Text.StringBuilder rep1 = null; |
||
827 | System.Text.StringBuilder rep2 = null; |
||
828 | |||
829 | cols = 16; |
||
830 | rows = data.Length / cols; |
||
831 | rem = data.Length % cols; |
||
832 | |||
833 | byte[] lbytes = new byte[8]; |
||
834 | for (row = 0, i = 0; row < rows; ++row) |
||
835 | { |
||
836 | rep1 = new System.Text.StringBuilder(); |
||
837 | rep2 = new System.Text.StringBuilder(); |
||
838 | |||
839 | for (i = 0; i < 8; ++i) |
||
840 | lbytes[i] = 0; |
||
841 | byte[] tbytes = System.Text.ASCIIEncoding.ASCII.GetBytes(System.Convert.ToString(row * 16, 16)); |
||
842 | for (int t = 0, l = lbytes.Length - tbytes.Length; t < tbytes.Length; ++l, ++t) |
||
843 | lbytes[l] = tbytes[t]; |
||
844 | |||
845 | rep0 = new System.Text.StringBuilder(new System.String(SupportClass.ToCharArray(lbytes))); |
||
846 | |||
847 | for (col = 0; col < cols; ++col) |
||
848 | { |
||
849 | byte b = data[i++]; |
||
850 | rep1.Append(toHexString(b)).Append(i % 2 == 0?" ":""); |
||
851 | if ((System.Char.IsLetter((char) b) || ((char) b).CompareTo('$') == 0 || ((char) b).CompareTo('_') == 0)) |
||
852 | rep2.Append((char) b); |
||
853 | else |
||
854 | rep2.Append("."); |
||
855 | } |
||
856 | rep.Append(rep0).Append(" : ").Append(rep1).Append(": ").Append(rep2).Append(eol); |
||
857 | } |
||
858 | |||
859 | rep1 = new System.Text.StringBuilder(); |
||
860 | rep2 = new System.Text.StringBuilder(); |
||
861 | |||
862 | for (i = 0; i < 8; ++i) |
||
863 | lbytes[i] = 0; |
||
864 | byte[] tbytes2 = System.Text.ASCIIEncoding.ASCII.GetBytes(System.Convert.ToString(row * 16, 16)); |
||
865 | for (int t = 0, l = lbytes.Length - tbytes2.Length; t < tbytes2.Length; ++l, ++t) |
||
866 | lbytes[l] = tbytes2[t]; |
||
867 | |||
868 | rep0 = new System.Text.StringBuilder(System.Text.ASCIIEncoding.ASCII.GetString(lbytes)); |
||
869 | |||
870 | for (col = 0; col < rem; ++col) |
||
871 | { |
||
872 | byte b = data[i++]; |
||
873 | rep1.Append(toHexString(b)).Append(i % 2 == 0?" ":""); |
||
874 | if ((System.Char.IsLetter((char) b) || ((char) b).CompareTo('$') == 0 || ((char) b).CompareTo('_') == 0)) |
||
875 | rep2.Append((char) b); |
||
876 | else |
||
877 | rep2.Append("."); |
||
878 | } |
||
879 | for (col = rem; col < 16; ++col) |
||
880 | rep1.Append(" ").Append(col % 2 == 0?" ":""); |
||
881 | |||
882 | rep.Append(rep0).Append(" : ").Append(rep1).Append(": ").Append(rep2).Append(eol); |
||
883 | |||
884 | return rep.ToString(); |
||
885 | } |
||
886 | |||
887 | /// <summary> Parse this ICCProfile into a RestrictedICCProfile |
||
888 | /// which is appropriate to the data in this profile. |
||
889 | /// Either a MonochromeInputRestrictedProfile or |
||
890 | /// MatrixBasedRestrictedProfile is returned |
||
891 | /// </summary> |
||
892 | /// <returns> RestrictedICCProfile |
||
893 | /// </returns> |
||
894 | /// <exception cref="ICCProfileInvalidException">no curve data |
||
895 | /// </exception> |
||
896 | public virtual RestrictedICCProfile parse() |
||
897 | { |
||
898 | |||
899 | // The next step is to determine which Restricted ICC type is used by this profile. |
||
900 | // Unfortunately, the only way to do this is to look through the tag table for |
||
901 | // the tags required by the two types. |
||
902 | |||
903 | // First look for the gray TRC tag. If the profile is indeed an input profile, and this |
||
904 | // tag exists, then the profile is a Monochrome Input profile |
||
905 | |||
906 | ICCCurveType grayTag = (ICCCurveType) tags[(System.Int32) kdwGrayTRCTag]; |
||
907 | if (grayTag != null) |
||
908 | { |
||
909 | return RestrictedICCProfile.createInstance(grayTag); |
||
910 | } |
||
911 | |||
912 | // If it wasn't a Monochrome Input profile, look for the Red Colorant tag. If that |
||
913 | // tag is found and the profile is indeed an input profile, then this profile is |
||
914 | // a Three-Component Matrix-Based Input profile |
||
915 | |||
916 | ICCCurveType rTRCTag = (ICCCurveType) tags[(System.Int32) kdwRedTRCTag]; |
||
917 | |||
918 | |||
919 | if (rTRCTag != null) |
||
920 | { |
||
921 | ICCCurveType gTRCTag = (ICCCurveType) tags[(System.Int32) kdwGreenTRCTag]; |
||
922 | ICCCurveType bTRCTag = (ICCCurveType) tags[(System.Int32) kdwBlueTRCTag]; |
||
923 | ICCXYZType rColorantTag = (ICCXYZType) tags[(System.Int32) kdwRedColorantTag]; |
||
924 | ICCXYZType gColorantTag = (ICCXYZType) tags[(System.Int32) kdwGreenColorantTag]; |
||
925 | ICCXYZType bColorantTag = (ICCXYZType) tags[(System.Int32) kdwBlueColorantTag]; |
||
926 | return RestrictedICCProfile.createInstance(rTRCTag, gTRCTag, bTRCTag, rColorantTag, gColorantTag, bColorantTag); |
||
927 | } |
||
928 | |||
929 | throw new ICCProfileInvalidException("curve data not found in profile"); |
||
930 | } |
||
931 | |||
932 | /// <summary> Output this ICCProfile to a RandomAccessFile</summary> |
||
933 | /// <param name="os">output file |
||
934 | /// </param> |
||
935 | //UPGRADE_TODO: Class 'java.io.RandomAccessFile' was converted to 'System.IO.FileStream' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioRandomAccessFile'" |
||
936 | public virtual void write(System.IO.FileStream os) |
||
937 | { |
||
938 | Header.write(os); |
||
939 | TagTable.write(os); |
||
940 | } |
||
941 | |||
942 | |||
943 | /* end class ICCProfile */ |
||
944 | static ICCProfile() |
||
945 | { |
||
946 | kdwProfileSignature = GetTagInt("acsp"); |
||
947 | kdwProfileSigReverse = GetTagInt("psca"); |
||
948 | kdwInputProfile = GetTagInt("scnr"); |
||
949 | kdwDisplayProfile = GetTagInt("mntr"); |
||
950 | kdwRGBData = GetTagInt("RGB "); |
||
951 | kdwGrayData = GetTagInt("GRAY"); |
||
952 | kdwXYZData = GetTagInt("XYZ "); |
||
953 | |||
954 | kdwGrayTRCTag = GetTagInt("kTRC"); |
||
955 | kdwRedColorantTag = GetTagInt("rXYZ"); |
||
956 | kdwGreenColorantTag = GetTagInt("gXYZ"); |
||
957 | kdwBlueColorantTag = GetTagInt("bXYZ"); |
||
958 | kdwRedTRCTag = GetTagInt("rTRC"); |
||
959 | kdwGreenTRCTag = GetTagInt("gTRC"); |
||
960 | kdwBlueTRCTag = GetTagInt("bTRC"); |
||
961 | kdwCopyrightTag = GetTagInt("cprt"); |
||
962 | kdwMediaWhiteTag = GetTagInt("wtpt"); |
||
963 | kdwProfileDescTag = GetTagInt("desc"); |
||
964 | } |
||
965 | static int GetTagInt(string tag) |
||
966 | { |
||
967 | byte[] tagBytes = ASCIIEncoding.ASCII.GetBytes(tag); |
||
968 | Array.Reverse(tagBytes); |
||
969 | return BitConverter.ToInt32(tagBytes, 0); |
||
970 | } |
||
971 | |||
972 | } |
||
973 | } |