Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 93710 Details for
Bug 57382
group 4 tiff image shows blank
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch for tif lzw decompression
patch-lzw.txt (text/plain), 10.86 KB, created by
Michael Baumgärtner
on 2008-03-26 18:15:10 EDT
(
hide
)
Description:
Patch for tif lzw decompression
Filename:
MIME Type:
Creator:
Michael Baumgärtner
Created:
2008-03-26 18:15:10 EDT
Size:
10.86 KB
patch
obsolete
>Index: Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFDirectory.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFDirectory.java,v >retrieving revision 1.5 >diff -u -r1.5 TIFFDirectory.java >--- Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFDirectory.java 9 May 2006 19:47:06 -0000 1.5 >+++ Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFDirectory.java 26 Mar 2008 22:09:03 -0000 >@@ -34,6 +34,10 @@ > int[] stripByteCounts; > int t4Options; > int colorMapOffset; >+ int predictor = 1; >+ >+ /* LZW fields */ >+ TIFFLZWDecoder lzwdecoder; > > /* Encoder fields */ > ImageData image; >@@ -55,7 +59,8 @@ > static final short TAG_T4Options = 292; > static final short TAG_ResolutionUnit = 296; > static final short TAG_ColorMap = 320; >- >+ static final short TAG_Predictor = 317; >+ > static final int TYPE_BYTE = 1; > static final int TYPE_ASCII = 2; > static final int TYPE_SHORT = 3; >@@ -63,9 +68,15 @@ > static final int TYPE_RATIONAL = 5; > > /* Different compression schemes */ >- static final int COMPRESSION_NONE = 1; >- static final int COMPRESSION_CCITT_3_1 = 2; >- static final int COMPRESSION_PACKBITS = 32773; >+ static final int COMPRESSION_NONE = 1; >+ static final int COMPRESSION_CCITT_3_1 = 2; >+ static final int COMPRESSION_CCITT_3_2 = 3; >+ static final int COMPRESSION_CCITT_4_2 = 4; >+ static final int COMPRESSION_LZW = 5; >+ static final int COMPRESSION_JPEG_OLD = 6; >+ static final int COMPRESSION_JPEG_TTN2 = 7; >+ static final int COMPRESSION_PACKBITS = 32773; >+ static final int COMPRESSION_DEFLATE = 32946; > > static final int IFD_ENTRY_SIZE = 12; > >@@ -149,7 +160,7 @@ > destIndex += data.length; > } else if (compression == COMPRESSION_PACKBITS) { > destIndex += decodePackBits(data, imageData, destIndex); >- } else if (compression == COMPRESSION_CCITT_3_1 || compression == 3) { >+ } else if (compression == COMPRESSION_CCITT_3_1 || compression == COMPRESSION_CCITT_3_2) { > TIFFModifiedHuffmanCodec codec = new TIFFModifiedHuffmanCodec(); > int nRows = rowsPerStrip; > if (i == length -1) { >@@ -158,6 +169,9 @@ > } > destIndex += codec.decode(data, imageData, destIndex, imageWidth, nRows); > } >+ else if(compression == COMPRESSION_LZW){ >+ destIndex = lzwdecoder.decode(data, imageData, destIndex, rowsPerStrip); >+ } > if (loader.hasListeners()) { > loader.notifyListeners(new ImageLoaderEvent(loader, image, i, i == length - 1)); > } >@@ -370,8 +384,25 @@ > colorMapOffset = getEntryValue(TYPE_LONG, buffer, offset); > break; > } >- } >- } >+ case TAG_Predictor:{ >+ // Option for lzw compression >+ predictor = getEntryValue(type, buffer, offset); >+ if (predictor != 1 && predictor != 2) { >+ SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); >+ //throw new RuntimeException("TIFFImage8"); >+ } >+ >+ if (predictor == 2 && bitsPerSample[0] != 8) { >+ SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); >+ //throw new RuntimeException(sampleSize + "TIFFImage9"); >+ } >+ break; >+ } >+ } >+ } >+ if(compression == COMPRESSION_LZW){ >+ lzwdecoder = new TIFFLZWDecoder(imageWidth, predictor, samplesPerPixel); >+ } > } > > public ImageData read() throws IOException { >Index: Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFLZWDecoder.java >=================================================================== >RCS file: Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFLZWDecoder.java >diff -N Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFLZWDecoder.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse SWT/common/org/eclipse/swt/internal/image/TIFFLZWDecoder.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,243 @@ >+package org.eclipse.swt.internal.image; >+ >+/* >+ >+ Licensed to the Apache Software Foundation (ASF) under one or more >+ contributor license agreements. See the NOTICE file distributed with >+ this work for additional information regarding copyright ownership. >+ The ASF licenses this file to You under the Apache License, Version 2.0 >+ (the "License"); you may not use this file except in compliance with >+ the License. You may obtain a copy of the License at >+ >+ http://www.apache.org/licenses/LICENSE-2.0 >+ >+ Unless required by applicable law or agreed to in writing, software >+ distributed under the License is distributed on an "AS IS" BASIS, >+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >+ See the License for the specific language governing permissions and >+ limitations under the License. >+ >+*/ >+ >+/** >+ * A class for performing LZW decoding. >+ * >+ * @version $Id$ >+ */ >+public class TIFFLZWDecoder { >+ >+ byte[][] stringTable; >+ byte[] data = null; >+ byte[] uncompData; >+ int tableIndex, bitsToGet = 9; >+ int bytePointer, bitPointer; >+ int dstIndex; >+ int w, h; >+ int predictor, samplesPerPixel; >+ int nextData = 0; >+ int nextBits = 0; >+ >+ int[] andTable = { >+ 511, >+ 1023, >+ 2047, >+ 4095 >+ }; >+ >+ public TIFFLZWDecoder(int w, int predictor, int samplesPerPixel) { >+ this.w = w; >+ this.predictor = predictor; >+ this.samplesPerPixel = samplesPerPixel; >+ } >+ >+ /** >+ * Method to decode LZW compressed data. >+ * >+ * @param data The compressed data. >+ * @param uncompData Array to return the uncompressed data in. >+ * @param h The number of rows the compressed data contains. >+ */ >+ public int decode(byte[] data, byte[] uncompData, int destIndex, int h) { >+ >+ if(data[0] == (byte)0x00 && data[1] == (byte)0x01) { >+ throw new UnsupportedOperationException("TIFFLZWDecoder0"); >+ } >+ >+ initializeStringTable(); >+ >+ this.data = data; >+ this.h = h; >+ this.uncompData = uncompData; >+ >+ // Initialize pointers >+ bytePointer = 0; >+ bitPointer = 0; >+ dstIndex = destIndex; >+ >+ >+ nextData = 0; >+ nextBits = 0; >+ >+ int code, oldCode = 0; >+ byte[] string; >+ >+ while ( ((code = getNextCode()) != 257) && >+ dstIndex != uncompData.length) { >+ >+ if (code == 256) { >+ >+ initializeStringTable(); >+ code = getNextCode(); >+ >+ if (code == 257) { >+ break; >+ } >+ >+ writeString(stringTable[code]); >+ oldCode = code; >+ >+ } else { >+ >+ if (code < tableIndex) { >+ >+ string = stringTable[code]; >+ >+ writeString(string); >+ addStringToTable(stringTable[oldCode], string[0]); >+ oldCode = code; >+ >+ } else { >+ >+ string = stringTable[oldCode]; >+ string = composeString(string, string[0]); >+ writeString(string); >+ addStringToTable(string); >+ oldCode = code; >+ } >+ >+ } >+ >+ } >+ >+ // Horizontal Differencing Predictor >+ if (predictor == 2) { >+ >+ int count; >+ for (int j = 0; j < h; j++) { >+ >+ count = samplesPerPixel * (j * w + 1)+ destIndex; >+ >+ for (int i = samplesPerPixel; i < w * samplesPerPixel; i++) { >+ >+ uncompData[count] += uncompData[count - samplesPerPixel]; >+ count++; >+ } >+ } >+ } >+ >+ return dstIndex; >+ } >+ >+ >+ /** >+ * Initialize the string table. >+ */ >+ public void initializeStringTable() { >+ >+ stringTable = new byte[4096][]; >+ >+ for (int i=0; i<256; i++) { >+ stringTable[i] = new byte[1]; >+ stringTable[i][0] = (byte)i; >+ } >+ >+ tableIndex = 258; >+ bitsToGet = 9; >+ } >+ >+ /** >+ * Write out the string just uncompressed. >+ */ >+ public void writeString(byte[] string) { >+ >+ for (int i=0; i<string.length; i++) { >+ uncompData[dstIndex++] = string[i]; >+ } >+ } >+ >+ /** >+ * Add a new string to the string table. >+ */ >+ public void addStringToTable(byte[] oldString, byte newString) { >+ int length = oldString.length; >+ byte[] string = new byte[length + 1]; >+ System.arraycopy(oldString, 0, string, 0, length); >+ string[length] = newString; >+ >+ // Add this new String to the table >+ stringTable[tableIndex++] = string; >+ >+ if (tableIndex == 511) { >+ bitsToGet = 10; >+ } else if (tableIndex == 1023) { >+ bitsToGet = 11; >+ } else if (tableIndex == 2047) { >+ bitsToGet = 12; >+ } >+ } >+ >+ /** >+ * Add a new string to the string table. >+ */ >+ public void addStringToTable(byte[] string) { >+ >+ // Add this new String to the table >+ stringTable[tableIndex++] = string; >+ >+ if (tableIndex == 511) { >+ bitsToGet = 10; >+ } else if (tableIndex == 1023) { >+ bitsToGet = 11; >+ } else if (tableIndex == 2047) { >+ bitsToGet = 12; >+ } >+ } >+ >+ /** >+ * Append <code>newString</code> to the end of <code>oldString</code>. >+ */ >+ public byte[] composeString(byte[] oldString, byte newString) { >+ int length = oldString.length; >+ byte[] string = new byte[length + 1]; >+ System.arraycopy(oldString, 0, string, 0, length); >+ string[length] = newString; >+ >+ return string; >+ } >+ >+ // Returns the next 9, 10, 11 or 12 bits >+ public int getNextCode() { >+ // Attempt to get the next code. The exception is caught to make >+ // this robust to cases wherein the EndOfInformation code has been >+ // omitted from a strip. Examples of such cases have been observed >+ // in practice. >+ try { >+ nextData = (nextData << 8) | (data[bytePointer++] & 0xff); >+ nextBits += 8; >+ >+ if (nextBits < bitsToGet) { >+ nextData = (nextData << 8) | (data[bytePointer++] & 0xff); >+ nextBits += 8; >+ } >+ >+ int code = >+ (nextData >> (nextBits - bitsToGet)) & andTable[bitsToGet-9]; >+ nextBits -= bitsToGet; >+ >+ return code; >+ } catch(ArrayIndexOutOfBoundsException e) { >+ // Strip not terminated as expected: return EndOfInformation code. >+ return 257; >+ } >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 57382
:
9214
|
10355
|
30351
| 93710 |
164213