mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-05 04:25:29 -04:00
TMI-104: Fixed metadata inconsistency, 1 channel SOF now always interpreted as color space Gray, regardless of Adobe App14 marker.
This commit is contained in:
parent
d6f90b0b52
commit
37d4c03548
@ -156,10 +156,12 @@ final class JPEGImage10MetadataCleaner {
|
||||
}
|
||||
|
||||
// Special case: Broken AdobeDCT segment, inconsistent with SOF, use values from SOF
|
||||
if (adobeDCT != null && adobeDCT.getTransform() == AdobeDCTSegment.YCCK && sof.componentsInFrame() < 4) {
|
||||
if (adobeDCT != null && (adobeDCT.getTransform() == AdobeDCTSegment.YCCK && sof.componentsInFrame() < 4 ||
|
||||
adobeDCT.getTransform() == AdobeDCTSegment.YCC && sof.componentsInFrame() < 3)) {
|
||||
reader.processWarningOccurred(String.format(
|
||||
"Invalid Adobe App14 marker. Indicates YCCK/CMYK data, but SOF%d has %d color components. " +
|
||||
"Invalid Adobe App14 marker. Indicates %s data, but SOF%d has %d color component(s). " +
|
||||
"Ignoring Adobe App14 marker.",
|
||||
adobeDCT.getTransform() == AdobeDCTSegment.YCCK ? "YCCK/CMYK" : "YCC/RGB",
|
||||
sof.marker & 0xf, sof.componentsInFrame()
|
||||
));
|
||||
|
||||
|
@ -323,7 +323,7 @@ public class JPEGImageReader extends ImageReaderBase {
|
||||
if (adobeDCT != null && (adobeDCT.getTransform() == AdobeDCTSegment.YCC && sof.componentsInFrame() != 3 ||
|
||||
adobeDCT.getTransform() == AdobeDCTSegment.YCCK && sof.componentsInFrame() != 4)) {
|
||||
processWarningOccurred(String.format(
|
||||
"Invalid Adobe App14 marker. Indicates %s data, but SOF%d has %d color components. " +
|
||||
"Invalid Adobe App14 marker. Indicates %s data, but SOF%d has %d color component(s). " +
|
||||
"Ignoring Adobe App14 marker.",
|
||||
adobeDCT.getTransform() == AdobeDCTSegment.YCCK ? "YCCK/CMYK" : "YCC/RGB",
|
||||
sof.marker & 0xf, sof.componentsInFrame()
|
||||
@ -1075,8 +1075,7 @@ public class JPEGImageReader extends ImageReaderBase {
|
||||
|
||||
@Override
|
||||
public IIOMetadata getImageMetadata(int imageIndex) throws IOException {
|
||||
// TMI-101: As we catch the IndexOutOfBoundsException below, we need to make sure that we don't catch the
|
||||
// IndexOutOfBoundsException that should be thrown, if (imageIndex < 0 || imageIndex > numImages).
|
||||
// checkBounds needed, as we catch the IndexOutOfBoundsException below.
|
||||
checkBounds(imageIndex);
|
||||
|
||||
IIOMetadata imageMetadata;
|
||||
|
@ -80,6 +80,7 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTestCase<JPEGImageRe
|
||||
|
||||
@Override
|
||||
protected List<TestData> getTestData() {
|
||||
// While a lot of these files don't conform to any spec (Exif/JFIF), we will read these.
|
||||
return Arrays.asList(
|
||||
new TestData(getClassLoaderResource("/jpeg/cmm-exception-adobe-rgb.jpg"), new Dimension(626, 76)),
|
||||
new TestData(getClassLoaderResource("/jpeg/cmm-exception-srgb.jpg"), new Dimension(1800, 1200)),
|
||||
@ -96,10 +97,11 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTestCase<JPEGImageRe
|
||||
}
|
||||
|
||||
protected List<TestData> getBrokenTestData() {
|
||||
// These files are considered too broken to be read (ie. most other software does not read them either).
|
||||
return Arrays.asList(
|
||||
new TestData(getClassLoaderResource("/broken-jpeg/broken-bogus-segment-length.jpg"), new Dimension(467, 612)),
|
||||
new TestData(getClassLoaderResource("/broken-jpeg/broken-adobe-marker-bad-length.jpg"), new Dimension(1800, 1200)),
|
||||
new TestData(getClassLoaderResource("/broken-jpeg/broken-invalid-adobe-ycc-gray.jpg"), new Dimension(11, 440))
|
||||
new TestData(getClassLoaderResource("/broken-jpeg/broken-bogus-segment-length.jpg"), new Dimension(467, 612)), // Semi-readable, parts missing
|
||||
new TestData(getClassLoaderResource("/broken-jpeg/broken-adobe-marker-bad-length.jpg"), new Dimension(1800, 1200)), // Unreadable, segment lengths are wrong
|
||||
new TestData(getClassLoaderResource("/broken-jpeg/broken-invalid-adobe-ycc-gray.jpg"), new Dimension(11, 440)) // Image readable, broken metadata (fixable?)
|
||||
);
|
||||
|
||||
// More test data in specific tests below
|
||||
@ -475,6 +477,33 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTestCase<JPEGImageRe
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImageMetadata1ChannelGrayWithBogusAdobeYCC() throws IOException {
|
||||
JPEGImageReader reader = createReader();
|
||||
|
||||
try {
|
||||
// Any sample should do here
|
||||
reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/invalid-adobe-ycc-gray-with-metadata.jpg")));
|
||||
IIOMetadata metadata = reader.getImageMetadata(0);
|
||||
IIOMetadataNode root = (IIOMetadataNode) metadata.getAsTree(IIOMetadataFormatImpl.standardMetadataFormatName);
|
||||
|
||||
IIOMetadataNode chroma = getSingleElementByName(root, "Chroma");
|
||||
IIOMetadataNode numChannels = getSingleElementByName(chroma, "NumChannels");
|
||||
assertEquals("1", numChannels.getAttribute("value"));
|
||||
IIOMetadataNode colorSpaceType = getSingleElementByName(chroma, "ColorSpaceType");
|
||||
assertEquals("GRAY", colorSpaceType.getAttribute("name"));
|
||||
}
|
||||
finally {
|
||||
reader.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private IIOMetadataNode getSingleElementByName(final IIOMetadataNode root, final String name) {
|
||||
NodeList elements = root.getElementsByTagName(name);
|
||||
assertEquals(1, elements.getLength());
|
||||
return (IIOMetadataNode) elements.item(0);
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void testGetImageMetadataOutOfBounds() throws IOException {
|
||||
JPEGImageReader reader = createReader();
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 299 B |
Loading…
x
Reference in New Issue
Block a user