summaryrefslogtreecommitdiffstats
path: root/bundles
diff options
context:
space:
mode:
authorBogdan Gheorghe <gheorghe@ca.ibm.com>2012-05-10 12:42:20 -0400
committerBogdan Gheorghe <gheorghe@ca.ibm.com>2012-05-10 12:42:20 -0400
commit68e03471d13fd16f26e5d37890119f05f1c0b292 (patch)
treec48627800742c6b1f7385cdab87e69831a7c2d4f /bundles
parentafaa39bdb2aab9490e8e3fdeb1deb754caa3e91b (diff)
downloadeclipse.platform.swt-68e03471d13fd16f26e5d37890119f05f1c0b292.tar.gz
eclipse.platform.swt-68e03471d13fd16f26e5d37890119f05f1c0b292.tar.xz
eclipse.platform.swt-68e03471d13fd16f26e5d37890119f05f1c0b292.zip
Bug 372790 - WinICOFileFormat cannot handle 256x256 icons
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/FileFormat.java18
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinICOFileFormat.java15
2 files changed, 25 insertions, 8 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/FileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/FileFormat.java
index 074b038bb5..1d33019b79 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/FileFormat.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/FileFormat.java
@@ -30,6 +30,13 @@ public abstract class FileFormat {
ImageLoader loader;
int compression;
+static FileFormat getFileFormat (LEDataInputStream stream, String format) throws Exception {
+ Class clazz = Class.forName(FORMAT_PACKAGE + '.' + format + FORMAT_SUFFIX);
+ FileFormat fileFormat = (FileFormat) clazz.newInstance();
+ if (fileFormat.isFileFormat(stream)) return fileFormat;
+ return null;
+}
+
/**
* Return whether or not the specified input stream
* represents a supported file format.
@@ -63,23 +70,18 @@ public ImageData[] loadFromStream(LEDataInputStream stream) {
public static ImageData[] load(InputStream is, ImageLoader loader) {
FileFormat fileFormat = null;
LEDataInputStream stream = new LEDataInputStream(is);
- boolean isSupported = false;
for (int i = 1; i < FORMATS.length; i++) {
if (FORMATS[i] != null) {
try {
- Class clazz = Class.forName(FORMAT_PACKAGE + '.' + FORMATS[i] + FORMAT_SUFFIX);
- fileFormat = (FileFormat) clazz.newInstance();
- if (fileFormat.isFileFormat(stream)) {
- isSupported = true;
- break;
- }
+ fileFormat = getFileFormat (stream, FORMATS[i]);
+ if (fileFormat != null) break;
} catch (ClassNotFoundException e) {
FORMATS[i] = null;
} catch (Exception e) {
}
}
}
- if (!isSupported) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
+ if (fileFormat == null) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
fileFormat.loader = loader;
return fileFormat.loadFromStream(stream);
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinICOFileFormat.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinICOFileFormat.java
index 3dbc5f51b3..ad5f0cd382 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinICOFileFormat.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/WinICOFileFormat.java
@@ -124,6 +124,14 @@ ImageData[] loadFromByteStream() {
* Load one icon from the byte stream.
*/
ImageData loadIcon(int[] iconHeader) {
+ try {
+ FileFormat png = getFileFormat(inputStream, "PNG");
+ if (png != null) {
+ png.loader = this.loader;
+ return png.loadFromStream(inputStream)[0];
+ }
+ } catch (Exception e) {
+ }
byte[] infoHeader = loadInfoHeader(iconHeader);
WinBMPFileFormat bmpFormat = new WinBMPFileFormat();
bmpFormat.inputStream = inputStream;
@@ -201,6 +209,13 @@ byte[] loadInfoHeader(int[] iconHeader) {
int infoWidth = (infoHeader[4] & 0xFF) | ((infoHeader[5] & 0xFF) << 8) | ((infoHeader[6] & 0xFF) << 16) | ((infoHeader[7] & 0xFF) << 24);
int infoHeight = (infoHeader[8] & 0xFF) | ((infoHeader[9] & 0xFF) << 8) | ((infoHeader[10] & 0xFF) << 16) | ((infoHeader[11] & 0xFF) << 24);
int bitCount = (infoHeader[14] & 0xFF) | ((infoHeader[15] & 0xFF) << 8);
+ /*
+ * Feature in the ico spec. The spec says that a width/height of 0 represents 256, however, newer images can be created with even larger sizes.
+ * Images with a width/height >= 256 will have their width/height set to 0 in the icon header; the fix for this case is to read the width/height
+ * directly from the image header.
+ */
+ if (width == 0) width = infoWidth;
+ if (height == 0) height = infoHeight / 2;
if (height == infoHeight && bitCount == 1) height /= 2;
if (!((width == infoWidth) && (height * 2 == infoHeight) &&
(bitCount == 1 || bitCount == 4 || bitCount == 8 || bitCount == 24 || bitCount == 32)))