mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-04 12:05:29 -04:00
TMI-99: JPEGImageReader does not ignore incorrect color RGB profile for CMYK data
This commit is contained in:
parent
c3cafc63d8
commit
34cd913216
@ -226,14 +226,14 @@ public class JPEGImageReader extends ImageReaderBase {
|
|||||||
ICC_Profile profile = getEmbeddedICCProfile(false);
|
ICC_Profile profile = getEmbeddedICCProfile(false);
|
||||||
|
|
||||||
if (csType == JPEGColorSpace.CMYK || csType == JPEGColorSpace.YCCK) {
|
if (csType == JPEGColorSpace.CMYK || csType == JPEGColorSpace.YCCK) {
|
||||||
if (profile != null) {
|
if (profile != null && profile.getNumComponents() == 4) {
|
||||||
typeList.add(ImageTypeSpecifiers.createInterleaved(ColorSpaces.createColorSpace(profile), new int[] {3, 2, 1, 0}, DataBuffer.TYPE_BYTE, false, false));
|
typeList.add(ImageTypeSpecifiers.createInterleaved(ColorSpaces.createColorSpace(profile), new int[] {3, 2, 1, 0}, DataBuffer.TYPE_BYTE, false, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
typeList.add(ImageTypeSpecifiers.createInterleaved(ColorSpaces.getColorSpace(ColorSpaces.CS_GENERIC_CMYK), new int[] {3, 2, 1, 0}, DataBuffer.TYPE_BYTE, false, false));
|
typeList.add(ImageTypeSpecifiers.createInterleaved(ColorSpaces.getColorSpace(ColorSpaces.CS_GENERIC_CMYK), new int[] {3, 2, 1, 0}, DataBuffer.TYPE_BYTE, false, false));
|
||||||
}
|
}
|
||||||
else if (csType == JPEGColorSpace.YCbCr || csType == JPEGColorSpace.RGB) {
|
else if (csType == JPEGColorSpace.YCbCr || csType == JPEGColorSpace.RGB) {
|
||||||
if (profile != null) {
|
if (profile != null && profile.getNumComponents() == 3) {
|
||||||
typeList.add(ImageTypeSpecifiers.createInterleaved(ColorSpaces.createColorSpace(profile), new int[] {0, 1, 2}, DataBuffer.TYPE_BYTE, false, false));
|
typeList.add(ImageTypeSpecifiers.createInterleaved(ColorSpaces.createColorSpace(profile), new int[] {0, 1, 2}, DataBuffer.TYPE_BYTE, false, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -246,8 +246,8 @@ public class JPEGImageReader extends ImageReaderBase {
|
|||||||
ImageTypeSpecifiers.createFromBufferedImageType(BufferedImage.TYPE_4BYTE_ABGR_PRE)
|
ImageTypeSpecifiers.createFromBufferedImageType(BufferedImage.TYPE_4BYTE_ABGR_PRE)
|
||||||
));
|
));
|
||||||
|
|
||||||
if (profile != null) {
|
if (profile != null && profile.getNumComponents() == 3) {
|
||||||
typeList.add(ImageTypeSpecifiers.createInterleaved(ColorSpaces.createColorSpace(profile), new int[] {0, 1, 2, 3}, DataBuffer.TYPE_BYTE, false, false));
|
typeList.add(ImageTypeSpecifiers.createInterleaved(ColorSpaces.createColorSpace(profile), new int[] {0, 1, 2, 3}, DataBuffer.TYPE_BYTE, true, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,10 +274,8 @@ public class JPEGImageReader extends ImageReaderBase {
|
|||||||
// Create based on embedded profile if exists, or create from "Generic CMYK"
|
// Create based on embedded profile if exists, or create from "Generic CMYK"
|
||||||
ICC_Profile profile = getEmbeddedICCProfile(false);
|
ICC_Profile profile = getEmbeddedICCProfile(false);
|
||||||
|
|
||||||
if (profile != null) {
|
if (profile != null && profile.getNumComponents() == 4) {
|
||||||
return ImageTypeSpecifiers.createInterleaved(ColorSpaces.createColorSpace(profile), new int[]{
|
return ImageTypeSpecifiers.createInterleaved(ColorSpaces.createColorSpace(profile), new int[]{3, 2, 1, 0}, DataBuffer.TYPE_BYTE, false, false);
|
||||||
3, 2, 1, 0
|
|
||||||
}, DataBuffer.TYPE_BYTE, false, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ImageTypeSpecifiers.createInterleaved(ColorSpaces.getColorSpace(ColorSpaces.CS_GENERIC_CMYK), new int[] {3, 2, 1, 0}, DataBuffer.TYPE_BYTE, false, false);
|
return ImageTypeSpecifiers.createInterleaved(ColorSpaces.getColorSpace(ColorSpaces.CS_GENERIC_CMYK), new int[] {3, 2, 1, 0}, DataBuffer.TYPE_BYTE, false, false);
|
||||||
@ -385,6 +383,10 @@ public class JPEGImageReader extends ImageReaderBase {
|
|||||||
"Ignoring ICC profile, assuming source color space %s.",
|
"Ignoring ICC profile, assuming source color space %s.",
|
||||||
intendedCS.getNumComponents(), startOfFrame.marker & 0xf, startOfFrame.componentsInFrame(), csType
|
intendedCS.getNumComponents(), startOfFrame.marker & 0xf, startOfFrame.componentsInFrame(), csType
|
||||||
));
|
));
|
||||||
|
|
||||||
|
if (csType == JPEGColorSpace.CMYK && image.getColorModel().getColorSpace().getType() != ColorSpace.TYPE_CMYK) {
|
||||||
|
convert = new ColorConvertOp(ColorSpaces.getColorSpace(ColorSpaces.CS_GENERIC_CMYK), image.getColorModel().getColorSpace(), null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// NOTE: Avoid using CCOp if same color space, as it's more compatible that way
|
// NOTE: Avoid using CCOp if same color space, as it's more compatible that way
|
||||||
|
@ -271,6 +271,29 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTestCase<JPEGImageRe
|
|||||||
assertTrue(reader.hasThumbnails(0)); // Should not blow up!
|
assertTrue(reader.hasThumbnails(0)); // Should not blow up!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCMYKWithRGBProfile() throws IOException {
|
||||||
|
// File contains JFIF (!), RGB ICC profile AND Adobe App14 specifying unknown conversion,
|
||||||
|
// but image data is 4 channel CMYK (from SOF0 channel Ids 'C', 'M', 'Y', 'K').
|
||||||
|
JPEGImageReader reader = createReader();
|
||||||
|
reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/jfif-cmyk-invalid-icc-profile-srgb.jpg")));
|
||||||
|
|
||||||
|
assertEquals(493, reader.getWidth(0));
|
||||||
|
assertEquals(500, reader.getHeight(0));
|
||||||
|
|
||||||
|
ImageReadParam param = reader.getDefaultReadParam();
|
||||||
|
param.setSourceRegion(new Rectangle(0, 0, 493, 16)); // Save some memory
|
||||||
|
BufferedImage image = reader.read(0, param);
|
||||||
|
|
||||||
|
assertNotNull(image);
|
||||||
|
assertEquals(493, image.getWidth());
|
||||||
|
assertEquals(16, image.getHeight());
|
||||||
|
|
||||||
|
// TODO: Need to test colors!
|
||||||
|
|
||||||
|
assertFalse(reader.hasThumbnails(0)); // Should not blow up!
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWarningEmbeddedColorProfileInvalidIgnored() throws IOException {
|
public void testWarningEmbeddedColorProfileInvalidIgnored() throws IOException {
|
||||||
JPEGImageReader reader = createReader();
|
JPEGImageReader reader = createReader();
|
||||||
|
Binary file not shown.
After Width: | Height: | Size: 55 KiB |
Loading…
x
Reference in New Issue
Block a user