mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-03 11:35:29 -04:00
#1152 Fix TIFF CCITT T.4/T.6 metadata compression names
This commit is contained in:
parent
13a64ed3bb
commit
3eabbcd8a3
@ -71,18 +71,18 @@ public final class TIFFImageMetadata extends AbstractMetadata {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an empty TIFF metadata object.
|
* Creates an empty TIFF metadata object.
|
||||||
*
|
* <br/>
|
||||||
* Client code can update or change the metadata using the
|
* Client code can update or change the metadata using the
|
||||||
* {@link #setFromTree(String, Node)}
|
* {@link #setFromTree(String, Node)}
|
||||||
* or {@link #mergeTree(String, Node)} methods.
|
* or {@link #mergeTree(String, Node)} methods.
|
||||||
*/
|
*/
|
||||||
public TIFFImageMetadata() {
|
public TIFFImageMetadata() {
|
||||||
this(new IFD(Collections.<Entry>emptyList()));
|
this(new IFD(Collections.emptyList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a TIFF metadata object, using the values from the given IFD.
|
* Creates a TIFF metadata object, using the values from the given IFD.
|
||||||
*
|
* <br/>
|
||||||
* Client code can update or change the metadata using the
|
* Client code can update or change the metadata using the
|
||||||
* {@link #setFromTree(String, Node)}
|
* {@link #setFromTree(String, Node)}
|
||||||
* or {@link #mergeTree(String, Node)} methods.
|
* or {@link #mergeTree(String, Node)} methods.
|
||||||
@ -95,7 +95,7 @@ public final class TIFFImageMetadata extends AbstractMetadata {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a TIFF metadata object, using the values from the given entries.
|
* Creates a TIFF metadata object, using the values from the given entries.
|
||||||
*
|
* <br/>
|
||||||
* Client code can update or change the metadata using the
|
* Client code can update or change the metadata using the
|
||||||
* {@link #setFromTree(String, Node)}
|
* {@link #setFromTree(String, Node)}
|
||||||
* or {@link #mergeTree(String, Node)} methods.
|
* or {@link #mergeTree(String, Node)} methods.
|
||||||
@ -493,10 +493,10 @@ public final class TIFFImageMetadata extends AbstractMetadata {
|
|||||||
compressionTypeName.setAttribute("value", "CCITT RLE");
|
compressionTypeName.setAttribute("value", "CCITT RLE");
|
||||||
break;
|
break;
|
||||||
case TIFFExtension.COMPRESSION_CCITT_T4:
|
case TIFFExtension.COMPRESSION_CCITT_T4:
|
||||||
compressionTypeName.setAttribute("value", "CCITT T4");
|
compressionTypeName.setAttribute("value", "CCITT T.4");
|
||||||
break;
|
break;
|
||||||
case TIFFExtension.COMPRESSION_CCITT_T6:
|
case TIFFExtension.COMPRESSION_CCITT_T6:
|
||||||
compressionTypeName.setAttribute("value", "CCITT T6");
|
compressionTypeName.setAttribute("value", "CCITT T.6");
|
||||||
break;
|
break;
|
||||||
case TIFFExtension.COMPRESSION_LZW:
|
case TIFFExtension.COMPRESSION_LZW:
|
||||||
compressionTypeName.setAttribute("value", "LZW");
|
compressionTypeName.setAttribute("value", "LZW");
|
||||||
@ -1038,7 +1038,7 @@ public final class TIFFImageMetadata extends AbstractMetadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we have resolution
|
// If we have resolution
|
||||||
if (xRes != null && yRes != null) {
|
if (xRes != null) { // yRes != null too
|
||||||
// If old unit was DPI, convert values and keep DPI, otherwise use PPCM
|
// If old unit was DPI, convert values and keep DPI, otherwise use PPCM
|
||||||
Entry resUnitEntry = entries.get(TIFF.TAG_RESOLUTION_UNIT);
|
Entry resUnitEntry = entries.get(TIFF.TAG_RESOLUTION_UNIT);
|
||||||
int resUnitValue = resUnitEntry != null && resUnitEntry.getValue() != null
|
int resUnitValue = resUnitEntry != null && resUnitEntry.getValue() != null
|
||||||
|
@ -188,6 +188,102 @@ public class TIFFImageMetadataTest {
|
|||||||
assertEquals("HP IL v1.1", ((Element) textEntry).getAttribute("value"));
|
assertEquals("HP IL v1.1", ((Element) textEntry).getAttribute("value"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMetadataStandardFormat_CCITT300dpi() throws IOException {
|
||||||
|
IIOMetadata metadata = createMetadata("/tiff/CCITT-G4-300dpi-StripByteCounts0.tif");
|
||||||
|
Node root = metadata.getAsTree(IIOMetadataFormatImpl.standardMetadataFormatName);
|
||||||
|
|
||||||
|
// Root: "javax_imageio_1.0"
|
||||||
|
assertNotNull(root);
|
||||||
|
assertEquals(IIOMetadataFormatImpl.standardMetadataFormatName, root.getNodeName());
|
||||||
|
assertEquals(5, root.getChildNodes().getLength());
|
||||||
|
|
||||||
|
// "Chroma"
|
||||||
|
Node chroma = root.getFirstChild();
|
||||||
|
assertEquals("Chroma", chroma.getNodeName());
|
||||||
|
|
||||||
|
assertEquals(3, chroma.getChildNodes().getLength());
|
||||||
|
|
||||||
|
Node colorSpaceType = chroma.getFirstChild();
|
||||||
|
assertEquals("ColorSpaceType", colorSpaceType.getNodeName());
|
||||||
|
assertEquals("GRAY", ((Element) colorSpaceType).getAttribute("name"));
|
||||||
|
|
||||||
|
Node numChannels = colorSpaceType.getNextSibling();
|
||||||
|
assertEquals("NumChannels", numChannels.getNodeName());
|
||||||
|
assertEquals("1", ((Element) numChannels).getAttribute("value"));
|
||||||
|
|
||||||
|
Node blackIsZero = numChannels.getNextSibling();
|
||||||
|
assertEquals("BlackIsZero", blackIsZero.getNodeName());
|
||||||
|
assertEquals("FALSE", ((Element) blackIsZero).getAttribute("value"));
|
||||||
|
|
||||||
|
// "Compression"
|
||||||
|
Node compression = chroma.getNextSibling();
|
||||||
|
assertEquals("Compression", compression.getNodeName());
|
||||||
|
assertEquals(2, compression.getChildNodes().getLength());
|
||||||
|
|
||||||
|
Node compressionTypeName = compression.getFirstChild();
|
||||||
|
assertEquals("CompressionTypeName", compressionTypeName.getNodeName());
|
||||||
|
assertEquals("CCITT T.6", ((Element) compressionTypeName).getAttribute("value"));
|
||||||
|
|
||||||
|
Node lossless = compressionTypeName.getNextSibling();
|
||||||
|
assertEquals("Lossless", lossless.getNodeName());
|
||||||
|
assertEquals(0, lossless.getAttributes().getLength());
|
||||||
|
|
||||||
|
// "Data"
|
||||||
|
Node data = compression.getNextSibling();
|
||||||
|
assertEquals("Data", data.getNodeName());
|
||||||
|
assertEquals(4, data.getChildNodes().getLength());
|
||||||
|
|
||||||
|
Node planarConfiguration = data.getFirstChild();
|
||||||
|
assertEquals("PlanarConfiguration", planarConfiguration.getNodeName());
|
||||||
|
assertEquals("PixelInterleaved", ((Element) planarConfiguration).getAttribute("value"));
|
||||||
|
|
||||||
|
Node sampleFormat = planarConfiguration.getNextSibling();
|
||||||
|
assertEquals("SampleFormat", sampleFormat.getNodeName());
|
||||||
|
assertEquals("UnsignedIntegral", ((Element) sampleFormat).getAttribute("value"));
|
||||||
|
|
||||||
|
Node bitsPerSample = sampleFormat.getNextSibling();
|
||||||
|
assertEquals("BitsPerSample", bitsPerSample.getNodeName());
|
||||||
|
assertEquals("1", ((Element) bitsPerSample).getAttribute("value"));
|
||||||
|
|
||||||
|
Node sampleMSB = bitsPerSample.getNextSibling();
|
||||||
|
assertEquals("SampleMSB", sampleMSB.getNodeName());
|
||||||
|
assertEquals("0", ((Element) sampleMSB).getAttribute("value"));
|
||||||
|
|
||||||
|
// "Dimension"
|
||||||
|
Node dimension = data.getNextSibling();
|
||||||
|
assertEquals("Dimension", dimension.getNodeName());
|
||||||
|
assertEquals(4, dimension.getChildNodes().getLength());
|
||||||
|
|
||||||
|
Node pixelAspectRatio = dimension.getFirstChild();
|
||||||
|
assertEquals("PixelAspectRatio", pixelAspectRatio.getNodeName());
|
||||||
|
assertEquals("1.0", ((Element) pixelAspectRatio).getAttribute("value"));
|
||||||
|
|
||||||
|
Node imageOrientation = pixelAspectRatio.getNextSibling();
|
||||||
|
assertEquals("ImageOrientation", imageOrientation.getNodeName());
|
||||||
|
assertEquals("Normal", ((Element) imageOrientation).getAttribute("value"));
|
||||||
|
|
||||||
|
Node horizontalPixelSize = imageOrientation.getNextSibling();
|
||||||
|
assertEquals("HorizontalPixelSize", horizontalPixelSize.getNodeName());
|
||||||
|
assertEquals("0.08466666666666667", ((Element) horizontalPixelSize).getAttribute("value"));
|
||||||
|
|
||||||
|
Node verticalPixelSize = horizontalPixelSize.getNextSibling();
|
||||||
|
assertEquals("VerticalPixelSize", verticalPixelSize.getNodeName());
|
||||||
|
assertEquals("0.08466666666666667", ((Element) verticalPixelSize).getAttribute("value"));
|
||||||
|
|
||||||
|
// "Document"
|
||||||
|
Node document = dimension.getNextSibling();
|
||||||
|
assertEquals("Document", document.getNodeName());
|
||||||
|
assertEquals(1, document.getChildNodes().getLength());
|
||||||
|
|
||||||
|
Node formatVersion = document.getFirstChild();
|
||||||
|
assertEquals("FormatVersion", formatVersion.getNodeName());
|
||||||
|
assertEquals("6.0", ((Element) formatVersion).getAttribute("value"));
|
||||||
|
|
||||||
|
// No more elements
|
||||||
|
assertNull(document.getNextSibling());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMetadataNativeFormat() throws IOException {
|
public void testMetadataNativeFormat() throws IOException {
|
||||||
IIOMetadata metadata = createMetadata("/tiff/quad-lzw.tif");
|
IIOMetadata metadata = createMetadata("/tiff/quad-lzw.tif");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user