Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngHuffmanTable.java')
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngHuffmanTable.java45
1 files changed, 21 insertions, 24 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngHuffmanTable.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngHuffmanTable.java
index 5d06cf01ac..655c78541a 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngHuffmanTable.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngHuffmanTable.java
@@ -1,15 +1,16 @@
/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.internal.image;
+import java.io.*;
public class PngHuffmanTable {
CodeLengthInfo[] codeLengthInfo;
@@ -17,6 +18,7 @@ public class PngHuffmanTable {
static final int MAX_CODE_LENGTH = 15;
static final int BAD_CODE = 0xFFFFFFF;
+ static final int incs[] = {1391376, 463792, 198768, 86961, 33936, 13776, 4592, 1968, 861, 336, 112, 48, 21, 7, 3, 1};
PngHuffmanTable (int[] lengths) {
super();
@@ -44,21 +46,20 @@ private void initialize(int[] lengths) {
}
private void generateTable(int[] lengths) {
- // Sort the values. Primary key is code size. Secondary key is value.
- for (int i = 0; i < lengths.length - 1; i++) {
- for (int j = i + 1; j < lengths.length; j++) {
- if (lengths[j] < lengths[i]
- || (lengths[j] == lengths[i]
- && codeValues[j] < codeValues[i]))
- {
- int tmp;
- tmp = lengths[j];
- lengths[j] = lengths[i];
- lengths[i] = tmp;
- tmp = codeValues[j];
- codeValues[j] = codeValues[i];
- codeValues[i] = tmp;
+ // Sort the values using shellsort. Primary key is code size. Secondary key is value.
+ int codeValuesTemp;
+ for (int k = 0; k < 16; k++) {
+ for (int h = incs[k], i = h; i < lengths.length; i++) {
+ int v = lengths[i];
+ codeValuesTemp = codeValues[i];
+ int j = i;
+ while (j >= h && (lengths[j - h] > v || (lengths[j - h] == v && codeValues[j - h] > codeValuesTemp))) {
+ lengths[j] = lengths[j - h];
+ codeValues[j] = codeValues[j - h];
+ j -= h;
}
+ lengths[j] = v;
+ codeValues[j] = codeValuesTemp;
}
}
@@ -90,7 +91,7 @@ private void generateTable(int[] lengths) {
}
}
-int getNextValue(PngDecodingDataStream stream) {
+int getNextValue(PngDecodingDataStream stream) throws IOException {
int code = stream.getNextIdatBit();
int codelength = 0;
@@ -114,10 +115,6 @@ int getNextValue(PngDecodingDataStream stream) {
return codeValues[index];
}
-class CodeValuePair {
- int value;
- int code;
-}
class CodeLengthInfo {
int length;
int max;

Back to the top