8172153: Create workaround for failure to use ICC profile contained in a TIFF field
Work around errors due to using an embedded ICC profile from the metadata Reviewed-by: prr
This commit is contained in:
parent
7c0476db0a
commit
95ffeea1a3
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -730,18 +730,47 @@ public class TIFFImageReader extends ImageReader {
|
|||||||
// to use it if the data layout is component type.
|
// to use it if the data layout is component type.
|
||||||
if (iccProfileField != null
|
if (iccProfileField != null
|
||||||
&& itsRaw.getColorModel() instanceof ComponentColorModel) {
|
&& itsRaw.getColorModel() instanceof ComponentColorModel) {
|
||||||
// Create a ColorSpace from the profile.
|
|
||||||
byte[] iccProfileValue = iccProfileField.getAsBytes();
|
|
||||||
ICC_Profile iccProfile
|
|
||||||
= ICC_Profile.getInstance(iccProfileValue);
|
|
||||||
ICC_ColorSpace iccColorSpace
|
|
||||||
= new ICC_ColorSpace(iccProfile);
|
|
||||||
|
|
||||||
// Get the raw sample and color information.
|
// Get the raw sample and color information.
|
||||||
ColorModel cmRaw = itsRaw.getColorModel();
|
ColorModel cmRaw = itsRaw.getColorModel();
|
||||||
ColorSpace csRaw = cmRaw.getColorSpace();
|
ColorSpace csRaw = cmRaw.getColorSpace();
|
||||||
SampleModel smRaw = itsRaw.getSampleModel();
|
SampleModel smRaw = itsRaw.getSampleModel();
|
||||||
|
|
||||||
|
ColorSpace iccColorSpace = null;
|
||||||
|
try {
|
||||||
|
// Create a ColorSpace from the profile.
|
||||||
|
byte[] iccProfileValue = iccProfileField.getAsBytes();
|
||||||
|
ICC_Profile iccProfile
|
||||||
|
= ICC_Profile.getInstance(iccProfileValue);
|
||||||
|
iccColorSpace = new ICC_ColorSpace(iccProfile);
|
||||||
|
|
||||||
|
// Workaround for JDK-8145241: test a conversion and fall
|
||||||
|
// back to a standard ColorSpace if it fails. This
|
||||||
|
// workaround could be removed if JDK-8145241 is fixed.
|
||||||
|
float[] rgb =
|
||||||
|
iccColorSpace.toRGB(new float[] {1.0F, 1.0F, 1.0F});
|
||||||
|
} catch (Exception iccProfileException) {
|
||||||
|
processWarningOccurred("Superseding bad ICC profile: "
|
||||||
|
+ iccProfileException.getMessage());
|
||||||
|
|
||||||
|
if (iccColorSpace != null) {
|
||||||
|
switch (iccColorSpace.getType()) {
|
||||||
|
case ColorSpace.TYPE_GRAY:
|
||||||
|
iccColorSpace =
|
||||||
|
ColorSpace.getInstance(ColorSpace.CS_GRAY);
|
||||||
|
break;
|
||||||
|
case ColorSpace.TYPE_RGB:
|
||||||
|
iccColorSpace =
|
||||||
|
ColorSpace.getInstance(ColorSpace.CS_sRGB);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
iccColorSpace = csRaw;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
iccColorSpace = csRaw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Get the number of samples per pixel and the number
|
// Get the number of samples per pixel and the number
|
||||||
// of color components.
|
// of color components.
|
||||||
int numBands = smRaw.getNumBands();
|
int numBands = smRaw.getNumBands();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user