6793818: JpegImageReader is too greedy creating color profiles
Reviewed-by: igor, prr
This commit is contained in:
parent
8c2a336349
commit
2726f2a362
@ -737,7 +737,7 @@ public class ICC_Profile implements Serializable {
|
|||||||
ICC_Profile(ProfileDeferralInfo pdi) {
|
ICC_Profile(ProfileDeferralInfo pdi) {
|
||||||
this.deferralInfo = pdi;
|
this.deferralInfo = pdi;
|
||||||
this.profileActivator = new ProfileActivator() {
|
this.profileActivator = new ProfileActivator() {
|
||||||
public void activate() {
|
public void activate() throws ProfileDataException {
|
||||||
activateDeferredProfile();
|
activateDeferredProfile();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -830,20 +830,16 @@ public class ICC_Profile implements Serializable {
|
|||||||
case ColorSpace.CS_sRGB:
|
case ColorSpace.CS_sRGB:
|
||||||
synchronized(ICC_Profile.class) {
|
synchronized(ICC_Profile.class) {
|
||||||
if (sRGBprofile == null) {
|
if (sRGBprofile == null) {
|
||||||
try {
|
/*
|
||||||
/*
|
* Deferral is only used for standard profiles.
|
||||||
* Deferral is only used for standard profiles.
|
* Enabling the appropriate access privileges is handled
|
||||||
* Enabling the appropriate access privileges is handled
|
* at a lower level.
|
||||||
* at a lower level.
|
*/
|
||||||
*/
|
ProfileDeferralInfo pInfo =
|
||||||
sRGBprofile = getDeferredInstance(
|
new ProfileDeferralInfo("sRGB.pf",
|
||||||
new ProfileDeferralInfo("sRGB.pf",
|
ColorSpace.TYPE_RGB, 3,
|
||||||
ColorSpace.TYPE_RGB,
|
CLASS_DISPLAY);
|
||||||
3, CLASS_DISPLAY));
|
sRGBprofile = getDeferredInstance(pInfo);
|
||||||
} catch (IOException e) {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Can't load standard profile: sRGB.pf");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
thisProfile = sRGBprofile;
|
thisProfile = sRGBprofile;
|
||||||
}
|
}
|
||||||
@ -853,7 +849,11 @@ public class ICC_Profile implements Serializable {
|
|||||||
case ColorSpace.CS_CIEXYZ:
|
case ColorSpace.CS_CIEXYZ:
|
||||||
synchronized(ICC_Profile.class) {
|
synchronized(ICC_Profile.class) {
|
||||||
if (XYZprofile == null) {
|
if (XYZprofile == null) {
|
||||||
XYZprofile = getStandardProfile("CIEXYZ.pf");
|
ProfileDeferralInfo pInfo =
|
||||||
|
new ProfileDeferralInfo("CIEXYZ.pf",
|
||||||
|
ColorSpace.TYPE_XYZ, 3,
|
||||||
|
CLASS_DISPLAY);
|
||||||
|
XYZprofile = getDeferredInstance(pInfo);
|
||||||
}
|
}
|
||||||
thisProfile = XYZprofile;
|
thisProfile = XYZprofile;
|
||||||
}
|
}
|
||||||
@ -863,7 +863,11 @@ public class ICC_Profile implements Serializable {
|
|||||||
case ColorSpace.CS_PYCC:
|
case ColorSpace.CS_PYCC:
|
||||||
synchronized(ICC_Profile.class) {
|
synchronized(ICC_Profile.class) {
|
||||||
if (PYCCprofile == null) {
|
if (PYCCprofile == null) {
|
||||||
PYCCprofile = getStandardProfile("PYCC.pf");
|
ProfileDeferralInfo pInfo =
|
||||||
|
new ProfileDeferralInfo("PYCC.pf",
|
||||||
|
ColorSpace.TYPE_3CLR, 3,
|
||||||
|
CLASS_DISPLAY);
|
||||||
|
PYCCprofile = getDeferredInstance(pInfo);
|
||||||
}
|
}
|
||||||
thisProfile = PYCCprofile;
|
thisProfile = PYCCprofile;
|
||||||
}
|
}
|
||||||
@ -873,7 +877,11 @@ public class ICC_Profile implements Serializable {
|
|||||||
case ColorSpace.CS_GRAY:
|
case ColorSpace.CS_GRAY:
|
||||||
synchronized(ICC_Profile.class) {
|
synchronized(ICC_Profile.class) {
|
||||||
if (GRAYprofile == null) {
|
if (GRAYprofile == null) {
|
||||||
GRAYprofile = getStandardProfile("GRAY.pf");
|
ProfileDeferralInfo pInfo =
|
||||||
|
new ProfileDeferralInfo("GRAY.pf",
|
||||||
|
ColorSpace.TYPE_GRAY, 1,
|
||||||
|
CLASS_DISPLAY);
|
||||||
|
GRAYprofile = getDeferredInstance(pInfo);
|
||||||
}
|
}
|
||||||
thisProfile = GRAYprofile;
|
thisProfile = GRAYprofile;
|
||||||
}
|
}
|
||||||
@ -883,7 +891,11 @@ public class ICC_Profile implements Serializable {
|
|||||||
case ColorSpace.CS_LINEAR_RGB:
|
case ColorSpace.CS_LINEAR_RGB:
|
||||||
synchronized(ICC_Profile.class) {
|
synchronized(ICC_Profile.class) {
|
||||||
if (LINEAR_RGBprofile == null) {
|
if (LINEAR_RGBprofile == null) {
|
||||||
LINEAR_RGBprofile = getStandardProfile("LINEAR_RGB.pf");
|
ProfileDeferralInfo pInfo =
|
||||||
|
new ProfileDeferralInfo("LINEAR_RGB.pf",
|
||||||
|
ColorSpace.TYPE_RGB, 3,
|
||||||
|
CLASS_DISPLAY);
|
||||||
|
LINEAR_RGBprofile = getDeferredInstance(pInfo);
|
||||||
}
|
}
|
||||||
thisProfile = LINEAR_RGBprofile;
|
thisProfile = LINEAR_RGBprofile;
|
||||||
}
|
}
|
||||||
@ -1047,9 +1059,7 @@ public class ICC_Profile implements Serializable {
|
|||||||
* code will take care of access privileges.
|
* code will take care of access privileges.
|
||||||
* @see activateDeferredProfile()
|
* @see activateDeferredProfile()
|
||||||
*/
|
*/
|
||||||
static ICC_Profile getDeferredInstance(ProfileDeferralInfo pdi)
|
static ICC_Profile getDeferredInstance(ProfileDeferralInfo pdi) {
|
||||||
throws IOException {
|
|
||||||
|
|
||||||
if (!ProfileDeferralMgr.deferring) {
|
if (!ProfileDeferralMgr.deferring) {
|
||||||
return getStandardProfile(pdi.filename);
|
return getStandardProfile(pdi.filename);
|
||||||
}
|
}
|
||||||
@ -1063,33 +1073,37 @@ public class ICC_Profile implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void activateDeferredProfile() {
|
void activateDeferredProfile() throws ProfileDataException {
|
||||||
byte profileData[];
|
byte profileData[];
|
||||||
FileInputStream fis;
|
FileInputStream fis;
|
||||||
String fileName = deferralInfo.filename;
|
String fileName = deferralInfo.filename;
|
||||||
|
|
||||||
profileActivator = null;
|
profileActivator = null;
|
||||||
deferralInfo = null;
|
deferralInfo = null;
|
||||||
if ((fis = openProfile(fileName)) == null) {
|
if ((fis = openProfile(fileName)) == null) {
|
||||||
throw new IllegalArgumentException("Cannot open file " + fileName);
|
throw new ProfileDataException("Cannot open file " + fileName);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
profileData = getProfileDataFromStream(fis);
|
profileData = getProfileDataFromStream(fis);
|
||||||
fis.close(); /* close the file */
|
fis.close(); /* close the file */
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
throw new IllegalArgumentException("Invalid ICC Profile Data" +
|
ProfileDataException pde = new
|
||||||
fileName);
|
ProfileDataException("Invalid ICC Profile Data" + fileName);
|
||||||
|
pde.initCause(e);
|
||||||
|
throw pde;
|
||||||
}
|
}
|
||||||
if (profileData == null) {
|
if (profileData == null) {
|
||||||
throw new IllegalArgumentException("Invalid ICC Profile Data" +
|
throw new ProfileDataException("Invalid ICC Profile Data" +
|
||||||
fileName);
|
fileName);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
ID = CMSManager.getModule().loadProfile(profileData);
|
ID = CMSManager.getModule().loadProfile(profileData);
|
||||||
} catch (CMMException c) {
|
} catch (CMMException c) {
|
||||||
throw new IllegalArgumentException("Invalid ICC Profile Data" +
|
ProfileDataException pde = new
|
||||||
fileName);
|
ProfileDataException("Invalid ICC Profile Data" + fileName);
|
||||||
|
pde.initCause(c);
|
||||||
|
throw pde;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
package sun.java2d.cmm;
|
package sun.java2d.cmm;
|
||||||
|
|
||||||
|
import java.awt.color.ProfileDataException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An interface to allow the ProfileDeferralMgr to activate a
|
* An interface to allow the ProfileDeferralMgr to activate a
|
||||||
@ -35,6 +36,6 @@ public interface ProfileActivator {
|
|||||||
/**
|
/**
|
||||||
* Activate a previously deferred ICC_Profile object.
|
* Activate a previously deferred ICC_Profile object.
|
||||||
*/
|
*/
|
||||||
public void activate();
|
public void activate() throws ProfileDataException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
package sun.java2d.cmm;
|
package sun.java2d.cmm;
|
||||||
|
|
||||||
|
import java.awt.color.ProfileDataException;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
|
|
||||||
@ -39,7 +40,7 @@ import java.util.Vector;
|
|||||||
public class ProfileDeferralMgr {
|
public class ProfileDeferralMgr {
|
||||||
|
|
||||||
public static boolean deferring = true;
|
public static boolean deferring = true;
|
||||||
private static Vector aVector;
|
private static Vector<ProfileActivator> aVector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Records a ProfileActivator object whose activate method will
|
* Records a ProfileActivator object whose activate method will
|
||||||
@ -51,7 +52,7 @@ public class ProfileDeferralMgr {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (aVector == null) {
|
if (aVector == null) {
|
||||||
aVector = new Vector(3, 3);
|
aVector = new Vector<ProfileActivator>(3, 3);
|
||||||
}
|
}
|
||||||
aVector.addElement(pa);
|
aVector.addElement(pa);
|
||||||
return;
|
return;
|
||||||
@ -89,8 +90,26 @@ public class ProfileDeferralMgr {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
n = aVector.size();
|
n = aVector.size();
|
||||||
for (i = 0; i < n; i++) {
|
for (ProfileActivator pa : aVector) {
|
||||||
((ProfileActivator) aVector.get(i)).activate();
|
try {
|
||||||
|
pa.activate();
|
||||||
|
} catch (ProfileDataException e) {
|
||||||
|
/*
|
||||||
|
* Ignore profile activation error for now:
|
||||||
|
* such exception is pssible due to absence
|
||||||
|
* or corruption of standard color profile.
|
||||||
|
* As for now we expect all profiles should
|
||||||
|
* be shiped with jre and presence of this
|
||||||
|
* exception is indication of some configuration
|
||||||
|
* problem in jre installation.
|
||||||
|
*
|
||||||
|
* NB: we still are greedy loading deferred profiles
|
||||||
|
* and load them all if any of them is needed.
|
||||||
|
* Therefore broken profile (if any) might be never used.
|
||||||
|
* If there will be attempt to use broken profile then
|
||||||
|
* it will result in CMMException.
|
||||||
|
*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
aVector.removeAllElements();
|
aVector.removeAllElements();
|
||||||
aVector = null;
|
aVector = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user