@@ -94,14 +94,31 @@ public class ICC_Profile implements Serializable {
94
94
private transient volatile Profile cmmProfile ;
95
95
private transient volatile ProfileDeferralInfo deferralInfo ;
96
96
97
- // Registry of singleton profile objects for specific color spaces
98
- // defined in the ColorSpace class (e.g. CS_sRGB), see
99
- // getInstance(int cspace) factory method.
100
- private static ICC_Profile sRGBprofile ;
101
- private static ICC_Profile XYZprofile ;
102
- private static ICC_Profile PYCCprofile ;
103
- private static ICC_Profile GRAYprofile ;
104
- private static ICC_Profile LINEAR_RGBprofile ;
97
+ /**
98
+ * The lazy registry of singleton profile objects for specific built-in
99
+ * color spaces defined in the ColorSpace class (e.g. CS_sRGB),
100
+ * see getInstance(int cspace) factory method.
101
+ */
102
+ private interface BuiltInProfile {
103
+ /*
104
+ * Deferral is only used for standard profiles. Enabling the appropriate
105
+ * access privileges is handled at a lower level.
106
+ */
107
+ ICC_Profile SRGB = new ICC_ProfileRGB (new ProfileDeferralInfo (
108
+ "sRGB.pf" , ColorSpace .TYPE_RGB , 3 , CLASS_DISPLAY ));
109
+
110
+ ICC_Profile LRGB = new ICC_ProfileRGB (new ProfileDeferralInfo (
111
+ "LINEAR_RGB.pf" , ColorSpace .TYPE_RGB , 3 , CLASS_DISPLAY ));
112
+
113
+ ICC_Profile XYZ = new ICC_Profile (new ProfileDeferralInfo (
114
+ "CIEXYZ.pf" , ColorSpace .TYPE_XYZ , 3 , CLASS_ABSTRACT ));
115
+
116
+ ICC_Profile PYCC = new ICC_Profile (new ProfileDeferralInfo (
117
+ "PYCC.pf" , ColorSpace .TYPE_3CLR , 3 , CLASS_COLORSPACECONVERSION ));
118
+
119
+ ICC_Profile GRAY = new ICC_ProfileGray (new ProfileDeferralInfo (
120
+ "GRAY.pf" , ColorSpace .TYPE_GRAY , 1 , CLASS_DISPLAY ));
121
+ }
105
122
106
123
/**
107
124
* Profile class is input.
@@ -818,89 +835,17 @@ else if ((getColorSpaceType (p) == ColorSpace.TYPE_RGB) &&
818
835
* @throws IllegalArgumentException If {@code cspace} is not one of the
819
836
* predefined color space types
820
837
*/
821
- public static ICC_Profile getInstance (int cspace ) {
822
- ICC_Profile thisProfile = null ;
823
- switch (cspace ) {
824
- case ColorSpace .CS_sRGB :
825
- synchronized (ICC_Profile .class ) {
826
- if (sRGBprofile == null ) {
827
- /*
828
- * Deferral is only used for standard profiles.
829
- * Enabling the appropriate access privileges is handled
830
- * at a lower level.
831
- */
832
- ProfileDeferralInfo pdi =
833
- new ProfileDeferralInfo ("sRGB.pf" ,
834
- ColorSpace .TYPE_RGB , 3 ,
835
- CLASS_DISPLAY );
836
- sRGBprofile = new ICC_ProfileRGB (pdi );
837
- }
838
- thisProfile = sRGBprofile ;
839
- }
840
-
841
- break ;
842
-
843
- case ColorSpace .CS_CIEXYZ :
844
- synchronized (ICC_Profile .class ) {
845
- if (XYZprofile == null ) {
846
- ProfileDeferralInfo pdi =
847
- new ProfileDeferralInfo ("CIEXYZ.pf" ,
848
- ColorSpace .TYPE_XYZ , 3 ,
849
- CLASS_ABSTRACT );
850
- XYZprofile = new ICC_Profile (pdi );
851
- }
852
- thisProfile = XYZprofile ;
853
- }
854
-
855
- break ;
856
-
857
- case ColorSpace .CS_PYCC :
858
- synchronized (ICC_Profile .class ) {
859
- if (PYCCprofile == null ) {
860
- ProfileDeferralInfo pdi =
861
- new ProfileDeferralInfo ("PYCC.pf" ,
862
- ColorSpace .TYPE_3CLR , 3 ,
863
- CLASS_COLORSPACECONVERSION );
864
- PYCCprofile = new ICC_Profile (pdi );
865
- }
866
- thisProfile = PYCCprofile ;
867
- }
868
-
869
- break ;
870
-
871
- case ColorSpace .CS_GRAY :
872
- synchronized (ICC_Profile .class ) {
873
- if (GRAYprofile == null ) {
874
- ProfileDeferralInfo pdi =
875
- new ProfileDeferralInfo ("GRAY.pf" ,
876
- ColorSpace .TYPE_GRAY , 1 ,
877
- CLASS_DISPLAY );
878
- GRAYprofile = new ICC_ProfileGray (pdi );
879
- }
880
- thisProfile = GRAYprofile ;
881
- }
882
-
883
- break ;
884
-
885
- case ColorSpace .CS_LINEAR_RGB :
886
- synchronized (ICC_Profile .class ) {
887
- if (LINEAR_RGBprofile == null ) {
888
- ProfileDeferralInfo pdi =
889
- new ProfileDeferralInfo ("LINEAR_RGB.pf" ,
890
- ColorSpace .TYPE_RGB , 3 ,
891
- CLASS_DISPLAY );
892
- LINEAR_RGBprofile = new ICC_ProfileRGB (pdi );
893
- }
894
- thisProfile = LINEAR_RGBprofile ;
838
+ public static ICC_Profile getInstance (int cspace ) {
839
+ return switch (cspace ) {
840
+ case ColorSpace .CS_sRGB -> BuiltInProfile .SRGB ;
841
+ case ColorSpace .CS_LINEAR_RGB -> BuiltInProfile .LRGB ;
842
+ case ColorSpace .CS_CIEXYZ -> BuiltInProfile .XYZ ;
843
+ case ColorSpace .CS_PYCC -> BuiltInProfile .PYCC ;
844
+ case ColorSpace .CS_GRAY -> BuiltInProfile .GRAY ;
845
+ default -> {
846
+ throw new IllegalArgumentException ("Unknown color space" );
895
847
}
896
-
897
- break ;
898
-
899
- default :
900
- throw new IllegalArgumentException ("Unknown color space" );
901
- }
902
-
903
- return thisProfile ;
848
+ };
904
849
}
905
850
906
851
/**
@@ -1803,15 +1748,15 @@ private void writeObject(ObjectOutputStream s)
1803
1748
s .defaultWriteObject ();
1804
1749
1805
1750
String csName = null ;
1806
- if (this == sRGBprofile ) {
1751
+ if (this == BuiltInProfile . SRGB ) {
1807
1752
csName = "CS_sRGB" ;
1808
- } else if (this == XYZprofile ) {
1753
+ } else if (this == BuiltInProfile . XYZ ) {
1809
1754
csName = "CS_CIEXYZ" ;
1810
- } else if (this == PYCCprofile ) {
1755
+ } else if (this == BuiltInProfile . PYCC ) {
1811
1756
csName = "CS_PYCC" ;
1812
- } else if (this == GRAYprofile ) {
1757
+ } else if (this == BuiltInProfile . GRAY ) {
1813
1758
csName = "CS_GRAY" ;
1814
- } else if (this == LINEAR_RGBprofile ) {
1759
+ } else if (this == BuiltInProfile . LRGB ) {
1815
1760
csName = "CS_LINEAR_RGB" ;
1816
1761
}
1817
1762
1 commit comments
openjdk-notifier[bot] commentedon Feb 11, 2021
Review
Issues