-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathICC_Profile.java
More file actions
2114 lines (1759 loc) · 67.4 KB
/
Copy pathICC_Profile.java
File metadata and controls
2114 lines (1759 loc) · 67.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
/*
**********************************************************************
**********************************************************************
**********************************************************************
*** COPYRIGHT (c) Eastman Kodak Company, 1997 ***
*** As an unpublished work pursuant to Title 17 of the United ***
*** States Code. All rights reserved. ***
**********************************************************************
**********************************************************************
**********************************************************************/
package java.awt.color;
import sun.java2d.cmm.PCMM;
import sun.java2d.cmm.CMSManager;
import sun.java2d.cmm.Profile;
import sun.java2d.cmm.ProfileDataVerifier;
import sun.java2d.cmm.ProfileDeferralMgr;
import sun.java2d.cmm.ProfileDeferralInfo;
import sun.java2d.cmm.ProfileActivator;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamException;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.security.AccessController;
import java.security.PrivilegedAction;
/**
* A representation of color profile data for device independent and
* device dependent color spaces based on the International Color
* Consortium Specification ICC.1:2001-12, File Format for Color Profiles,
* (see <A href="http://www.color.org"> http://www.color.org</A>).
* <p>
* An ICC_ColorSpace object can be constructed from an appropriate
* ICC_Profile.
* Typically, an ICC_ColorSpace would be associated with an ICC
* Profile which is either an input, display, or output profile (see
* the ICC specification). There are also device link, abstract,
* color space conversion, and named color profiles. These are less
* useful for tagging a color or image, but are useful for other
* purposes (in particular device link profiles can provide improved
* performance for converting from one device's color space to
* another's).
* <p>
* ICC Profiles represent transformations from the color space of
* the profile (e.g. a monitor) to a Profile Connection Space (PCS).
* Profiles of interest for tagging images or colors have a PCS
* which is one of the two specific device independent
* spaces (one CIEXYZ space and one CIELab space) defined in the
* ICC Profile Format Specification. Most profiles of interest
* either have invertible transformations or explicitly specify
* transformations going both directions.
* @see ICC_ColorSpace
*/
public class ICC_Profile implements Serializable {
private static final long serialVersionUID = -3938515861990936766L;
private transient Profile cmmProfile;
private transient ProfileDeferralInfo deferralInfo;
private transient ProfileActivator profileActivator;
// Registry of singleton profile objects for specific color spaces
// defined in the ColorSpace class (e.g. CS_sRGB), see
// getInstance(int cspace) factory method.
private static ICC_Profile sRGBprofile;
private static ICC_Profile XYZprofile;
private static ICC_Profile PYCCprofile;
private static ICC_Profile GRAYprofile;
private static ICC_Profile LINEAR_RGBprofile;
/**
* Profile class is input.
*/
public static final int CLASS_INPUT = 0;
/**
* Profile class is display.
*/
public static final int CLASS_DISPLAY = 1;
/**
* Profile class is output.
*/
public static final int CLASS_OUTPUT = 2;
/**
* Profile class is device link.
*/
public static final int CLASS_DEVICELINK = 3;
/**
* Profile class is color space conversion.
*/
public static final int CLASS_COLORSPACECONVERSION = 4;
/**
* Profile class is abstract.
*/
public static final int CLASS_ABSTRACT = 5;
/**
* Profile class is named color.
*/
public static final int CLASS_NAMEDCOLOR = 6;
/**
* ICC Profile Color Space Type Signature: 'XYZ '.
*/
public static final int icSigXYZData = 0x58595A20; /* 'XYZ ' */
/**
* ICC Profile Color Space Type Signature: 'Lab '.
*/
public static final int icSigLabData = 0x4C616220; /* 'Lab ' */
/**
* ICC Profile Color Space Type Signature: 'Luv '.
*/
public static final int icSigLuvData = 0x4C757620; /* 'Luv ' */
/**
* ICC Profile Color Space Type Signature: 'YCbr'.
*/
public static final int icSigYCbCrData = 0x59436272; /* 'YCbr' */
/**
* ICC Profile Color Space Type Signature: 'Yxy '.
*/
public static final int icSigYxyData = 0x59787920; /* 'Yxy ' */
/**
* ICC Profile Color Space Type Signature: 'RGB '.
*/
public static final int icSigRgbData = 0x52474220; /* 'RGB ' */
/**
* ICC Profile Color Space Type Signature: 'GRAY'.
*/
public static final int icSigGrayData = 0x47524159; /* 'GRAY' */
/**
* ICC Profile Color Space Type Signature: 'HSV'.
*/
public static final int icSigHsvData = 0x48535620; /* 'HSV ' */
/**
* ICC Profile Color Space Type Signature: 'HLS'.
*/
public static final int icSigHlsData = 0x484C5320; /* 'HLS ' */
/**
* ICC Profile Color Space Type Signature: 'CMYK'.
*/
public static final int icSigCmykData = 0x434D594B; /* 'CMYK' */
/**
* ICC Profile Color Space Type Signature: 'CMY '.
*/
public static final int icSigCmyData = 0x434D5920; /* 'CMY ' */
/**
* ICC Profile Color Space Type Signature: '2CLR'.
*/
public static final int icSigSpace2CLR = 0x32434C52; /* '2CLR' */
/**
* ICC Profile Color Space Type Signature: '3CLR'.
*/
public static final int icSigSpace3CLR = 0x33434C52; /* '3CLR' */
/**
* ICC Profile Color Space Type Signature: '4CLR'.
*/
public static final int icSigSpace4CLR = 0x34434C52; /* '4CLR' */
/**
* ICC Profile Color Space Type Signature: '5CLR'.
*/
public static final int icSigSpace5CLR = 0x35434C52; /* '5CLR' */
/**
* ICC Profile Color Space Type Signature: '6CLR'.
*/
public static final int icSigSpace6CLR = 0x36434C52; /* '6CLR' */
/**
* ICC Profile Color Space Type Signature: '7CLR'.
*/
public static final int icSigSpace7CLR = 0x37434C52; /* '7CLR' */
/**
* ICC Profile Color Space Type Signature: '8CLR'.
*/
public static final int icSigSpace8CLR = 0x38434C52; /* '8CLR' */
/**
* ICC Profile Color Space Type Signature: '9CLR'.
*/
public static final int icSigSpace9CLR = 0x39434C52; /* '9CLR' */
/**
* ICC Profile Color Space Type Signature: 'ACLR'.
*/
public static final int icSigSpaceACLR = 0x41434C52; /* 'ACLR' */
/**
* ICC Profile Color Space Type Signature: 'BCLR'.
*/
public static final int icSigSpaceBCLR = 0x42434C52; /* 'BCLR' */
/**
* ICC Profile Color Space Type Signature: 'CCLR'.
*/
public static final int icSigSpaceCCLR = 0x43434C52; /* 'CCLR' */
/**
* ICC Profile Color Space Type Signature: 'DCLR'.
*/
public static final int icSigSpaceDCLR = 0x44434C52; /* 'DCLR' */
/**
* ICC Profile Color Space Type Signature: 'ECLR'.
*/
public static final int icSigSpaceECLR = 0x45434C52; /* 'ECLR' */
/**
* ICC Profile Color Space Type Signature: 'FCLR'.
*/
public static final int icSigSpaceFCLR = 0x46434C52; /* 'FCLR' */
/**
* ICC Profile Class Signature: 'scnr'.
*/
public static final int icSigInputClass = 0x73636E72; /* 'scnr' */
/**
* ICC Profile Class Signature: 'mntr'.
*/
public static final int icSigDisplayClass = 0x6D6E7472; /* 'mntr' */
/**
* ICC Profile Class Signature: 'prtr'.
*/
public static final int icSigOutputClass = 0x70727472; /* 'prtr' */
/**
* ICC Profile Class Signature: 'link'.
*/
public static final int icSigLinkClass = 0x6C696E6B; /* 'link' */
/**
* ICC Profile Class Signature: 'abst'.
*/
public static final int icSigAbstractClass = 0x61627374; /* 'abst' */
/**
* ICC Profile Class Signature: 'spac'.
*/
public static final int icSigColorSpaceClass = 0x73706163; /* 'spac' */
/**
* ICC Profile Class Signature: 'nmcl'.
*/
public static final int icSigNamedColorClass = 0x6e6d636c; /* 'nmcl' */
/**
* ICC Profile Rendering Intent: Perceptual.
*/
public static final int icPerceptual = 0;
/**
* ICC Profile Rendering Intent: RelativeColorimetric.
*/
public static final int icRelativeColorimetric = 1;
/**
* ICC Profile Rendering Intent: Media-RelativeColorimetric.
* @since 1.5
*/
public static final int icMediaRelativeColorimetric = 1;
/**
* ICC Profile Rendering Intent: Saturation.
*/
public static final int icSaturation = 2;
/**
* ICC Profile Rendering Intent: AbsoluteColorimetric.
*/
public static final int icAbsoluteColorimetric = 3;
/**
* ICC Profile Rendering Intent: ICC-AbsoluteColorimetric.
* @since 1.5
*/
public static final int icICCAbsoluteColorimetric = 3;
/**
* ICC Profile Tag Signature: 'head' - special.
*/
public static final int icSigHead = 0x68656164; /* 'head' - special */
/**
* ICC Profile Tag Signature: 'A2B0'.
*/
public static final int icSigAToB0Tag = 0x41324230; /* 'A2B0' */
/**
* ICC Profile Tag Signature: 'A2B1'.
*/
public static final int icSigAToB1Tag = 0x41324231; /* 'A2B1' */
/**
* ICC Profile Tag Signature: 'A2B2'.
*/
public static final int icSigAToB2Tag = 0x41324232; /* 'A2B2' */
/**
* ICC Profile Tag Signature: 'bXYZ'.
*/
public static final int icSigBlueColorantTag = 0x6258595A; /* 'bXYZ' */
/**
* ICC Profile Tag Signature: 'bXYZ'.
* @since 1.5
*/
public static final int icSigBlueMatrixColumnTag = 0x6258595A; /* 'bXYZ' */
/**
* ICC Profile Tag Signature: 'bTRC'.
*/
public static final int icSigBlueTRCTag = 0x62545243; /* 'bTRC' */
/**
* ICC Profile Tag Signature: 'B2A0'.
*/
public static final int icSigBToA0Tag = 0x42324130; /* 'B2A0' */
/**
* ICC Profile Tag Signature: 'B2A1'.
*/
public static final int icSigBToA1Tag = 0x42324131; /* 'B2A1' */
/**
* ICC Profile Tag Signature: 'B2A2'.
*/
public static final int icSigBToA2Tag = 0x42324132; /* 'B2A2' */
/**
* ICC Profile Tag Signature: 'calt'.
*/
public static final int icSigCalibrationDateTimeTag = 0x63616C74;
/* 'calt' */
/**
* ICC Profile Tag Signature: 'targ'.
*/
public static final int icSigCharTargetTag = 0x74617267; /* 'targ' */
/**
* ICC Profile Tag Signature: 'cprt'.
*/
public static final int icSigCopyrightTag = 0x63707274; /* 'cprt' */
/**
* ICC Profile Tag Signature: 'crdi'.
*/
public static final int icSigCrdInfoTag = 0x63726469; /* 'crdi' */
/**
* ICC Profile Tag Signature: 'dmnd'.
*/
public static final int icSigDeviceMfgDescTag = 0x646D6E64; /* 'dmnd' */
/**
* ICC Profile Tag Signature: 'dmdd'.
*/
public static final int icSigDeviceModelDescTag = 0x646D6464; /* 'dmdd' */
/**
* ICC Profile Tag Signature: 'devs'.
*/
public static final int icSigDeviceSettingsTag = 0x64657673; /* 'devs' */
/**
* ICC Profile Tag Signature: 'gamt'.
*/
public static final int icSigGamutTag = 0x67616D74; /* 'gamt' */
/**
* ICC Profile Tag Signature: 'kTRC'.
*/
public static final int icSigGrayTRCTag = 0x6b545243; /* 'kTRC' */
/**
* ICC Profile Tag Signature: 'gXYZ'.
*/
public static final int icSigGreenColorantTag = 0x6758595A; /* 'gXYZ' */
/**
* ICC Profile Tag Signature: 'gXYZ'.
* @since 1.5
*/
public static final int icSigGreenMatrixColumnTag = 0x6758595A;/* 'gXYZ' */
/**
* ICC Profile Tag Signature: 'gTRC'.
*/
public static final int icSigGreenTRCTag = 0x67545243; /* 'gTRC' */
/**
* ICC Profile Tag Signature: 'lumi'.
*/
public static final int icSigLuminanceTag = 0x6C756d69; /* 'lumi' */
/**
* ICC Profile Tag Signature: 'meas'.
*/
public static final int icSigMeasurementTag = 0x6D656173; /* 'meas' */
/**
* ICC Profile Tag Signature: 'bkpt'.
*/
public static final int icSigMediaBlackPointTag = 0x626B7074; /* 'bkpt' */
/**
* ICC Profile Tag Signature: 'wtpt'.
*/
public static final int icSigMediaWhitePointTag = 0x77747074; /* 'wtpt' */
/**
* ICC Profile Tag Signature: 'ncl2'.
*/
public static final int icSigNamedColor2Tag = 0x6E636C32; /* 'ncl2' */
/**
* ICC Profile Tag Signature: 'resp'.
*/
public static final int icSigOutputResponseTag = 0x72657370; /* 'resp' */
/**
* ICC Profile Tag Signature: 'pre0'.
*/
public static final int icSigPreview0Tag = 0x70726530; /* 'pre0' */
/**
* ICC Profile Tag Signature: 'pre1'.
*/
public static final int icSigPreview1Tag = 0x70726531; /* 'pre1' */
/**
* ICC Profile Tag Signature: 'pre2'.
*/
public static final int icSigPreview2Tag = 0x70726532; /* 'pre2' */
/**
* ICC Profile Tag Signature: 'desc'.
*/
public static final int icSigProfileDescriptionTag = 0x64657363;
/* 'desc' */
/**
* ICC Profile Tag Signature: 'pseq'.
*/
public static final int icSigProfileSequenceDescTag = 0x70736571;
/* 'pseq' */
/**
* ICC Profile Tag Signature: 'psd0'.
*/
public static final int icSigPs2CRD0Tag = 0x70736430; /* 'psd0' */
/**
* ICC Profile Tag Signature: 'psd1'.
*/
public static final int icSigPs2CRD1Tag = 0x70736431; /* 'psd1' */
/**
* ICC Profile Tag Signature: 'psd2'.
*/
public static final int icSigPs2CRD2Tag = 0x70736432; /* 'psd2' */
/**
* ICC Profile Tag Signature: 'psd3'.
*/
public static final int icSigPs2CRD3Tag = 0x70736433; /* 'psd3' */
/**
* ICC Profile Tag Signature: 'ps2s'.
*/
public static final int icSigPs2CSATag = 0x70733273; /* 'ps2s' */
/**
* ICC Profile Tag Signature: 'ps2i'.
*/
public static final int icSigPs2RenderingIntentTag = 0x70733269;
/* 'ps2i' */
/**
* ICC Profile Tag Signature: 'rXYZ'.
*/
public static final int icSigRedColorantTag = 0x7258595A; /* 'rXYZ' */
/**
* ICC Profile Tag Signature: 'rXYZ'.
* @since 1.5
*/
public static final int icSigRedMatrixColumnTag = 0x7258595A; /* 'rXYZ' */
/**
* ICC Profile Tag Signature: 'rTRC'.
*/
public static final int icSigRedTRCTag = 0x72545243; /* 'rTRC' */
/**
* ICC Profile Tag Signature: 'scrd'.
*/
public static final int icSigScreeningDescTag = 0x73637264; /* 'scrd' */
/**
* ICC Profile Tag Signature: 'scrn'.
*/
public static final int icSigScreeningTag = 0x7363726E; /* 'scrn' */
/**
* ICC Profile Tag Signature: 'tech'.
*/
public static final int icSigTechnologyTag = 0x74656368; /* 'tech' */
/**
* ICC Profile Tag Signature: 'bfd '.
*/
public static final int icSigUcrBgTag = 0x62666420; /* 'bfd ' */
/**
* ICC Profile Tag Signature: 'vued'.
*/
public static final int icSigViewingCondDescTag = 0x76756564; /* 'vued' */
/**
* ICC Profile Tag Signature: 'view'.
*/
public static final int icSigViewingConditionsTag = 0x76696577;/* 'view' */
/**
* ICC Profile Tag Signature: 'chrm'.
*/
public static final int icSigChromaticityTag = 0x6368726d; /* 'chrm' */
/**
* ICC Profile Tag Signature: 'chad'.
* @since 1.5
*/
public static final int icSigChromaticAdaptationTag = 0x63686164;/* 'chad' */
/**
* ICC Profile Tag Signature: 'clro'.
* @since 1.5
*/
public static final int icSigColorantOrderTag = 0x636C726F; /* 'clro' */
/**
* ICC Profile Tag Signature: 'clrt'.
* @since 1.5
*/
public static final int icSigColorantTableTag = 0x636C7274; /* 'clrt' */
/**
* ICC Profile Header Location: profile size in bytes.
*/
public static final int icHdrSize = 0; /* Profile size in bytes */
/**
* ICC Profile Header Location: CMM for this profile.
*/
public static final int icHdrCmmId = 4; /* CMM for this profile */
/**
* ICC Profile Header Location: format version number.
*/
public static final int icHdrVersion = 8; /* Format version number */
/**
* ICC Profile Header Location: type of profile.
*/
public static final int icHdrDeviceClass = 12; /* Type of profile */
/**
* ICC Profile Header Location: color space of data.
*/
public static final int icHdrColorSpace = 16; /* Color space of data */
/**
* ICC Profile Header Location: PCS - XYZ or Lab only.
*/
public static final int icHdrPcs = 20; /* PCS - XYZ or Lab only */
/**
* ICC Profile Header Location: date profile was created.
*/
public static final int icHdrDate = 24; /* Date profile was created */
/**
* ICC Profile Header Location: icMagicNumber.
*/
public static final int icHdrMagic = 36; /* icMagicNumber */
/**
* ICC Profile Header Location: primary platform.
*/
public static final int icHdrPlatform = 40; /* Primary Platform */
/**
* ICC Profile Header Location: various bit settings.
*/
public static final int icHdrFlags = 44; /* Various bit settings */
/**
* ICC Profile Header Location: device manufacturer.
*/
public static final int icHdrManufacturer = 48; /* Device manufacturer */
/**
* ICC Profile Header Location: device model number.
*/
public static final int icHdrModel = 52; /* Device model number */
/**
* ICC Profile Header Location: device attributes.
*/
public static final int icHdrAttributes = 56; /* Device attributes */
/**
* ICC Profile Header Location: rendering intent.
*/
public static final int icHdrRenderingIntent = 64; /* Rendering intent */
/**
* ICC Profile Header Location: profile illuminant.
*/
public static final int icHdrIlluminant = 68; /* Profile illuminant */
/**
* ICC Profile Header Location: profile creator.
*/
public static final int icHdrCreator = 80; /* Profile creator */
/**
* ICC Profile Header Location: profile's ID.
* @since 1.5
*/
public static final int icHdrProfileID = 84; /* Profile's ID */
/**
* ICC Profile Constant: tag type signaturE.
*/
public static final int icTagType = 0; /* tag type signature */
/**
* ICC Profile Constant: reserved.
*/
public static final int icTagReserved = 4; /* reserved */
/**
* ICC Profile Constant: curveType count.
*/
public static final int icCurveCount = 8; /* curveType count */
/**
* ICC Profile Constant: curveType data.
*/
public static final int icCurveData = 12; /* curveType data */
/**
* ICC Profile Constant: XYZNumber X.
*/
public static final int icXYZNumberX = 8; /* XYZNumber X */
/**
* Constructs an ICC_Profile object with a given ID.
*/
ICC_Profile(Profile p) {
this.cmmProfile = p;
}
/**
* Constructs an ICC_Profile object whose loading will be deferred.
* The ID will be 0 until the profile is loaded.
*/
ICC_Profile(ProfileDeferralInfo pdi) {
this.deferralInfo = pdi;
this.profileActivator = new ProfileActivator() {
public void activate() throws ProfileDataException {
activateDeferredProfile();
}
};
ProfileDeferralMgr.registerDeferral(this.profileActivator);
}
/**
* Frees the resources associated with an ICC_Profile object.
*/
protected void finalize () {
if (cmmProfile != null) {
CMSManager.getModule().freeProfile(cmmProfile);
} else if (profileActivator != null) {
ProfileDeferralMgr.unregisterDeferral(profileActivator);
}
}
/**
* Constructs an ICC_Profile object corresponding to the data in
* a byte array. Throws an IllegalArgumentException if the data
* does not correspond to a valid ICC Profile.
* @param data the specified ICC Profile data
* @return an <code>ICC_Profile</code> object corresponding to
* the data in the specified <code>data</code> array.
*/
public static ICC_Profile getInstance(byte[] data) {
ICC_Profile thisProfile;
Profile p = null;
if (ProfileDeferralMgr.deferring) {
ProfileDeferralMgr.activateProfiles();
}
ProfileDataVerifier.verify(data);
try {
p = CMSManager.getModule().loadProfile(data);
} catch (CMMException c) {
throw new IllegalArgumentException("Invalid ICC Profile Data");
}
try {
if ((getColorSpaceType (p) == ColorSpace.TYPE_GRAY) &&
(getData (p, icSigMediaWhitePointTag) != null) &&
(getData (p, icSigGrayTRCTag) != null)) {
thisProfile = new ICC_ProfileGray (p);
}
else if ((getColorSpaceType (p) == ColorSpace.TYPE_RGB) &&
(getData (p, icSigMediaWhitePointTag) != null) &&
(getData (p, icSigRedColorantTag) != null) &&
(getData (p, icSigGreenColorantTag) != null) &&
(getData (p, icSigBlueColorantTag) != null) &&
(getData (p, icSigRedTRCTag) != null) &&
(getData (p, icSigGreenTRCTag) != null) &&
(getData (p, icSigBlueTRCTag) != null)) {
thisProfile = new ICC_ProfileRGB (p);
}
else {
thisProfile = new ICC_Profile (p);
}
} catch (CMMException c) {
thisProfile = new ICC_Profile (p);
}
return thisProfile;
}
/**
* Constructs an ICC_Profile corresponding to one of the specific color
* spaces defined by the ColorSpace class (for example CS_sRGB).
* Throws an IllegalArgumentException if cspace is not one of the
* defined color spaces.
*
* @param cspace the type of color space to create a profile for.
* The specified type is one of the color
* space constants defined in the <CODE>ColorSpace</CODE> class.
*
* @return an <code>ICC_Profile</code> object corresponding to
* the specified <code>ColorSpace</code> type.
* @exception IllegalArgumentException If <CODE>cspace</CODE> is not
* one of the predefined color space types.
*/
public static ICC_Profile getInstance (int cspace) {
ICC_Profile thisProfile = null;
String fileName;
switch (cspace) {
case ColorSpace.CS_sRGB:
synchronized(ICC_Profile.class) {
if (sRGBprofile == null) {
/*
* Deferral is only used for standard profiles.
* Enabling the appropriate access privileges is handled
* at a lower level.
*/
ProfileDeferralInfo pInfo =
new ProfileDeferralInfo("sRGB.pf",
ColorSpace.TYPE_RGB, 3,
CLASS_DISPLAY);
sRGBprofile = getDeferredInstance(pInfo);
}
thisProfile = sRGBprofile;
}
break;
case ColorSpace.CS_CIEXYZ:
synchronized(ICC_Profile.class) {
if (XYZprofile == null) {
ProfileDeferralInfo pInfo =
new ProfileDeferralInfo("CIEXYZ.pf",
ColorSpace.TYPE_XYZ, 3,
CLASS_DISPLAY);
XYZprofile = getDeferredInstance(pInfo);
}
thisProfile = XYZprofile;
}
break;
case ColorSpace.CS_PYCC:
synchronized(ICC_Profile.class) {
if (PYCCprofile == null) {
if (standardProfileExists("PYCC.pf"))
{
ProfileDeferralInfo pInfo =
new ProfileDeferralInfo("PYCC.pf",
ColorSpace.TYPE_3CLR, 3,
CLASS_DISPLAY);
PYCCprofile = getDeferredInstance(pInfo);
} else {
throw new IllegalArgumentException(
"Can't load standard profile: PYCC.pf");
}
}
thisProfile = PYCCprofile;
}
break;
case ColorSpace.CS_GRAY:
synchronized(ICC_Profile.class) {
if (GRAYprofile == null) {
ProfileDeferralInfo pInfo =
new ProfileDeferralInfo("GRAY.pf",
ColorSpace.TYPE_GRAY, 1,
CLASS_DISPLAY);
GRAYprofile = getDeferredInstance(pInfo);
}
thisProfile = GRAYprofile;
}
break;
case ColorSpace.CS_LINEAR_RGB:
synchronized(ICC_Profile.class) {
if (LINEAR_RGBprofile == null) {
ProfileDeferralInfo pInfo =
new ProfileDeferralInfo("LINEAR_RGB.pf",
ColorSpace.TYPE_RGB, 3,
CLASS_DISPLAY);
LINEAR_RGBprofile = getDeferredInstance(pInfo);
}
thisProfile = LINEAR_RGBprofile;
}
break;
default:
throw new IllegalArgumentException("Unknown color space");
}
return thisProfile;
}
/* This asserts system privileges, so is used only for the
* standard profiles.
*/
private static ICC_Profile getStandardProfile(final String name) {
return AccessController.doPrivileged(
new PrivilegedAction<ICC_Profile>() {
public ICC_Profile run() {
ICC_Profile p = null;
try {
p = getInstance (name);
} catch (IOException ex) {
throw new IllegalArgumentException(
"Can't load standard profile: " + name);
}
return p;
}
});
}
/**
* Constructs an ICC_Profile corresponding to the data in a file.
* fileName may be an absolute or a relative file specification.
* Relative file names are looked for in several places: first, relative
* to any directories specified by the java.iccprofile.path property;
* second, relative to any directories specified by the java.class.path
* property; finally, in a directory used to store profiles always
* available, such as the profile for sRGB. Built-in profiles use .pf as
* the file name extension for profiles, e.g. sRGB.pf.
* This method throws an IOException if the specified file cannot be
* opened or if an I/O error occurs while reading the file. It throws
* an IllegalArgumentException if the file does not contain valid ICC
* Profile data.
* @param fileName The file that contains the data for the profile.
*
* @return an <code>ICC_Profile</code> object corresponding to
* the data in the specified file.
* @exception IOException If the specified file cannot be opened or
* an I/O error occurs while reading the file.
*
* @exception IllegalArgumentException If the file does not
* contain valid ICC Profile data.
*
* @exception SecurityException If a security manager is installed
* and it does not permit read access to the given file.
*/
public static ICC_Profile getInstance(String fileName) throws IOException {
ICC_Profile thisProfile;
FileInputStream fis = null;
File f = getProfileFile(fileName);
if (f != null) {
fis = new FileInputStream(f);
}
if (fis == null) {
throw new IOException("Cannot open file " + fileName);
}
thisProfile = getInstance(fis);
fis.close(); /* close the file */
return thisProfile;
}
/**
* Constructs an ICC_Profile corresponding to the data in an InputStream.
* This method throws an IllegalArgumentException if the stream does not
* contain valid ICC Profile data. It throws an IOException if an I/O
* error occurs while reading the stream.
* @param s The input stream from which to read the profile data.
*
* @return an <CODE>ICC_Profile</CODE> object corresponding to the