55
55
import sun .java2d .cmm .CMSManager ;
56
56
import sun .java2d .cmm .PCMM ;
57
57
import sun .java2d .cmm .Profile ;
58
- import sun .java2d .cmm .ProfileActivator ;
59
58
import sun .java2d .cmm .ProfileDataVerifier ;
60
59
import sun .java2d .cmm .ProfileDeferralInfo ;
61
- import sun .java2d .cmm .ProfileDeferralMgr ;
62
60
63
61
/**
64
62
* A representation of color profile data for device independent and device
@@ -93,10 +91,8 @@ public class ICC_Profile implements Serializable {
93
91
@ Serial
94
92
private static final long serialVersionUID = -3938515861990936766L ;
95
93
96
- private transient Profile cmmProfile ;
97
-
98
- private transient ProfileDeferralInfo deferralInfo ;
99
- private transient ProfileActivator profileActivator ;
94
+ private transient volatile Profile cmmProfile ;
95
+ private transient volatile ProfileDeferralInfo deferralInfo ;
100
96
101
97
// Registry of singleton profile objects for specific color spaces
102
98
// defined in the ColorSpace class (e.g. CS_sRGB), see
@@ -731,21 +727,15 @@ public class ICC_Profile implements Serializable {
731
727
* Constructs an {@code ICC_Profile} object with a given ID.
732
728
*/
733
729
ICC_Profile (Profile p ) {
734
- this . cmmProfile = p ;
730
+ cmmProfile = p ;
735
731
}
736
732
737
733
/**
738
734
* Constructs an {@code ICC_Profile} object whose loading will be deferred.
739
735
* The ID will be 0 until the profile is loaded.
740
736
*/
741
737
ICC_Profile (ProfileDeferralInfo pdi ) {
742
- this .deferralInfo = pdi ;
743
- this .profileActivator = new ProfileActivator () {
744
- public void activate () throws ProfileDataException {
745
- activateDeferredProfile ();
746
- }
747
- };
748
- ProfileDeferralMgr .registerDeferral (this .profileActivator );
738
+ deferralInfo = pdi ;
749
739
}
750
740
751
741
/**
@@ -780,10 +770,6 @@ public static ICC_Profile getInstance(byte[] data) {
780
770
781
771
Profile p = null ;
782
772
783
- if (ProfileDeferralMgr .deferring ) {
784
- ProfileDeferralMgr .activateProfiles ();
785
- }
786
-
787
773
ProfileDataVerifier .verify (data );
788
774
789
775
try {
@@ -842,11 +828,11 @@ public static ICC_Profile getInstance (int cspace) {
842
828
* Enabling the appropriate access privileges is handled
843
829
* at a lower level.
844
830
*/
845
- ProfileDeferralInfo pInfo =
831
+ ProfileDeferralInfo pdi =
846
832
new ProfileDeferralInfo ("sRGB.pf" ,
847
833
ColorSpace .TYPE_RGB , 3 ,
848
834
CLASS_DISPLAY );
849
- sRGBprofile = getDeferredInstance ( pInfo );
835
+ sRGBprofile = new ICC_ProfileRGB ( pdi );
850
836
}
851
837
thisProfile = sRGBprofile ;
852
838
}
@@ -856,11 +842,11 @@ public static ICC_Profile getInstance (int cspace) {
856
842
case ColorSpace .CS_CIEXYZ :
857
843
synchronized (ICC_Profile .class ) {
858
844
if (XYZprofile == null ) {
859
- ProfileDeferralInfo pInfo =
845
+ ProfileDeferralInfo pdi =
860
846
new ProfileDeferralInfo ("CIEXYZ.pf" ,
861
847
ColorSpace .TYPE_XYZ , 3 ,
862
848
CLASS_ABSTRACT );
863
- XYZprofile = getDeferredInstance ( pInfo );
849
+ XYZprofile = new ICC_Profile ( pdi );
864
850
}
865
851
thisProfile = XYZprofile ;
866
852
}
@@ -870,11 +856,11 @@ public static ICC_Profile getInstance (int cspace) {
870
856
case ColorSpace .CS_PYCC :
871
857
synchronized (ICC_Profile .class ) {
872
858
if (PYCCprofile == null ) {
873
- ProfileDeferralInfo pInfo =
859
+ ProfileDeferralInfo pdi =
874
860
new ProfileDeferralInfo ("PYCC.pf" ,
875
861
ColorSpace .TYPE_3CLR , 3 ,
876
862
CLASS_COLORSPACECONVERSION );
877
- PYCCprofile = getDeferredInstance ( pInfo );
863
+ PYCCprofile = new ICC_Profile ( pdi );
878
864
}
879
865
thisProfile = PYCCprofile ;
880
866
}
@@ -884,11 +870,11 @@ public static ICC_Profile getInstance (int cspace) {
884
870
case ColorSpace .CS_GRAY :
885
871
synchronized (ICC_Profile .class ) {
886
872
if (GRAYprofile == null ) {
887
- ProfileDeferralInfo pInfo =
873
+ ProfileDeferralInfo pdi =
888
874
new ProfileDeferralInfo ("GRAY.pf" ,
889
875
ColorSpace .TYPE_GRAY , 1 ,
890
876
CLASS_DISPLAY );
891
- GRAYprofile = getDeferredInstance ( pInfo );
877
+ GRAYprofile = new ICC_ProfileGray ( pdi );
892
878
}
893
879
thisProfile = GRAYprofile ;
894
880
}
@@ -898,11 +884,11 @@ public static ICC_Profile getInstance (int cspace) {
898
884
case ColorSpace .CS_LINEAR_RGB :
899
885
synchronized (ICC_Profile .class ) {
900
886
if (LINEAR_RGBprofile == null ) {
901
- ProfileDeferralInfo pInfo =
887
+ ProfileDeferralInfo pdi =
902
888
new ProfileDeferralInfo ("LINEAR_RGB.pf" ,
903
889
ColorSpace .TYPE_RGB , 3 ,
904
890
CLASS_DISPLAY );
905
- LINEAR_RGBprofile = getDeferredInstance ( pInfo );
891
+ LINEAR_RGBprofile = new ICC_ProfileRGB ( pdi );
906
892
}
907
893
thisProfile = LINEAR_RGBprofile ;
908
894
}
@@ -916,26 +902,6 @@ public static ICC_Profile getInstance (int cspace) {
916
902
return thisProfile ;
917
903
}
918
904
919
- /**
920
- * This method asserts system privileges, so is used only for the standard
921
- * profiles.
922
- */
923
- private static ICC_Profile getStandardProfile (final String name ) {
924
- return AccessController .doPrivileged (
925
- new PrivilegedAction <ICC_Profile >() {
926
- public ICC_Profile run () {
927
- ICC_Profile p = null ;
928
- try {
929
- p = getInstance (name );
930
- } catch (IOException ex ) {
931
- throw new IllegalArgumentException (
932
- "Can't load standard profile: " + name );
933
- }
934
- return p ;
935
- }
936
- });
937
- }
938
-
939
905
/**
940
906
* Constructs an {@code ICC_Profile} corresponding to the data in a file.
941
907
* {@code fileName} may be an absolute or a relative file specification.
@@ -997,13 +963,7 @@ public static ICC_Profile getInstance(String fileName) throws IOException {
997
963
* Profile data
998
964
*/
999
965
public static ICC_Profile getInstance (InputStream s ) throws IOException {
1000
- byte [] profileData ;
1001
-
1002
- if (s instanceof ProfileDeferralInfo ) {
1003
- /* hack to detect profiles whose loading can be deferred */
1004
- return getDeferredInstance ((ProfileDeferralInfo ) s );
1005
- }
1006
-
966
+ byte [] profileData ;
1007
967
if ((profileData = getProfileDataFromStream (s )) == null ) {
1008
968
throw new IllegalArgumentException ("Invalid ICC Profile Data" );
1009
969
}
@@ -1035,61 +995,32 @@ static byte[] getProfileDataFromStream(InputStream s) throws IOException {
1035
995
}
1036
996
1037
997
/**
1038
- * Constructs an {@code ICC_Profile} for which the actual loading of the
1039
- * profile data from a file and the initialization of the CMM should be
1040
- * deferred as long as possible. Deferral is only used for standard
1041
- * profiles. If deferring is disabled, then getStandardProfile() ensures
1042
- * that all of the appropriate access privileges are granted when loading
1043
- * this profile. If deferring is enabled, then the deferred activation code
1044
- * will take care of access privileges.
1045
- *
1046
- * @see #activateDeferredProfile()
998
+ * Activates the deferred standard profiles. Implementation of this method
999
+ * mimics the old behaviour when the CMMException and IOException were
1000
+ * wrapped by the ProfileDataException, and the ProfileDataException itself
1001
+ * was ignored during activation.
1047
1002
*/
1048
- static ICC_Profile getDeferredInstance (ProfileDeferralInfo pdi ) {
1049
- if (!ProfileDeferralMgr .deferring ) {
1050
- return getStandardProfile (pdi .filename );
1051
- }
1052
- if (pdi .colorSpaceType == ColorSpace .TYPE_RGB ) {
1053
- return new ICC_ProfileRGB (pdi );
1054
- } else if (pdi .colorSpaceType == ColorSpace .TYPE_GRAY ) {
1055
- return new ICC_ProfileGray (pdi );
1056
- } else {
1057
- return new ICC_Profile (pdi );
1058
- }
1059
- }
1060
-
1061
-
1062
- void activateDeferredProfile () throws ProfileDataException {
1063
- byte [] profileData ;
1064
- final String fileName = deferralInfo .filename ;
1065
-
1066
- profileActivator = null ;
1067
- deferralInfo = null ;
1068
- InputStream is = getStandardProfileInputStream (fileName );
1069
- if (is == null ) {
1070
- throw new ProfileDataException ("Cannot open file " + fileName );
1071
- }
1072
- try {
1073
- profileData = getProfileDataFromStream (is );
1074
- is .close (); /* close the file */
1075
- }
1076
- catch (IOException e ) {
1077
- ProfileDataException pde = new
1078
- ProfileDataException ("Invalid ICC Profile Data" + fileName );
1079
- pde .initCause (e );
1080
- throw pde ;
1081
- }
1082
- if (profileData == null ) {
1083
- throw new ProfileDataException ("Invalid ICC Profile Data" +
1084
- fileName );
1085
- }
1086
- try {
1087
- cmmProfile = CMSManager .getModule ().loadProfile (profileData );
1088
- } catch (CMMException c ) {
1089
- ProfileDataException pde = new
1090
- ProfileDataException ("Invalid ICC Profile Data" + fileName );
1091
- pde .initCause (c );
1092
- throw pde ;
1003
+ private void activate () {
1004
+ if (cmmProfile == null ) {
1005
+ synchronized (this ) {
1006
+ if (cmmProfile != null ) {
1007
+ return ;
1008
+ }
1009
+ var is = getStandardProfileInputStream (deferralInfo .filename );
1010
+ if (is == null ) {
1011
+ return ;
1012
+ }
1013
+ try {
1014
+ byte [] data = getProfileDataFromStream (is );
1015
+ if (data != null ) {
1016
+ cmmProfile = CMSManager .getModule ().loadProfile (data );
1017
+ // from now we cannot use the deferred value, drop it
1018
+ deferralInfo = null ;
1019
+ }
1020
+ is .close (); /* close the stream */
1021
+ } catch (CMMException | IOException ignore ) {
1022
+ }
1023
+ }
1093
1024
}
1094
1025
}
1095
1026
@@ -1130,11 +1061,9 @@ public int getProfileClass() {
1130
1061
byte [] theHeader ;
1131
1062
int theClassSig , theClass ;
1132
1063
1133
- if (deferralInfo != null ) {
1134
- return deferralInfo .profileClass ; /* Need to have this info for
1135
- ICC_ColorSpace without
1136
- causing a deferred profile
1137
- to be loaded */
1064
+ ProfileDeferralInfo info = deferralInfo ;
1065
+ if (info != null ) {
1066
+ return info .profileClass ;
1138
1067
}
1139
1068
1140
1069
theHeader = getData (icSigHead );
@@ -1190,12 +1119,11 @@ public int getProfileClass() {
1190
1119
* {@code ColorSpace} class
1191
1120
*/
1192
1121
public int getColorSpaceType () {
1193
- if (deferralInfo != null ) {
1194
- return deferralInfo .colorSpaceType ; /* Need to have this info for
1195
- ICC_ColorSpace without
1196
- causing a deferred profile
1197
- to be loaded */
1122
+ ProfileDeferralInfo info = deferralInfo ;
1123
+ if (info != null ) {
1124
+ return info .colorSpaceType ;
1198
1125
}
1126
+ activate ();
1199
1127
return getColorSpaceType (cmmProfile );
1200
1128
}
1201
1129
@@ -1223,9 +1151,7 @@ static int getColorSpaceType(Profile p) {
1223
1151
* {@code ColorSpace} class
1224
1152
*/
1225
1153
public int getPCSType () {
1226
- if (ProfileDeferralMgr .deferring ) {
1227
- ProfileDeferralMgr .activateProfiles ();
1228
- }
1154
+ activate ();
1229
1155
return getPCSType (cmmProfile );
1230
1156
}
1231
1157
@@ -1283,9 +1209,7 @@ public byte[] getData() {
1283
1209
int profileSize ;
1284
1210
byte [] profileData ;
1285
1211
1286
- if (ProfileDeferralMgr .deferring ) {
1287
- ProfileDeferralMgr .activateProfiles ();
1288
- }
1212
+ activate ();
1289
1213
1290
1214
PCMM mdl = CMSManager .getModule ();
1291
1215
@@ -1315,9 +1239,7 @@ public byte[] getData() {
1315
1239
*/
1316
1240
public byte [] getData (int tagSignature ) {
1317
1241
1318
- if (ProfileDeferralMgr .deferring ) {
1319
- ProfileDeferralMgr .activateProfiles ();
1320
- }
1242
+ activate ();
1321
1243
1322
1244
return getData (cmmProfile , tagSignature );
1323
1245
}
@@ -1363,9 +1285,7 @@ static byte[] getData(Profile p, int tagSignature) {
1363
1285
*/
1364
1286
public void setData (int tagSignature , byte [] tagData ) {
1365
1287
1366
- if (ProfileDeferralMgr .deferring ) {
1367
- ProfileDeferralMgr .activateProfiles ();
1368
- }
1288
+ activate ();
1369
1289
1370
1290
CMSManager .getModule ().setTagData (cmmProfile , tagSignature , tagData );
1371
1291
}
@@ -1417,11 +1337,9 @@ public int getNumComponents() {
1417
1337
byte [] theHeader ;
1418
1338
int theColorSpaceSig , theNumComponents ;
1419
1339
1420
- if (deferralInfo != null ) {
1421
- return deferralInfo .numComponents ; /* Need to have this info for
1422
- ICC_ColorSpace without
1423
- causing a deferred profile
1424
- to be loaded */
1340
+ ProfileDeferralInfo info = deferralInfo ;
1341
+ if (info != null ) {
1342
+ return info .numComponents ;
1425
1343
}
1426
1344
theHeader = getData (icSigHead );
1427
1345
0 commit comments