mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-10-04 11:26:44 -04:00
#204 TIFF metadata refactor
This commit is contained in:
@@ -28,6 +28,8 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.plugins.tiff;
|
||||
|
||||
import com.twelvemonkeys.imageio.metadata.tiff.TIFF;
|
||||
|
||||
/**
|
||||
* TIFFExtension
|
||||
*
|
||||
@@ -81,7 +83,7 @@ interface TIFFExtension {
|
||||
|
||||
/**
|
||||
* For use with Photometric: 5 (Separated), when image data is in a color space other than CMYK.
|
||||
* See {@link com.twelvemonkeys.imageio.metadata.exif.TIFF#TAG_INK_NAMES InkNames} field for a
|
||||
* See {@link TIFF#TAG_INK_NAMES InkNames} field for a
|
||||
* description of the inks to be used.
|
||||
*/
|
||||
int INKSET_NOT_CMYK = 2;
|
||||
|
@@ -29,11 +29,12 @@
|
||||
package com.twelvemonkeys.imageio.plugins.tiff;
|
||||
|
||||
import com.twelvemonkeys.imageio.AbstractMetadata;
|
||||
import com.twelvemonkeys.imageio.metadata.AbstractDirectory;
|
||||
import com.twelvemonkeys.imageio.metadata.Directory;
|
||||
import com.twelvemonkeys.imageio.metadata.Entry;
|
||||
import com.twelvemonkeys.imageio.metadata.exif.Rational;
|
||||
import com.twelvemonkeys.imageio.metadata.exif.TIFF;
|
||||
import com.twelvemonkeys.imageio.metadata.tiff.IFD;
|
||||
import com.twelvemonkeys.imageio.metadata.tiff.Rational;
|
||||
import com.twelvemonkeys.imageio.metadata.tiff.TIFF;
|
||||
import com.twelvemonkeys.imageio.metadata.tiff.TIFFEntry;
|
||||
import com.twelvemonkeys.lang.Validate;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
@@ -70,7 +71,7 @@ public final class TIFFImageMetadata extends AbstractMetadata {
|
||||
* or {@link #mergeTree(String, Node)} methods.
|
||||
*/
|
||||
public TIFFImageMetadata() {
|
||||
this(new TIFFIFD(Collections.<Entry>emptyList()));
|
||||
this(new IFD(Collections.<Entry>emptyList()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +95,7 @@ public final class TIFFImageMetadata extends AbstractMetadata {
|
||||
* or {@link #mergeTree(String, Node)} methods.
|
||||
*/
|
||||
public TIFFImageMetadata(final Collection<Entry> entries) {
|
||||
this(new TIFFIFD(entries));
|
||||
this(new IFD(entries));
|
||||
}
|
||||
|
||||
protected IIOMetadataNode getNativeTree() {
|
||||
@@ -921,7 +922,7 @@ public final class TIFFImageMetadata extends AbstractMetadata {
|
||||
// TODO: Consistency validation?
|
||||
|
||||
// Finally create a new IFD from merged values
|
||||
ifd = new TIFFIFD(entries.values());
|
||||
ifd = new IFD(entries.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -941,7 +942,7 @@ public final class TIFFImageMetadata extends AbstractMetadata {
|
||||
// TODO: Consistency validation?
|
||||
|
||||
// Finally create a new IFD from merged values
|
||||
ifd = new TIFFIFD(entries.values());
|
||||
ifd = new IFD(entries.values());
|
||||
}
|
||||
|
||||
private void mergeEntries(final String formatName, final Node root, final Map<Integer, Entry> entries) throws IIOInvalidTreeException {
|
||||
@@ -1027,25 +1028,25 @@ public final class TIFFImageMetadata extends AbstractMetadata {
|
||||
int x = Math.round(xRes * scale * RATIONAL_SCALE_FACTOR);
|
||||
int y = Math.round(yRes * scale * RATIONAL_SCALE_FACTOR);
|
||||
|
||||
entries.put(TIFF.TAG_X_RESOLUTION, new TIFFImageWriter.TIFFEntry(TIFF.TAG_X_RESOLUTION, new Rational(x, RATIONAL_SCALE_FACTOR)));
|
||||
entries.put(TIFF.TAG_Y_RESOLUTION, new TIFFImageWriter.TIFFEntry(TIFF.TAG_Y_RESOLUTION, new Rational(y, RATIONAL_SCALE_FACTOR)));
|
||||
entries.put(TIFF.TAG_X_RESOLUTION, new TIFFEntry(TIFF.TAG_X_RESOLUTION, new Rational(x, RATIONAL_SCALE_FACTOR)));
|
||||
entries.put(TIFF.TAG_Y_RESOLUTION, new TIFFEntry(TIFF.TAG_Y_RESOLUTION, new Rational(y, RATIONAL_SCALE_FACTOR)));
|
||||
entries.put(TIFF.TAG_RESOLUTION_UNIT,
|
||||
new TIFFImageWriter.TIFFEntry(TIFF.TAG_RESOLUTION_UNIT, TIFF.TYPE_SHORT, resUnitValue));
|
||||
new TIFFEntry(TIFF.TAG_RESOLUTION_UNIT, TIFF.TYPE_SHORT, resUnitValue));
|
||||
}
|
||||
else if (aspect != null) {
|
||||
if (aspect >= 1) {
|
||||
int v = Math.round(aspect * RATIONAL_SCALE_FACTOR);
|
||||
entries.put(TIFF.TAG_X_RESOLUTION, new TIFFImageWriter.TIFFEntry(TIFF.TAG_X_RESOLUTION, new Rational(v, RATIONAL_SCALE_FACTOR)));
|
||||
entries.put(TIFF.TAG_Y_RESOLUTION, new TIFFImageWriter.TIFFEntry(TIFF.TAG_Y_RESOLUTION, new Rational(1)));
|
||||
entries.put(TIFF.TAG_X_RESOLUTION, new TIFFEntry(TIFF.TAG_X_RESOLUTION, new Rational(v, RATIONAL_SCALE_FACTOR)));
|
||||
entries.put(TIFF.TAG_Y_RESOLUTION, new TIFFEntry(TIFF.TAG_Y_RESOLUTION, new Rational(1)));
|
||||
}
|
||||
else {
|
||||
int v = Math.round(RATIONAL_SCALE_FACTOR / aspect);
|
||||
entries.put(TIFF.TAG_X_RESOLUTION, new TIFFImageWriter.TIFFEntry(TIFF.TAG_X_RESOLUTION, new Rational(1)));
|
||||
entries.put(TIFF.TAG_Y_RESOLUTION, new TIFFImageWriter.TIFFEntry(TIFF.TAG_Y_RESOLUTION, new Rational(v, RATIONAL_SCALE_FACTOR)));
|
||||
entries.put(TIFF.TAG_X_RESOLUTION, new TIFFEntry(TIFF.TAG_X_RESOLUTION, new Rational(1)));
|
||||
entries.put(TIFF.TAG_Y_RESOLUTION, new TIFFEntry(TIFF.TAG_Y_RESOLUTION, new Rational(v, RATIONAL_SCALE_FACTOR)));
|
||||
}
|
||||
|
||||
entries.put(TIFF.TAG_RESOLUTION_UNIT,
|
||||
new TIFFImageWriter.TIFFEntry(TIFF.TAG_RESOLUTION_UNIT, TIFF.TYPE_SHORT, TIFFBaseline.RESOLUTION_UNIT_NONE));
|
||||
new TIFFEntry(TIFF.TAG_RESOLUTION_UNIT, TIFF.TYPE_SHORT, TIFFBaseline.RESOLUTION_UNIT_NONE));
|
||||
}
|
||||
// Else give up...
|
||||
}
|
||||
@@ -1086,37 +1087,37 @@ public final class TIFFImageMetadata extends AbstractMetadata {
|
||||
// We do all comparisons in lower case, for compatibility
|
||||
keyword = keyword.toLowerCase();
|
||||
|
||||
TIFFImageWriter.TIFFEntry entry;
|
||||
TIFFEntry entry;
|
||||
|
||||
if ("documentname".equals(keyword)) {
|
||||
entry = new TIFFImageWriter.TIFFEntry(TIFF.TAG_DOCUMENT_NAME, TIFF.TYPE_ASCII, value);
|
||||
entry = new TIFFEntry(TIFF.TAG_DOCUMENT_NAME, TIFF.TYPE_ASCII, value);
|
||||
}
|
||||
else if ("imagedescription".equals(keyword)) {
|
||||
entry = new TIFFImageWriter.TIFFEntry(TIFF.TAG_IMAGE_DESCRIPTION, TIFF.TYPE_ASCII, value);
|
||||
entry = new TIFFEntry(TIFF.TAG_IMAGE_DESCRIPTION, TIFF.TYPE_ASCII, value);
|
||||
}
|
||||
else if ("make".equals(keyword)) {
|
||||
entry = new TIFFImageWriter.TIFFEntry(TIFF.TAG_MAKE, TIFF.TYPE_ASCII, value);
|
||||
entry = new TIFFEntry(TIFF.TAG_MAKE, TIFF.TYPE_ASCII, value);
|
||||
}
|
||||
else if ("model".equals(keyword)) {
|
||||
entry = new TIFFImageWriter.TIFFEntry(TIFF.TAG_MODEL, TIFF.TYPE_ASCII, value);
|
||||
entry = new TIFFEntry(TIFF.TAG_MODEL, TIFF.TYPE_ASCII, value);
|
||||
}
|
||||
else if ("pagename".equals(keyword)) {
|
||||
entry = new TIFFImageWriter.TIFFEntry(TIFF.TAG_PAGE_NAME, TIFF.TYPE_ASCII, value);
|
||||
entry = new TIFFEntry(TIFF.TAG_PAGE_NAME, TIFF.TYPE_ASCII, value);
|
||||
}
|
||||
else if ("software".equals(keyword)) {
|
||||
entry = new TIFFImageWriter.TIFFEntry(TIFF.TAG_SOFTWARE, TIFF.TYPE_ASCII, value);
|
||||
entry = new TIFFEntry(TIFF.TAG_SOFTWARE, TIFF.TYPE_ASCII, value);
|
||||
}
|
||||
else if ("artist".equals(keyword)) {
|
||||
entry = new TIFFImageWriter.TIFFEntry(TIFF.TAG_ARTIST, TIFF.TYPE_ASCII, value);
|
||||
entry = new TIFFEntry(TIFF.TAG_ARTIST, TIFF.TYPE_ASCII, value);
|
||||
}
|
||||
else if ("hostcomputer".equals(keyword)) {
|
||||
entry = new TIFFImageWriter.TIFFEntry(TIFF.TAG_HOST_COMPUTER, TIFF.TYPE_ASCII, value);
|
||||
entry = new TIFFEntry(TIFF.TAG_HOST_COMPUTER, TIFF.TYPE_ASCII, value);
|
||||
}
|
||||
else if ("inknames".equals(keyword)) {
|
||||
entry = new TIFFImageWriter.TIFFEntry(TIFF.TAG_INK_NAMES, TIFF.TYPE_ASCII, value);
|
||||
entry = new TIFFEntry(TIFF.TAG_INK_NAMES, TIFF.TYPE_ASCII, value);
|
||||
}
|
||||
else if ("copyright".equals(keyword)) {
|
||||
entry = new TIFFImageWriter.TIFFEntry(TIFF.TAG_COPYRIGHT, TIFF.TYPE_ASCII, value);
|
||||
entry = new TIFFEntry(TIFF.TAG_COPYRIGHT, TIFF.TYPE_ASCII, value);
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
@@ -1148,7 +1149,7 @@ public final class TIFFImageMetadata extends AbstractMetadata {
|
||||
entries.add(toEntry(nodes.item(i)));
|
||||
}
|
||||
|
||||
return new TIFFIFD(entries);
|
||||
return new IFD(entries);
|
||||
}
|
||||
|
||||
private Entry toEntry(final Node node) throws IIOInvalidTreeException {
|
||||
@@ -1158,14 +1159,14 @@ public final class TIFFImageMetadata extends AbstractMetadata {
|
||||
int tag = Integer.parseInt(getAttribute(node, "parentTagNumber"));
|
||||
Directory subIFD = toIFD(node);
|
||||
|
||||
return new TIFFImageWriter.TIFFEntry(tag, TIFF.TYPE_IFD, subIFD);
|
||||
return new TIFFEntry(tag, TIFF.TYPE_IFD, subIFD);
|
||||
}
|
||||
else if (name.equals("TIFFField")) {
|
||||
int tag = Integer.parseInt(getAttribute(node, "number"));
|
||||
short type = getTIFFType(node);
|
||||
Object value = getValue(node, type);
|
||||
|
||||
return value != null ? new TIFFImageWriter.TIFFEntry(tag, type, value) : null;
|
||||
return value != null ? new TIFFEntry(tag, type, value) : null;
|
||||
}
|
||||
else {
|
||||
throw new IIOInvalidTreeException("Expected \"TIFFIFD\" or \"TIFFField\" node: " + name, node);
|
||||
@@ -1337,11 +1338,4 @@ public final class TIFFImageMetadata extends AbstractMetadata {
|
||||
public Entry getTIFFField(final int tagNumber) {
|
||||
return ifd.getEntryById(tagNumber);
|
||||
}
|
||||
|
||||
// TODO: Replace with IFD class when moved to new package and made public!
|
||||
private final static class TIFFIFD extends AbstractDirectory {
|
||||
public TIFFIFD(final Collection<Entry> entries) {
|
||||
super(entries);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -36,12 +36,12 @@ import com.twelvemonkeys.imageio.color.YCbCrConverter;
|
||||
import com.twelvemonkeys.imageio.metadata.CompoundDirectory;
|
||||
import com.twelvemonkeys.imageio.metadata.Directory;
|
||||
import com.twelvemonkeys.imageio.metadata.Entry;
|
||||
import com.twelvemonkeys.imageio.metadata.exif.EXIFReader;
|
||||
import com.twelvemonkeys.imageio.metadata.exif.Rational;
|
||||
import com.twelvemonkeys.imageio.metadata.exif.TIFF;
|
||||
import com.twelvemonkeys.imageio.metadata.iptc.IPTCReader;
|
||||
import com.twelvemonkeys.imageio.metadata.jpeg.JPEG;
|
||||
import com.twelvemonkeys.imageio.metadata.psd.PSDReader;
|
||||
import com.twelvemonkeys.imageio.metadata.tiff.Rational;
|
||||
import com.twelvemonkeys.imageio.metadata.tiff.TIFF;
|
||||
import com.twelvemonkeys.imageio.metadata.tiff.TIFFReader;
|
||||
import com.twelvemonkeys.imageio.metadata.xmp.XMPReader;
|
||||
import com.twelvemonkeys.imageio.stream.ByteArrayImageInputStream;
|
||||
import com.twelvemonkeys.imageio.stream.SubImageInputStream;
|
||||
@@ -171,7 +171,7 @@ public final class TIFFImageReader extends ImageReaderBase {
|
||||
}
|
||||
|
||||
if (IFDs == null) {
|
||||
IFDs = (CompoundDirectory) new EXIFReader().read(imageInput); // NOTE: Sets byte order as a side effect
|
||||
IFDs = (CompoundDirectory) new TIFFReader().read(imageInput); // NOTE: Sets byte order as a side effect
|
||||
|
||||
if (DEBUG) {
|
||||
System.err.println("Byte order: " + imageInput.getByteOrder());
|
||||
|
@@ -28,7 +28,7 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.plugins.tiff;
|
||||
|
||||
import com.twelvemonkeys.imageio.metadata.exif.TIFF;
|
||||
import com.twelvemonkeys.imageio.metadata.tiff.TIFF;
|
||||
import com.twelvemonkeys.imageio.spi.ImageReaderSpiBase;
|
||||
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
|
@@ -30,12 +30,12 @@ package com.twelvemonkeys.imageio.plugins.tiff;
|
||||
|
||||
import com.twelvemonkeys.image.ImageUtil;
|
||||
import com.twelvemonkeys.imageio.ImageWriterBase;
|
||||
import com.twelvemonkeys.imageio.metadata.AbstractEntry;
|
||||
import com.twelvemonkeys.imageio.metadata.Directory;
|
||||
import com.twelvemonkeys.imageio.metadata.Entry;
|
||||
import com.twelvemonkeys.imageio.metadata.exif.EXIFWriter;
|
||||
import com.twelvemonkeys.imageio.metadata.exif.Rational;
|
||||
import com.twelvemonkeys.imageio.metadata.exif.TIFF;
|
||||
import com.twelvemonkeys.imageio.metadata.tiff.Rational;
|
||||
import com.twelvemonkeys.imageio.metadata.tiff.TIFF;
|
||||
import com.twelvemonkeys.imageio.metadata.tiff.TIFFEntry;
|
||||
import com.twelvemonkeys.imageio.metadata.tiff.TIFFWriter;
|
||||
import com.twelvemonkeys.imageio.stream.SubImageOutputStream;
|
||||
import com.twelvemonkeys.imageio.util.IIOUtil;
|
||||
import com.twelvemonkeys.io.enc.EncoderStream;
|
||||
@@ -54,7 +54,6 @@ import java.awt.color.ColorSpace;
|
||||
import java.awt.color.ICC_ColorSpace;
|
||||
import java.awt.image.*;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Array;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
import java.util.zip.Deflater;
|
||||
@@ -111,7 +110,7 @@ public final class TIFFImageWriter extends ImageWriterBase {
|
||||
/**
|
||||
* Metadata writer for sequence writing
|
||||
*/
|
||||
private EXIFWriter sequenceExifWriter = null;
|
||||
private TIFFWriter sequenceTiffWriter = null;
|
||||
|
||||
/**
|
||||
* Position of last IFD Pointer on active sequence writing
|
||||
@@ -129,87 +128,21 @@ public final class TIFFImageWriter extends ImageWriterBase {
|
||||
// TODO: Allow appending/partly overwrite of existing file...
|
||||
}
|
||||
|
||||
static final class TIFFEntry extends AbstractEntry {
|
||||
// TODO: Expose a merge of this and the EXIFEntry class...
|
||||
private final short type;
|
||||
|
||||
private static short guessType(final Object val) {
|
||||
// TODO: This code is duplicated in EXIFWriter.getType, needs refactor!
|
||||
Object value = Validate.notNull(val);
|
||||
|
||||
boolean array = value.getClass().isArray();
|
||||
if (array) {
|
||||
value = Array.get(value, 0);
|
||||
}
|
||||
|
||||
// Note: This "narrowing" is to keep data consistent between read/write.
|
||||
// TODO: Check for negative values and use signed types?
|
||||
if (value instanceof Byte) {
|
||||
return TIFF.TYPE_BYTE;
|
||||
}
|
||||
if (value instanceof Short) {
|
||||
if (!array && (Short) value < Byte.MAX_VALUE) {
|
||||
return TIFF.TYPE_BYTE;
|
||||
}
|
||||
|
||||
return TIFF.TYPE_SHORT;
|
||||
}
|
||||
if (value instanceof Integer) {
|
||||
if (!array && (Integer) value < Short.MAX_VALUE) {
|
||||
return TIFF.TYPE_SHORT;
|
||||
}
|
||||
|
||||
return TIFF.TYPE_LONG;
|
||||
}
|
||||
if (value instanceof Long) {
|
||||
if (!array && (Long) value < Integer.MAX_VALUE) {
|
||||
return TIFF.TYPE_LONG;
|
||||
}
|
||||
}
|
||||
|
||||
if (value instanceof Rational) {
|
||||
return TIFF.TYPE_RATIONAL;
|
||||
}
|
||||
|
||||
if (value instanceof String) {
|
||||
return TIFF.TYPE_ASCII;
|
||||
}
|
||||
|
||||
// TODO: More types
|
||||
|
||||
throw new UnsupportedOperationException(String.format("Method guessType not implemented for value of type %s", value.getClass()));
|
||||
}
|
||||
|
||||
TIFFEntry(final int identifier, final Object value) {
|
||||
this(identifier, guessType(value), value);
|
||||
}
|
||||
|
||||
TIFFEntry(int identifier, short type, Object value) {
|
||||
super(identifier, value);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return TIFF.TYPE_NAMES[type];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final IIOMetadata streamMetadata, final IIOImage image, final ImageWriteParam param) throws IOException {
|
||||
assertOutput();
|
||||
configureStreamByteOrder(streamMetadata, imageOutput);
|
||||
|
||||
// TODO: Make TIFFEntry and possibly TIFFDirectory? public
|
||||
EXIFWriter exifWriter = new EXIFWriter();
|
||||
exifWriter.writeTIFFHeader(imageOutput);
|
||||
TIFFWriter tiffWriter = new TIFFWriter();
|
||||
tiffWriter.writeTIFFHeader(imageOutput);
|
||||
|
||||
writePage(image, param, exifWriter, imageOutput.getStreamPosition());
|
||||
writePage(image, param, tiffWriter, imageOutput.getStreamPosition());
|
||||
|
||||
imageOutput.flush();
|
||||
}
|
||||
|
||||
private long writePage(IIOImage image, ImageWriteParam param, EXIFWriter exifWriter, long lastIFDPointerOffset)
|
||||
private long writePage(IIOImage image, ImageWriteParam param, TIFFWriter tiffWriter, long lastIFDPointerOffset)
|
||||
throws IOException {
|
||||
RenderedImage renderedImage = image.getRenderedImage();
|
||||
|
||||
@@ -382,14 +315,14 @@ public final class TIFFImageWriter extends ImageWriterBase {
|
||||
// This implementation, allows semi-streaming-compatible uncompressed TIFFs
|
||||
long streamPosition = imageOutput.getStreamPosition();
|
||||
|
||||
long ifdSize = exifWriter.computeIFDSize(entries.values());
|
||||
long ifdSize = tiffWriter.computeIFDSize(entries.values());
|
||||
long stripOffset = streamPosition + 4 + ifdSize + 4;
|
||||
long stripByteCount = (renderedImage.getWidth() * renderedImage.getHeight() * pixelSize + 7) / 8;
|
||||
|
||||
entries.put(TIFF.TAG_STRIP_OFFSETS, new TIFFEntry(TIFF.TAG_STRIP_OFFSETS, stripOffset));
|
||||
entries.put(TIFF.TAG_STRIP_BYTE_COUNTS, new TIFFEntry(TIFF.TAG_STRIP_BYTE_COUNTS, stripByteCount));
|
||||
|
||||
long ifdPointer = exifWriter.writeIFD(entries.values(), imageOutput); // NOTE: Writer takes case of ordering tags
|
||||
long ifdPointer = tiffWriter.writeIFD(entries.values(), imageOutput); // NOTE: Writer takes case of ordering tags
|
||||
nextIFDPointerOffset = imageOutput.getStreamPosition();
|
||||
|
||||
// If we have a previous IFD, update pointer
|
||||
@@ -438,7 +371,7 @@ public final class TIFFImageWriter extends ImageWriterBase {
|
||||
entries.put(TIFF.TAG_STRIP_OFFSETS, new TIFFEntry(TIFF.TAG_STRIP_OFFSETS, stripOffset));
|
||||
entries.put(TIFF.TAG_STRIP_BYTE_COUNTS, new TIFFEntry(TIFF.TAG_STRIP_BYTE_COUNTS, stripByteCount));
|
||||
|
||||
long ifdPointer = exifWriter.writeIFD(entries.values(), imageOutput); // NOTE: Writer takes case of ordering tags
|
||||
long ifdPointer = tiffWriter.writeIFD(entries.values(), imageOutput); // NOTE: Writer takes case of ordering tags
|
||||
|
||||
nextIFDPointerOffset = imageOutput.getStreamPosition();
|
||||
|
||||
@@ -958,8 +891,8 @@ public final class TIFFImageWriter extends ImageWriterBase {
|
||||
// Ignore streamMetadata. ByteOrder is determined from OutputStream
|
||||
assertOutput();
|
||||
isWritingSequence = true;
|
||||
sequenceExifWriter = new EXIFWriter();
|
||||
sequenceExifWriter.writeTIFFHeader(imageOutput);
|
||||
sequenceTiffWriter = new TIFFWriter();
|
||||
sequenceTiffWriter.writeTIFFHeader(imageOutput);
|
||||
sequenceLastIFDPos = imageOutput.getStreamPosition();
|
||||
}
|
||||
|
||||
@@ -973,7 +906,7 @@ public final class TIFFImageWriter extends ImageWriterBase {
|
||||
imageOutput.flushBefore(sequenceLastIFDPos);
|
||||
}
|
||||
|
||||
sequenceLastIFDPos = writePage(image, param, sequenceExifWriter, sequenceLastIFDPos);
|
||||
sequenceLastIFDPos = writePage(image, param, sequenceTiffWriter, sequenceLastIFDPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -983,7 +916,7 @@ public final class TIFFImageWriter extends ImageWriterBase {
|
||||
}
|
||||
|
||||
isWritingSequence = false;
|
||||
sequenceExifWriter = null;
|
||||
sequenceTiffWriter = null;
|
||||
sequenceLastIFDPos = -1;
|
||||
imageOutput.flush();
|
||||
}
|
||||
@@ -993,7 +926,7 @@ public final class TIFFImageWriter extends ImageWriterBase {
|
||||
super.resetMembers();
|
||||
|
||||
isWritingSequence = false;
|
||||
sequenceExifWriter = null;
|
||||
sequenceTiffWriter = null;
|
||||
sequenceLastIFDPos = -1;
|
||||
}
|
||||
|
||||
|
@@ -2,9 +2,10 @@ package com.twelvemonkeys.imageio.plugins.tiff;
|
||||
|
||||
import com.twelvemonkeys.imageio.metadata.Directory;
|
||||
import com.twelvemonkeys.imageio.metadata.Entry;
|
||||
import com.twelvemonkeys.imageio.metadata.exif.EXIFReader;
|
||||
import com.twelvemonkeys.imageio.metadata.exif.Rational;
|
||||
import com.twelvemonkeys.imageio.metadata.exif.TIFF;
|
||||
import com.twelvemonkeys.imageio.metadata.tiff.Rational;
|
||||
import com.twelvemonkeys.imageio.metadata.tiff.TIFF;
|
||||
import com.twelvemonkeys.imageio.metadata.tiff.TIFFEntry;
|
||||
import com.twelvemonkeys.imageio.metadata.tiff.TIFFReader;
|
||||
import com.twelvemonkeys.imageio.stream.URLImageInputStreamSpi;
|
||||
import com.twelvemonkeys.lang.StringUtil;
|
||||
import org.junit.Test;
|
||||
@@ -49,7 +50,7 @@ public class TIFFImageMetadataTest {
|
||||
// TODO: Candidate abstract super method
|
||||
private IIOMetadata createMetadata(final String resource) throws IOException {
|
||||
try (ImageInputStream input = ImageIO.createImageInputStream(getClassLoaderResource(resource))) {
|
||||
Directory ifd = new EXIFReader().read(input);
|
||||
Directory ifd = new TIFFReader().read(input);
|
||||
// System.err.println("ifd: " + ifd);
|
||||
return new TIFFImageMetadata(ifd);
|
||||
}
|
||||
@@ -477,9 +478,9 @@ public class TIFFImageMetadataTest {
|
||||
@Test
|
||||
public void testStandardChromaSamplesPerPixel() {
|
||||
Set<Entry> entries = new HashSet<>();
|
||||
entries.add(new TIFFImageWriter.TIFFEntry(TIFF.TAG_PHOTOMETRIC_INTERPRETATION, TIFFBaseline.PHOTOMETRIC_RGB));
|
||||
entries.add(new TIFFImageWriter.TIFFEntry(TIFF.TAG_SAMPLES_PER_PIXEL, 4));
|
||||
entries.add(new TIFFImageWriter.TIFFEntry(TIFF.TAG_BITS_PER_SAMPLE, new int[] {8, 8, 8})); // This is incorrect, just making sure the correct value is selected
|
||||
entries.add(new TIFFEntry(TIFF.TAG_PHOTOMETRIC_INTERPRETATION, TIFFBaseline.PHOTOMETRIC_RGB));
|
||||
entries.add(new TIFFEntry(TIFF.TAG_SAMPLES_PER_PIXEL, 4));
|
||||
entries.add(new TIFFEntry(TIFF.TAG_BITS_PER_SAMPLE, new int[] {8, 8, 8})); // This is incorrect, just making sure the correct value is selected
|
||||
|
||||
IIOMetadataNode chromaNode = new TIFFImageMetadata(entries).getStandardChromaNode();
|
||||
assertNotNull(chromaNode);
|
||||
@@ -491,8 +492,8 @@ public class TIFFImageMetadataTest {
|
||||
@Test
|
||||
public void testStandardChromaSamplesPerPixelFallbackBitsPerSample() {
|
||||
Set<Entry> entries = new HashSet<>();
|
||||
entries.add(new TIFFImageWriter.TIFFEntry(TIFF.TAG_PHOTOMETRIC_INTERPRETATION, TIFFBaseline.PHOTOMETRIC_RGB));
|
||||
entries.add(new TIFFImageWriter.TIFFEntry(TIFF.TAG_BITS_PER_SAMPLE, new int[] {8, 8, 8}));
|
||||
entries.add(new TIFFEntry(TIFF.TAG_PHOTOMETRIC_INTERPRETATION, TIFFBaseline.PHOTOMETRIC_RGB));
|
||||
entries.add(new TIFFEntry(TIFF.TAG_BITS_PER_SAMPLE, new int[] {8, 8, 8}));
|
||||
|
||||
IIOMetadataNode chromaNode = new TIFFImageMetadata(entries).getStandardChromaNode();
|
||||
assertNotNull(chromaNode);
|
||||
@@ -504,7 +505,7 @@ public class TIFFImageMetadataTest {
|
||||
@Test
|
||||
public void testStandardChromaSamplesPerPixelFallbackDefault() {
|
||||
Set<Entry> entries = new HashSet<>();
|
||||
entries.add(new TIFFImageWriter.TIFFEntry(TIFF.TAG_PHOTOMETRIC_INTERPRETATION, TIFFBaseline.PHOTOMETRIC_BLACK_IS_ZERO));
|
||||
entries.add(new TIFFEntry(TIFF.TAG_PHOTOMETRIC_INTERPRETATION, TIFFBaseline.PHOTOMETRIC_BLACK_IS_ZERO));
|
||||
|
||||
IIOMetadataNode chromaNode = new TIFFImageMetadata(entries).getStandardChromaNode();
|
||||
assertNotNull(chromaNode);
|
||||
@@ -515,7 +516,7 @@ public class TIFFImageMetadataTest {
|
||||
@Test
|
||||
public void testStandardDataBitsPerSampleFallbackDefault() {
|
||||
Set<Entry> entries = new HashSet<>();
|
||||
entries.add(new TIFFImageWriter.TIFFEntry(TIFF.TAG_PHOTOMETRIC_INTERPRETATION, TIFFBaseline.PHOTOMETRIC_BLACK_IS_ZERO));
|
||||
entries.add(new TIFFEntry(TIFF.TAG_PHOTOMETRIC_INTERPRETATION, TIFFBaseline.PHOTOMETRIC_BLACK_IS_ZERO));
|
||||
|
||||
IIOMetadataNode dataNode = new TIFFImageMetadata(entries).getStandardDataNode();
|
||||
assertNotNull(dataNode);
|
||||
@@ -526,7 +527,7 @@ public class TIFFImageMetadataTest {
|
||||
@Test
|
||||
public void testStandardNodeSamplesPerPixelFallbackDefault() {
|
||||
Set<Entry> entries = new HashSet<>();
|
||||
entries.add(new TIFFImageWriter.TIFFEntry(TIFF.TAG_PHOTOMETRIC_INTERPRETATION, TIFFBaseline.PHOTOMETRIC_RGB));
|
||||
entries.add(new TIFFEntry(TIFF.TAG_PHOTOMETRIC_INTERPRETATION, TIFFBaseline.PHOTOMETRIC_RGB));
|
||||
|
||||
// Just to make sure we haven't accidentally missed something
|
||||
IIOMetadataNode standardTree = (IIOMetadataNode) new TIFFImageMetadata(entries).getAsTree(IIOMetadataFormatImpl.standardMetadataFormatName);
|
||||
@@ -656,4 +657,4 @@ public class TIFFImageMetadataTest {
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -30,9 +30,9 @@ package com.twelvemonkeys.imageio.plugins.tiff;
|
||||
|
||||
import com.twelvemonkeys.imageio.metadata.Directory;
|
||||
import com.twelvemonkeys.imageio.metadata.Entry;
|
||||
import com.twelvemonkeys.imageio.metadata.exif.EXIFReader;
|
||||
import com.twelvemonkeys.imageio.metadata.exif.Rational;
|
||||
import com.twelvemonkeys.imageio.metadata.exif.TIFF;
|
||||
import com.twelvemonkeys.imageio.metadata.tiff.Rational;
|
||||
import com.twelvemonkeys.imageio.metadata.tiff.TIFF;
|
||||
import com.twelvemonkeys.imageio.metadata.tiff.TIFFReader;
|
||||
import com.twelvemonkeys.imageio.stream.ByteArrayImageInputStream;
|
||||
import com.twelvemonkeys.imageio.util.ImageWriterAbstractTestCase;
|
||||
import com.twelvemonkeys.io.FastByteArrayOutputStream;
|
||||
@@ -131,7 +131,7 @@ public class TIFFImageWriterTest extends ImageWriterAbstractTestCase {
|
||||
|
||||
assertTrue("No image data written", buffer.size() > 0);
|
||||
|
||||
Directory ifds = new EXIFReader().read(new ByteArrayImageInputStream(buffer.toByteArray()));
|
||||
Directory ifds = new TIFFReader().read(new ByteArrayImageInputStream(buffer.toByteArray()));
|
||||
|
||||
Entry resolutionUnit = ifds.getEntryById(TIFF.TAG_RESOLUTION_UNIT);
|
||||
assertNotNull(resolutionUnit);
|
||||
@@ -179,7 +179,7 @@ public class TIFFImageWriterTest extends ImageWriterAbstractTestCase {
|
||||
|
||||
assertTrue("No image data written", buffer.size() > 0);
|
||||
|
||||
Directory ifds = new EXIFReader().read(new ByteArrayImageInputStream(buffer.toByteArray()));
|
||||
Directory ifds = new TIFFReader().read(new ByteArrayImageInputStream(buffer.toByteArray()));
|
||||
Entry software = ifds.getEntryById(TIFF.TAG_SOFTWARE);
|
||||
assertNotNull(software);
|
||||
assertEquals(softwareString, software.getValueAsString());
|
||||
@@ -227,7 +227,7 @@ public class TIFFImageWriterTest extends ImageWriterAbstractTestCase {
|
||||
|
||||
assertTrue("No image data written", buffer.size() > 0);
|
||||
|
||||
Directory ifds = new EXIFReader().read(new ByteArrayImageInputStream(buffer.toByteArray()));
|
||||
Directory ifds = new TIFFReader().read(new ByteArrayImageInputStream(buffer.toByteArray()));
|
||||
|
||||
Entry resolutionUnit = ifds.getEntryById(TIFF.TAG_RESOLUTION_UNIT);
|
||||
assertNotNull(resolutionUnit);
|
||||
@@ -278,7 +278,7 @@ public class TIFFImageWriterTest extends ImageWriterAbstractTestCase {
|
||||
|
||||
assertTrue("No image data written", buffer.size() > 0);
|
||||
|
||||
Directory ifds = new EXIFReader().read(new ByteArrayImageInputStream(buffer.toByteArray()));
|
||||
Directory ifds = new TIFFReader().read(new ByteArrayImageInputStream(buffer.toByteArray()));
|
||||
Entry software = ifds.getEntryById(TIFF.TAG_SOFTWARE);
|
||||
assertNotNull(software);
|
||||
assertEquals(softwareString, software.getValueAsString());
|
||||
|
Reference in New Issue
Block a user