summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarolyn MacLeod <carolyn>2009-08-11 15:05:29 +0000
committerCarolyn MacLeod <carolyn>2009-08-11 15:05:29 +0000
commitdd0862c01e9b993d658b395af820f586129ec8a1 (patch)
treeaf9be56b2a129b2e9b6dafc52a93163b8711e1cb
parent3592e964ac5b7db50141d6962fe69da4f0c9d091 (diff)
downloadeclipse.platform.swt-dd0862c01e9b993d658b395af820f586129ec8a1.tar.gz
eclipse.platform.swt-dd0862c01e9b993d658b395af820f586129ec8a1.tar.xz
eclipse.platform.swt-dd0862c01e9b993d658b395af820f586129ec8a1.zip
212773 - Multipage TIFF image is not supported
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFDirectory.java54
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFFileFormat.java16
2 files changed, 64 insertions, 6 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFDirectory.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFDirectory.java
index 053be45cfd..4a882d2e5e 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFDirectory.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFDirectory.java
@@ -23,6 +23,7 @@ final class TIFFDirectory {
int depth;
/* Directory fields */
+ int subfileType;
int imageWidth;
int imageLength;
int[] bitsPerSample;
@@ -41,19 +42,27 @@ final class TIFFDirectory {
static final int NO_VALUE = -1;
+ static final short TAG_NewSubfileType = 254;
+ static final short TAG_SubfileType = 255;
static final short TAG_ImageWidth = 256;
static final short TAG_ImageLength = 257;
static final short TAG_BitsPerSample = 258;
static final short TAG_Compression = 259;
static final short TAG_PhotometricInterpretation = 262;
+ static final short TAG_FillOrder = 266;
+ static final short TAG_ImageDescription = 270;
static final short TAG_StripOffsets = 273;
+ static final short TAG_Orientation = 274;
static final short TAG_SamplesPerPixel = 277;
static final short TAG_RowsPerStrip = 278;
static final short TAG_StripByteCounts = 279;
static final short TAG_XResolution = 282;
static final short TAG_YResolution = 283;
+ static final short TAG_PlanarConfiguration = 284;
static final short TAG_T4Options = 292;
static final short TAG_ResolutionUnit = 296;
+ static final short TAG_Software = 305;
+ static final short TAG_DateTime = 306;
static final short TAG_ColorMap = 320;
static final int TYPE_BYTE = 1;
@@ -62,6 +71,13 @@ final class TIFFDirectory {
static final int TYPE_LONG = 4;
static final int TYPE_RATIONAL = 5;
+ static final int FILETYPE_REDUCEDIMAGE = 1;
+ static final int FILETYPE_PAGE = 2;
+ static final int FILETYPE_MASK = 4;
+ static final int OFILETYPE_IMAGE = 1;
+ static final int OFILETYPE_REDUCEDIMAGE = 2;
+ static final int OFILETYPE_PAGE = 3;
+
/* Different compression schemes */
static final int COMPRESSION_NONE = 1;
static final int COMPRESSION_CCITT_3_1 = 2;
@@ -299,6 +315,15 @@ void parseEntries(byte[] buffer) throws IOException {
int type = toInt(buffer, offset + 2, TYPE_SHORT);
int count = toInt(buffer, offset + 4, TYPE_LONG);
switch (tag) {
+ case TAG_NewSubfileType: {
+ subfileType = getEntryValue(type, buffer, offset);
+ break;
+ }
+ case TAG_SubfileType: {
+ int oldSubfileType = getEntryValue(type, buffer, offset);
+ subfileType = oldSubfileType == OFILETYPE_REDUCEDIMAGE ? FILETYPE_REDUCEDIMAGE : oldSubfileType == OFILETYPE_PAGE ? FILETYPE_PAGE : 0;
+ break;
+ }
case TAG_ImageWidth: {
imageWidth = getEntryValue(type, buffer, offset);
break;
@@ -317,6 +342,14 @@ void parseEntries(byte[] buffer) throws IOException {
compression = getEntryValue(type, buffer, offset);
break;
}
+ case TAG_FillOrder: {
+ /* Ignored: baseline only requires default fill order. */
+ break;
+ }
+ case TAG_ImageDescription: {
+ /* Ignored */
+ break;
+ }
case TAG_PhotometricInterpretation: {
photometricInterpretation = getEntryValue(type, buffer, offset);
break;
@@ -327,6 +360,10 @@ void parseEntries(byte[] buffer) throws IOException {
getEntryValue(type, buffer, offset, stripOffsets);
break;
}
+ case TAG_Orientation: {
+ /* Ignored: baseline only requires top left orientation. */
+ break;
+ }
case TAG_SamplesPerPixel: {
if (type != TYPE_SHORT) SWT.error(SWT.ERROR_INVALID_IMAGE);
samplesPerPixel = getEntryValue(type, buffer, offset);
@@ -351,6 +388,10 @@ void parseEntries(byte[] buffer) throws IOException {
/* Ignored */
break;
}
+ case TAG_PlanarConfiguration: {
+ /* Ignored: baseline only requires default planar configuration. */
+ break;
+ }
case TAG_T4Options: {
if (type != TYPE_LONG) SWT.error(SWT.ERROR_INVALID_IMAGE);
t4Options = getEntryValue(type, buffer, offset);
@@ -364,6 +405,14 @@ void parseEntries(byte[] buffer) throws IOException {
/* Ignored */
break;
}
+ case TAG_Software: {
+ /* Ignored */
+ break;
+ }
+ case TAG_DateTime: {
+ /* Ignored */
+ break;
+ }
case TAG_ColorMap: {
if (type != TYPE_SHORT) SWT.error(SWT.ERROR_INVALID_IMAGE);
/* Get the offset of the colorMap (use TYPE_LONG) */
@@ -374,7 +423,7 @@ void parseEntries(byte[] buffer) throws IOException {
}
}
-public ImageData read() throws IOException {
+public ImageData read(int [] nextIFDOffset) throws IOException {
/* Set TIFF default values */
bitsPerSample = new int[] {1};
colorMapOffset = NO_VALUE;
@@ -392,6 +441,9 @@ public ImageData read() throws IOException {
int numberEntries = toInt(buffer, 0, TYPE_SHORT);
buffer = new byte[IFD_ENTRY_SIZE * numberEntries];
file.read(buffer);
+ byte buffer2[] = new byte[4];
+ file.read(buffer2);
+ nextIFDOffset[0] = toInt(buffer2, 0, TYPE_LONG);
parseEntries(buffer);
PaletteData palette = null;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFFileFormat.java
index b419a57106..f1db3e8894 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFFileFormat.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFFileFormat.java
@@ -53,11 +53,17 @@ ImageData[] loadFromByteStream() {
int offset = isLittleEndian ?
(header[4] & 0xFF) | ((header[5] & 0xFF) << 8) | ((header[6] & 0xFF) << 16) | ((header[7] & 0xFF) << 24) :
(header[7] & 0xFF) | ((header[6] & 0xFF) << 8) | ((header[5] & 0xFF) << 16) | ((header[4] & 0xFF) << 24);
- file.seek(offset);
- TIFFDirectory directory = new TIFFDirectory(file, isLittleEndian, loader);
- ImageData image = directory.read();
- /* A baseline reader is only expected to read the first directory */
- images = new ImageData[] {image};
+ while (offset != 0) {
+ file.seek(offset);
+ TIFFDirectory directory = new TIFFDirectory(file, isLittleEndian, loader);
+ int [] nextIFDOffset = new int[1];
+ ImageData image = directory.read(nextIFDOffset);
+ offset = nextIFDOffset[0];
+ ImageData[] oldImages = images;
+ images = new ImageData[oldImages.length + 1];
+ System.arraycopy(oldImages, 0, images, 0, oldImages.length);
+ images[images.length - 1] = image;
+ }
} catch (IOException e) {
SWT.error(SWT.ERROR_IO, e);
}