< prev index next >

src/java.desktop/share/classes/java/awt/color/ICC_Profile.java

Print this page




 749     }
 750 
 751 
 752     /**
 753      * Frees the resources associated with an ICC_Profile object.
 754      */
 755     protected void finalize () {
 756         if (cmmProfile != null) {
 757             CMSManager.getModule().freeProfile(cmmProfile);
 758         } else if (profileActivator != null) {
 759             ProfileDeferralMgr.unregisterDeferral(profileActivator);
 760         }
 761     }
 762 
 763 
 764     /**
 765      * Constructs an ICC_Profile object corresponding to the data in
 766      * a byte array.  Throws an IllegalArgumentException if the data
 767      * does not correspond to a valid ICC Profile.
 768      * @param data the specified ICC Profile data
 769      * @return an <code>ICC_Profile</code> object corresponding to
 770      *          the data in the specified <code>data</code> array.
 771      */
 772     public static ICC_Profile getInstance(byte[] data) {
 773     ICC_Profile thisProfile;
 774 
 775         Profile p = null;
 776 
 777         if (ProfileDeferralMgr.deferring) {
 778             ProfileDeferralMgr.activateProfiles();
 779         }
 780 
 781         ProfileDataVerifier.verify(data);
 782 
 783         try {
 784             p = CMSManager.getModule().loadProfile(data);
 785         } catch (CMMException c) {
 786             throw new IllegalArgumentException("Invalid ICC Profile Data");
 787         }
 788 
 789         try {
 790             if ((getColorSpaceType (p) == ColorSpace.TYPE_GRAY) &&


 804             }
 805             else {
 806                 thisProfile = new ICC_Profile (p);
 807             }
 808         } catch (CMMException c) {
 809             thisProfile = new ICC_Profile (p);
 810         }
 811         return thisProfile;
 812     }
 813 
 814 
 815 
 816     /**
 817      * Constructs an ICC_Profile corresponding to one of the specific color
 818      * spaces defined by the ColorSpace class (for example CS_sRGB).
 819      * Throws an IllegalArgumentException if cspace is not one of the
 820      * defined color spaces.
 821      *
 822      * @param cspace the type of color space to create a profile for.
 823      * The specified type is one of the color
 824      * space constants defined in the  <CODE>ColorSpace</CODE> class.
 825      *
 826      * @return an <code>ICC_Profile</code> object corresponding to
 827      *          the specified <code>ColorSpace</code> type.
 828      * @exception IllegalArgumentException If <CODE>cspace</CODE> is not
 829      * one of the predefined color space types.
 830      */
 831     public static ICC_Profile getInstance (int cspace) {
 832         ICC_Profile thisProfile = null;
 833         String fileName;
 834 
 835         switch (cspace) {
 836         case ColorSpace.CS_sRGB:
 837             synchronized(ICC_Profile.class) {
 838                 if (sRGBprofile == null) {
 839                     /*
 840                      * Deferral is only used for standard profiles.
 841                      * Enabling the appropriate access privileges is handled
 842                      * at a lower level.
 843                      */
 844                     ProfileDeferralInfo pInfo =
 845                         new ProfileDeferralInfo("sRGB.pf",
 846                                                 ColorSpace.TYPE_RGB, 3,
 847                                                 CLASS_DISPLAY);
 848                     sRGBprofile = getDeferredInstance(pInfo);


 939                      return p;
 940                  }
 941              });
 942     }
 943 
 944     /**
 945      * Constructs an ICC_Profile corresponding to the data in a file.
 946      * fileName may be an absolute or a relative file specification.
 947      * Relative file names are looked for in several places: first, relative
 948      * to any directories specified by the java.iccprofile.path property;
 949      * second, relative to any directories specified by the java.class.path
 950      * property; finally, in a directory used to store profiles always
 951      * available, such as the profile for sRGB.  Built-in profiles use .pf as
 952      * the file name extension for profiles, e.g. sRGB.pf.
 953      * This method throws an IOException if the specified file cannot be
 954      * opened or if an I/O error occurs while reading the file.  It throws
 955      * an IllegalArgumentException if the file does not contain valid ICC
 956      * Profile data.
 957      * @param fileName The file that contains the data for the profile.
 958      *
 959      * @return an <code>ICC_Profile</code> object corresponding to
 960      *          the data in the specified file.
 961      * @exception IOException If the specified file cannot be opened or
 962      * an I/O error occurs while reading the file.
 963      *
 964      * @exception IllegalArgumentException If the file does not
 965      * contain valid ICC Profile data.
 966      *
 967      * @exception SecurityException If a security manager is installed
 968      * and it does not permit read access to the given file.
 969      */
 970     public static ICC_Profile getInstance(String fileName) throws IOException {
 971         ICC_Profile thisProfile;
 972         InputStream is = null;
 973 
 974 
 975         File f = getProfileFile(fileName);
 976         if (f != null) {
 977             is = new FileInputStream(f);
 978         } else {
 979             is = getStandardProfileInputStream(fileName);
 980         }
 981         if (is == null) {
 982             throw new IOException("Cannot open file " + fileName);
 983         }
 984 
 985         thisProfile = getInstance(is);
 986 
 987         is.close();    /* close the file */
 988 
 989         return thisProfile;
 990     }
 991 
 992 
 993     /**
 994      * Constructs an ICC_Profile corresponding to the data in an InputStream.
 995      * This method throws an IllegalArgumentException if the stream does not
 996      * contain valid ICC Profile data.  It throws an IOException if an I/O
 997      * error occurs while reading the stream.
 998      * @param s The input stream from which to read the profile data.
 999      *
1000      * @return an <CODE>ICC_Profile</CODE> object corresponding to the
1001      *     data in the specified <code>InputStream</code>.
1002      *
1003      * @exception IOException If an I/O error occurs while reading the stream.
1004      *
1005      * @exception IllegalArgumentException If the stream does not
1006      * contain valid ICC Profile data.
1007      */
1008     public static ICC_Profile getInstance(InputStream s) throws IOException {
1009     byte profileData[];
1010 
1011         if (s instanceof ProfileDeferralInfo) {
1012             /* hack to detect profiles whose loading can be deferred */
1013             return getDeferredInstance((ProfileDeferralInfo) s);
1014         }
1015 
1016         if ((profileData = getProfileDataFromStream(s)) == null) {
1017             throw new IllegalArgumentException("Invalid ICC Profile Data");
1018         }
1019 
1020         return getInstance(profileData);
1021     }


1196             theClass = CLASS_NAMEDCOLOR;
1197             break;
1198 
1199         default:
1200             throw new IllegalArgumentException("Unknown profile class");
1201         }
1202 
1203         return theClass;
1204     }
1205 
1206     /**
1207      * Returns the color space type.  Returns one of the color space type
1208      * constants defined by the ColorSpace class.  This is the
1209      * "input" color space of the profile.  The type defines the
1210      * number of components of the color space and the interpretation,
1211      * e.g. TYPE_RGB identifies a color space with three components - red,
1212      * green, and blue.  It does not define the particular color
1213      * characteristics of the space, e.g. the chromaticities of the
1214      * primaries.
1215      * @return One of the color space type constants defined in the
1216      * <CODE>ColorSpace</CODE> class.
1217      */
1218     public int getColorSpaceType() {
1219         if (deferralInfo != null) {
1220             return deferralInfo.colorSpaceType; /* Need to have this info for
1221                                                    ICC_ColorSpace without
1222                                                    causing a deferred profile
1223                                                    to be loaded */
1224         }
1225         return    getColorSpaceType(cmmProfile);
1226     }
1227 
1228     static int getColorSpaceType(Profile p) {
1229     byte[] theHeader;
1230     int theColorSpaceSig, theColorSpace;
1231 
1232         theHeader = getData(p, icSigHead);
1233         theColorSpaceSig = intFromBigEndian(theHeader, icHdrColorSpace);
1234         theColorSpace = iccCStoJCS (theColorSpaceSig);
1235         return theColorSpace;
1236     }
1237 
1238     /**
1239      * Returns the color space type of the Profile Connection Space (PCS).
1240      * Returns one of the color space type constants defined by the
1241      * ColorSpace class.  This is the "output" color space of the
1242      * profile.  For an input, display, or output profile useful
1243      * for tagging colors or images, this will be either TYPE_XYZ or
1244      * TYPE_Lab and should be interpreted as the corresponding specific
1245      * color space defined in the ICC specification.  For a device
1246      * link profile, this could be any of the color space type constants.
1247      * @return One of the color space type constants defined in the
1248      * <CODE>ColorSpace</CODE> class.
1249      */
1250     public int getPCSType() {
1251         if (ProfileDeferralMgr.deferring) {
1252             ProfileDeferralMgr.activateProfiles();
1253         }
1254         return getPCSType(cmmProfile);
1255     }
1256 
1257 
1258     static int getPCSType(Profile p) {
1259     byte[] theHeader;
1260     int thePCSSig, thePCS;
1261 
1262         theHeader = getData(p, icSigHead);
1263         thePCSSig = intFromBigEndian(theHeader, icHdrPcs);
1264         thePCS = iccCStoJCS(thePCSSig);
1265         return thePCS;
1266     }
1267 
1268 


1325 
1326         /* get the data for the profile */
1327         mdl.getProfileData(cmmProfile, profileData);
1328 
1329         return profileData;
1330     }
1331 
1332 
1333     /**
1334      * Returns a particular tagged data element from the profile as
1335      * a byte array.  Elements are identified by signatures
1336      * as defined in the ICC specification.  The signature
1337      * icSigHead can be used to get the header.  This method is useful
1338      * for advanced applets or applications which need to access
1339      * profile data directly.
1340      *
1341      * @param tagSignature The ICC tag signature for the data element you
1342      * want to get.
1343      *
1344      * @return A byte array that contains the tagged data element. Returns
1345      * <code>null</code> if the specified tag doesn't exist.
1346      * @see #setData(int, byte[])
1347      */
1348     public byte[] getData(int tagSignature) {
1349 
1350         if (ProfileDeferralMgr.deferring) {
1351             ProfileDeferralMgr.activateProfiles();
1352         }
1353 
1354         return getData(cmmProfile, tagSignature);
1355     }
1356 
1357 
1358     static byte[] getData(Profile p, int tagSignature) {
1359     int tagSize;
1360     byte[] tagData;
1361 
1362         try {
1363             PCMM mdl = CMSManager.getModule();
1364 
1365             /* get the number of bytes needed for this tag */


1912      *
1913      * There are two primary factory methods for construction of ICC
1914      * profiles: getInstance(int cspace) and getInstance(byte[] data).
1915      * This implementation of ICC_Profile uses the former to return a
1916      * cached singleton profile object, other implementations will
1917      * likely use this technique too.  To preserve the singleton
1918      * pattern across serialization we serialize cached singleton
1919      * profiles in such a way that deserializing VM could call
1920      * getInstance(int cspace) method that will resolve deserialized
1921      * object into the corresponding singleton as well.
1922      *
1923      * Since the singletons are private to ICC_Profile the readResolve
1924      * method have to be `protected' instead of `private' so that
1925      * singletons that are instances of subclasses of ICC_Profile
1926      * could be correctly deserialized.
1927      */
1928 
1929 
1930     /**
1931      * Version of the format of additional serialized data in the
1932      * stream.  Version&nbsp;<code>1</code> corresponds to Java&nbsp;2
1933      * Platform,&nbsp;v1.3.
1934      * @since 1.3
1935      * @serial
1936      */
1937     private int iccProfileSerializedDataVersion = 1;
1938 
1939 
1940     /**
1941      * Writes default serializable fields to the stream.  Writes a
1942      * string and an array of bytes to the stream as additional data.
1943      *
1944      * @param s stream used for serialization.
1945      * @throws IOException
1946      *     thrown by <code>ObjectInputStream</code>.
1947      * @serialData
1948      *     The <code>String</code> is the name of one of
1949      *     <code>CS_<var>*</var></code> constants defined in the
1950      *     {@link ColorSpace} class if the profile object is a profile
1951      *     for a predefined color space (for example
1952      *     <code>"CS_sRGB"</code>).  The string is <code>null</code>
1953      *     otherwise.
1954      *     <p>
1955      *     The <code>byte[]</code> array is the profile data for the
1956      *     profile.  For predefined color spaces <code>null</code> is
1957      *     written instead of the profile data.  If in the future
1958      *     versions of Java API new predefined color spaces will be
1959      *     added, future versions of this class may choose to write
1960      *     for new predefined color spaces not only the color space
1961      *     name, but the profile data as well so that older versions
1962      *     could still deserialize the object.
1963      */
1964     private void writeObject(ObjectOutputStream s)
1965       throws IOException
1966     {
1967         s.defaultWriteObject();
1968 
1969         String csName = null;
1970         if (this == sRGBprofile) {
1971             csName = "CS_sRGB";
1972         } else if (this == XYZprofile) {
1973             csName = "CS_CIEXYZ";
1974         } else if (this == PYCCprofile) {
1975             csName = "CS_PYCC";
1976         } else if (this == GRAYprofile) {


1986         byte[] data = null;
1987         if (csName == null) {
1988             // getData will activate deferred profile if necessary
1989             data = getData();
1990         }
1991 
1992         s.writeObject(csName);
1993         s.writeObject(data);
1994     }
1995 
1996     // Temporary storage used by readObject to store resolved profile
1997     // (obtained with getInstance) for readResolve to return.
1998     private transient ICC_Profile resolvedDeserializedProfile;
1999 
2000     /**
2001      * Reads default serializable fields from the stream.  Reads from
2002      * the stream a string and an array of bytes as additional data.
2003      *
2004      * @param s stream used for deserialization.
2005      * @throws IOException
2006      *     thrown by <code>ObjectInputStream</code>.
2007      * @throws ClassNotFoundException
2008      *     thrown by <code>ObjectInputStream</code>.
2009      * @serialData
2010      *     The <code>String</code> is the name of one of
2011      *     <code>CS_<var>*</var></code> constants defined in the
2012      *     {@link ColorSpace} class if the profile object is a profile
2013      *     for a predefined color space (for example
2014      *     <code>"CS_sRGB"</code>).  The string is <code>null</code>
2015      *     otherwise.
2016      *     <p>
2017      *     The <code>byte[]</code> array is the profile data for the
2018      *     profile.  It will usually be <code>null</code> for the
2019      *     predefined profiles.
2020      *     <p>
2021      *     If the string is recognized as a constant name for
2022      *     predefined color space the object will be resolved into
2023      *     profile obtained with
2024      *     <code>getInstance(int&nbsp;cspace)</code> and the profile
2025      *     data are ignored.  Otherwise the object will be resolved
2026      *     into profile obtained with
2027      *     <code>getInstance(byte[]&nbsp;data)</code>.
2028      * @see #readResolve()
2029      * @see #getInstance(int)
2030      * @see #getInstance(byte[])
2031      */
2032     private void readObject(ObjectInputStream s)
2033       throws IOException, ClassNotFoundException
2034     {
2035         s.defaultReadObject();
2036 
2037         String csName = (String)s.readObject();
2038         byte[] data = (byte[])s.readObject();




 749     }
 750 
 751 
 752     /**
 753      * Frees the resources associated with an ICC_Profile object.
 754      */
 755     protected void finalize () {
 756         if (cmmProfile != null) {
 757             CMSManager.getModule().freeProfile(cmmProfile);
 758         } else if (profileActivator != null) {
 759             ProfileDeferralMgr.unregisterDeferral(profileActivator);
 760         }
 761     }
 762 
 763 
 764     /**
 765      * Constructs an ICC_Profile object corresponding to the data in
 766      * a byte array.  Throws an IllegalArgumentException if the data
 767      * does not correspond to a valid ICC Profile.
 768      * @param data the specified ICC Profile data
 769      * @return an {@code ICC_Profile} object corresponding to
 770      *          the data in the specified {@code data} array.
 771      */
 772     public static ICC_Profile getInstance(byte[] data) {
 773     ICC_Profile thisProfile;
 774 
 775         Profile p = null;
 776 
 777         if (ProfileDeferralMgr.deferring) {
 778             ProfileDeferralMgr.activateProfiles();
 779         }
 780 
 781         ProfileDataVerifier.verify(data);
 782 
 783         try {
 784             p = CMSManager.getModule().loadProfile(data);
 785         } catch (CMMException c) {
 786             throw new IllegalArgumentException("Invalid ICC Profile Data");
 787         }
 788 
 789         try {
 790             if ((getColorSpaceType (p) == ColorSpace.TYPE_GRAY) &&


 804             }
 805             else {
 806                 thisProfile = new ICC_Profile (p);
 807             }
 808         } catch (CMMException c) {
 809             thisProfile = new ICC_Profile (p);
 810         }
 811         return thisProfile;
 812     }
 813 
 814 
 815 
 816     /**
 817      * Constructs an ICC_Profile corresponding to one of the specific color
 818      * spaces defined by the ColorSpace class (for example CS_sRGB).
 819      * Throws an IllegalArgumentException if cspace is not one of the
 820      * defined color spaces.
 821      *
 822      * @param cspace the type of color space to create a profile for.
 823      * The specified type is one of the color
 824      * space constants defined in the  {@code ColorSpace} class.
 825      *
 826      * @return an {@code ICC_Profile} object corresponding to
 827      *          the specified {@code ColorSpace} type.
 828      * @exception IllegalArgumentException If {@code cspace} is not
 829      * one of the predefined color space types.
 830      */
 831     public static ICC_Profile getInstance (int cspace) {
 832         ICC_Profile thisProfile = null;
 833         String fileName;
 834 
 835         switch (cspace) {
 836         case ColorSpace.CS_sRGB:
 837             synchronized(ICC_Profile.class) {
 838                 if (sRGBprofile == null) {
 839                     /*
 840                      * Deferral is only used for standard profiles.
 841                      * Enabling the appropriate access privileges is handled
 842                      * at a lower level.
 843                      */
 844                     ProfileDeferralInfo pInfo =
 845                         new ProfileDeferralInfo("sRGB.pf",
 846                                                 ColorSpace.TYPE_RGB, 3,
 847                                                 CLASS_DISPLAY);
 848                     sRGBprofile = getDeferredInstance(pInfo);


 939                      return p;
 940                  }
 941              });
 942     }
 943 
 944     /**
 945      * Constructs an ICC_Profile corresponding to the data in a file.
 946      * fileName may be an absolute or a relative file specification.
 947      * Relative file names are looked for in several places: first, relative
 948      * to any directories specified by the java.iccprofile.path property;
 949      * second, relative to any directories specified by the java.class.path
 950      * property; finally, in a directory used to store profiles always
 951      * available, such as the profile for sRGB.  Built-in profiles use .pf as
 952      * the file name extension for profiles, e.g. sRGB.pf.
 953      * This method throws an IOException if the specified file cannot be
 954      * opened or if an I/O error occurs while reading the file.  It throws
 955      * an IllegalArgumentException if the file does not contain valid ICC
 956      * Profile data.
 957      * @param fileName The file that contains the data for the profile.
 958      *
 959      * @return an {@code ICC_Profile} object corresponding to
 960      *          the data in the specified file.
 961      * @exception IOException If the specified file cannot be opened or
 962      * an I/O error occurs while reading the file.
 963      *
 964      * @exception IllegalArgumentException If the file does not
 965      * contain valid ICC Profile data.
 966      *
 967      * @exception SecurityException If a security manager is installed
 968      * and it does not permit read access to the given file.
 969      */
 970     public static ICC_Profile getInstance(String fileName) throws IOException {
 971         ICC_Profile thisProfile;
 972         InputStream is = null;
 973 
 974 
 975         File f = getProfileFile(fileName);
 976         if (f != null) {
 977             is = new FileInputStream(f);
 978         } else {
 979             is = getStandardProfileInputStream(fileName);
 980         }
 981         if (is == null) {
 982             throw new IOException("Cannot open file " + fileName);
 983         }
 984 
 985         thisProfile = getInstance(is);
 986 
 987         is.close();    /* close the file */
 988 
 989         return thisProfile;
 990     }
 991 
 992 
 993     /**
 994      * Constructs an ICC_Profile corresponding to the data in an InputStream.
 995      * This method throws an IllegalArgumentException if the stream does not
 996      * contain valid ICC Profile data.  It throws an IOException if an I/O
 997      * error occurs while reading the stream.
 998      * @param s The input stream from which to read the profile data.
 999      *
1000      * @return an {@code ICC_Profile} object corresponding to the
1001      *     data in the specified {@code InputStream}.
1002      *
1003      * @exception IOException If an I/O error occurs while reading the stream.
1004      *
1005      * @exception IllegalArgumentException If the stream does not
1006      * contain valid ICC Profile data.
1007      */
1008     public static ICC_Profile getInstance(InputStream s) throws IOException {
1009     byte profileData[];
1010 
1011         if (s instanceof ProfileDeferralInfo) {
1012             /* hack to detect profiles whose loading can be deferred */
1013             return getDeferredInstance((ProfileDeferralInfo) s);
1014         }
1015 
1016         if ((profileData = getProfileDataFromStream(s)) == null) {
1017             throw new IllegalArgumentException("Invalid ICC Profile Data");
1018         }
1019 
1020         return getInstance(profileData);
1021     }


1196             theClass = CLASS_NAMEDCOLOR;
1197             break;
1198 
1199         default:
1200             throw new IllegalArgumentException("Unknown profile class");
1201         }
1202 
1203         return theClass;
1204     }
1205 
1206     /**
1207      * Returns the color space type.  Returns one of the color space type
1208      * constants defined by the ColorSpace class.  This is the
1209      * "input" color space of the profile.  The type defines the
1210      * number of components of the color space and the interpretation,
1211      * e.g. TYPE_RGB identifies a color space with three components - red,
1212      * green, and blue.  It does not define the particular color
1213      * characteristics of the space, e.g. the chromaticities of the
1214      * primaries.
1215      * @return One of the color space type constants defined in the
1216      * {@code ColorSpace} class.
1217      */
1218     public int getColorSpaceType() {
1219         if (deferralInfo != null) {
1220             return deferralInfo.colorSpaceType; /* Need to have this info for
1221                                                    ICC_ColorSpace without
1222                                                    causing a deferred profile
1223                                                    to be loaded */
1224         }
1225         return    getColorSpaceType(cmmProfile);
1226     }
1227 
1228     static int getColorSpaceType(Profile p) {
1229     byte[] theHeader;
1230     int theColorSpaceSig, theColorSpace;
1231 
1232         theHeader = getData(p, icSigHead);
1233         theColorSpaceSig = intFromBigEndian(theHeader, icHdrColorSpace);
1234         theColorSpace = iccCStoJCS (theColorSpaceSig);
1235         return theColorSpace;
1236     }
1237 
1238     /**
1239      * Returns the color space type of the Profile Connection Space (PCS).
1240      * Returns one of the color space type constants defined by the
1241      * ColorSpace class.  This is the "output" color space of the
1242      * profile.  For an input, display, or output profile useful
1243      * for tagging colors or images, this will be either TYPE_XYZ or
1244      * TYPE_Lab and should be interpreted as the corresponding specific
1245      * color space defined in the ICC specification.  For a device
1246      * link profile, this could be any of the color space type constants.
1247      * @return One of the color space type constants defined in the
1248      * {@code ColorSpace} class.
1249      */
1250     public int getPCSType() {
1251         if (ProfileDeferralMgr.deferring) {
1252             ProfileDeferralMgr.activateProfiles();
1253         }
1254         return getPCSType(cmmProfile);
1255     }
1256 
1257 
1258     static int getPCSType(Profile p) {
1259     byte[] theHeader;
1260     int thePCSSig, thePCS;
1261 
1262         theHeader = getData(p, icSigHead);
1263         thePCSSig = intFromBigEndian(theHeader, icHdrPcs);
1264         thePCS = iccCStoJCS(thePCSSig);
1265         return thePCS;
1266     }
1267 
1268 


1325 
1326         /* get the data for the profile */
1327         mdl.getProfileData(cmmProfile, profileData);
1328 
1329         return profileData;
1330     }
1331 
1332 
1333     /**
1334      * Returns a particular tagged data element from the profile as
1335      * a byte array.  Elements are identified by signatures
1336      * as defined in the ICC specification.  The signature
1337      * icSigHead can be used to get the header.  This method is useful
1338      * for advanced applets or applications which need to access
1339      * profile data directly.
1340      *
1341      * @param tagSignature The ICC tag signature for the data element you
1342      * want to get.
1343      *
1344      * @return A byte array that contains the tagged data element. Returns
1345      * {@code null} if the specified tag doesn't exist.
1346      * @see #setData(int, byte[])
1347      */
1348     public byte[] getData(int tagSignature) {
1349 
1350         if (ProfileDeferralMgr.deferring) {
1351             ProfileDeferralMgr.activateProfiles();
1352         }
1353 
1354         return getData(cmmProfile, tagSignature);
1355     }
1356 
1357 
1358     static byte[] getData(Profile p, int tagSignature) {
1359     int tagSize;
1360     byte[] tagData;
1361 
1362         try {
1363             PCMM mdl = CMSManager.getModule();
1364 
1365             /* get the number of bytes needed for this tag */


1912      *
1913      * There are two primary factory methods for construction of ICC
1914      * profiles: getInstance(int cspace) and getInstance(byte[] data).
1915      * This implementation of ICC_Profile uses the former to return a
1916      * cached singleton profile object, other implementations will
1917      * likely use this technique too.  To preserve the singleton
1918      * pattern across serialization we serialize cached singleton
1919      * profiles in such a way that deserializing VM could call
1920      * getInstance(int cspace) method that will resolve deserialized
1921      * object into the corresponding singleton as well.
1922      *
1923      * Since the singletons are private to ICC_Profile the readResolve
1924      * method have to be `protected' instead of `private' so that
1925      * singletons that are instances of subclasses of ICC_Profile
1926      * could be correctly deserialized.
1927      */
1928 
1929 
1930     /**
1931      * Version of the format of additional serialized data in the
1932      * stream.  Version&nbsp;{@code 1} corresponds to Java&nbsp;2
1933      * Platform,&nbsp;v1.3.
1934      * @since 1.3
1935      * @serial
1936      */
1937     private int iccProfileSerializedDataVersion = 1;
1938 
1939 
1940     /**
1941      * Writes default serializable fields to the stream.  Writes a
1942      * string and an array of bytes to the stream as additional data.
1943      *
1944      * @param s stream used for serialization.
1945      * @throws IOException
1946      *     thrown by {@code ObjectInputStream}.
1947      * @serialData
1948      *     The {@code String} is the name of one of
1949      *     <code>CS_<var>*</var></code> constants defined in the
1950      *     {@link ColorSpace} class if the profile object is a profile
1951      *     for a predefined color space (for example
1952      *     {@code "CS_sRGB"}).  The string is {@code null}
1953      *     otherwise.
1954      *     <p>
1955      *     The {@code byte[]} array is the profile data for the
1956      *     profile.  For predefined color spaces {@code null} is
1957      *     written instead of the profile data.  If in the future
1958      *     versions of Java API new predefined color spaces will be
1959      *     added, future versions of this class may choose to write
1960      *     for new predefined color spaces not only the color space
1961      *     name, but the profile data as well so that older versions
1962      *     could still deserialize the object.
1963      */
1964     private void writeObject(ObjectOutputStream s)
1965       throws IOException
1966     {
1967         s.defaultWriteObject();
1968 
1969         String csName = null;
1970         if (this == sRGBprofile) {
1971             csName = "CS_sRGB";
1972         } else if (this == XYZprofile) {
1973             csName = "CS_CIEXYZ";
1974         } else if (this == PYCCprofile) {
1975             csName = "CS_PYCC";
1976         } else if (this == GRAYprofile) {


1986         byte[] data = null;
1987         if (csName == null) {
1988             // getData will activate deferred profile if necessary
1989             data = getData();
1990         }
1991 
1992         s.writeObject(csName);
1993         s.writeObject(data);
1994     }
1995 
1996     // Temporary storage used by readObject to store resolved profile
1997     // (obtained with getInstance) for readResolve to return.
1998     private transient ICC_Profile resolvedDeserializedProfile;
1999 
2000     /**
2001      * Reads default serializable fields from the stream.  Reads from
2002      * the stream a string and an array of bytes as additional data.
2003      *
2004      * @param s stream used for deserialization.
2005      * @throws IOException
2006      *     thrown by {@code ObjectInputStream}.
2007      * @throws ClassNotFoundException
2008      *     thrown by {@code ObjectInputStream}.
2009      * @serialData
2010      *     The {@code String} is the name of one of
2011      *     <code>CS_<var>*</var></code> constants defined in the
2012      *     {@link ColorSpace} class if the profile object is a profile
2013      *     for a predefined color space (for example
2014      *     {@code "CS_sRGB"}).  The string is {@code null}
2015      *     otherwise.
2016      *     <p>
2017      *     The {@code byte[]} array is the profile data for the
2018      *     profile.  It will usually be {@code null} for the
2019      *     predefined profiles.
2020      *     <p>
2021      *     If the string is recognized as a constant name for
2022      *     predefined color space the object will be resolved into
2023      *     profile obtained with
2024      *     <code>getInstance(int&nbsp;cspace)</code> and the profile
2025      *     data are ignored.  Otherwise the object will be resolved
2026      *     into profile obtained with
2027      *     <code>getInstance(byte[]&nbsp;data)</code>.
2028      * @see #readResolve()
2029      * @see #getInstance(int)
2030      * @see #getInstance(byte[])
2031      */
2032     private void readObject(ObjectInputStream s)
2033       throws IOException, ClassNotFoundException
2034     {
2035         s.defaultReadObject();
2036 
2037         String csName = (String)s.readObject();
2038         byte[] data = (byte[])s.readObject();


< prev index next >