Mercurial > projects > dwt2
annotate org.eclipse.swt.gtk.linux.x86/src/org/eclipse/swt/internal/image/PngHuffmanTables.d @ 120:536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
===D2===
* added [Try]Immutable/Const/Shared templates to work with differenses in D1/D2 instead of version statements
used these templates to work with strict type storage rules of dmd-2.053
* com.ibm.icu now also compilable with D2, but not tested yet
* small fixes
Snippet288 - shared data is in TLS
===Phobos===
* fixed critical bugs in Phobos implemention
completely incorrect segfault prone fromStringz (Linux's port ruthless killer)
terrible, incorrect StringBuffer realization (StyledText killer)
* fixed small bugs as well
Snippet72 - misprint in the snippet
* implemented missed functionality for Phobos
ByteArrayOutputStream implemented (image loading available)
formatting correctly works for all DWT's cases
As a result, folowing snippets now works with Phobos (Snippet### - what is fixed):
Snippet24, 42, 111, 115, 130, 235, 276 - bad string formatting
Snippet48, 282 - crash on image loading
Snippet163, 189, 211, 213, 217, 218, 222 - crash on copy/cut in StyledText
Snippet244 - hang-up
===Tango===
* few changes for the latest Tango trunc-r5661
* few small performance improvments
===General===
* implMissing-s for only one version changed to implMissingInTango/InPhobos
* incorrect calls to Format in toString-s fixed
* fixed loading \uXXXX characters in ResourceBundle
* added good UTF-8 support for StyledText, TextLayout (Win32) and friends
UTF functions revised and tested. It is now in java.nonstandard.*Utf modules
StyledText and TextLayout (Win32) modules revised for UTF-8 support
* removed small diferences in most identical files in *.swt.* folders
*.swt.internal.image, *.swt.events and *.swt.custom are identical in Win32/Linux32
now 179 of 576 (~31%) files in *.swt.* folders are fully identical
* Win32: snippets now have right subsystem, pretty icons and native system style controls
* small fixes in snippets
Snippet44 - it's not Snippet44
Snippet212 - functions work with different images and offsets arrays
Win32: Snippet282 - crash on close if the button has an image
Snippet293 - setGrayed is commented
and others
Win32: As a result, folowing snippets now works
Snippet68 - color doesn't change
Snippet163, 189, 211, 213, 217, 218, 222 - UTF-8 issues (see above)
Snippet193 - no tabel headers
author | Denis Shelomovskij <verylonglogin.reg@gmail.com> |
---|---|
date | Sat, 09 Jul 2011 15:50:20 +0300 |
parents | 7a2dd761a8b2 |
children |
rev | line source |
---|---|
25 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2006 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module org.eclipse.swt.internal.image.PngHuffmanTables; | |
14 | |
15 import org.eclipse.swt.internal.image.PngHuffmanTable; | |
16 import org.eclipse.swt.internal.image.PngDecodingDataStream; | |
17 import org.eclipse.swt.internal.image.PngLzBlockReader; | |
18 | |
19 public class PngHuffmanTables { | |
20 PngHuffmanTable literalTable; | |
21 PngHuffmanTable distanceTable; | |
22 | |
23 static PngHuffmanTable FixedLiteralTable; | |
24 static PngHuffmanTable FixedDistanceTable; | |
25 | |
49
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
25
diff
changeset
|
26 static const int LiteralTableSize = 288; |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
49
diff
changeset
|
27 static int[] FixedLiteralLengths = [ |
25 | 28 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, |
29 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, | |
30 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, | |
31 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, | |
32 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, | |
33 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, | |
34 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, | |
35 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, | |
36 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, | |
37 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, | |
38 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7, 7, 7, 7, 7, 7, 7, 7, | |
39 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, | |
40 ]; | |
41 | |
49
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
25
diff
changeset
|
42 static const int DistanceTableSize = 32; |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
49
diff
changeset
|
43 static int[] FixedDistanceLengths = [ |
25 | 44 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
45 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, | |
46 ]; | |
47 | |
49
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
25
diff
changeset
|
48 static const int LengthCodeTableSize = 19; |
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
25
diff
changeset
|
49 static const int[] LengthCodeOrder = [ |
25 | 50 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, |
51 11, 4, 12, 3, 13, 2, 14, 1, 15 | |
52 ]; | |
53 | |
54 static PngHuffmanTables getDynamicTables(PngDecodingDataStream stream) { | |
55 return new PngHuffmanTables(stream); | |
56 } | |
57 static PngHuffmanTables getFixedTables() { | |
58 return new PngHuffmanTables(); | |
59 } | |
60 | |
61 private PngHuffmanTable getFixedLiteralTable() { | |
62 if (FixedLiteralTable is null) { | |
63 FixedLiteralTable = new PngHuffmanTable(FixedLiteralLengths); | |
64 } | |
65 return FixedLiteralTable; | |
66 } | |
67 | |
68 private PngHuffmanTable getFixedDistanceTable() { | |
69 if (FixedDistanceTable is null) { | |
70 FixedDistanceTable = new PngHuffmanTable(FixedDistanceLengths); | |
71 } | |
72 return FixedDistanceTable; | |
73 } | |
74 | |
75 private this () { | |
76 literalTable = getFixedLiteralTable(); | |
77 distanceTable = getFixedDistanceTable(); | |
78 } | |
79 | |
80 private this (PngDecodingDataStream stream) { | |
81 int literals = PngLzBlockReader.FIRST_LENGTH_CODE | |
82 + stream.getNextIdatBits(5); | |
83 int distances = PngLzBlockReader.FIRST_DISTANCE_CODE | |
84 + stream.getNextIdatBits(5); | |
85 int codeLengthCodes = PngLzBlockReader.FIRST_CODE_LENGTH_CODE | |
86 + stream.getNextIdatBits(4); | |
87 | |
88 if (codeLengthCodes > PngLzBlockReader.LAST_CODE_LENGTH_CODE) { | |
89 stream.error(); | |
90 } | |
91 | |
92 /* Tricky, tricky, tricky. The length codes are stored in | |
93 * a very odd order. (For the order, see the definition of | |
94 * the static field lengthCodeOrder.) Also, the data may | |
95 * not contain values for all the codes. It may just contain | |
96 * values for the first X number of codes. The table should | |
97 * be of size <LengthCodeTableSize> regardless of the number | |
98 * of values actually given in the table. | |
99 */ | |
100 int[] lengthCodes = new int[LengthCodeTableSize]; | |
101 for (int i = 0; i < codeLengthCodes; i++) { | |
102 lengthCodes[LengthCodeOrder[i]] = stream.getNextIdatBits(3); | |
103 } | |
104 PngHuffmanTable codeLengthsTable = new PngHuffmanTable(lengthCodes); | |
105 | |
106 int[] literalLengths = readLengths( | |
107 stream, literals, codeLengthsTable, LiteralTableSize); | |
108 int[] distanceLengths = readLengths( | |
109 stream, distances, codeLengthsTable, DistanceTableSize); | |
110 | |
111 literalTable = new PngHuffmanTable(literalLengths); | |
112 distanceTable = new PngHuffmanTable(distanceLengths); | |
113 } | |
114 | |
115 private int [] readLengths (PngDecodingDataStream stream, | |
116 int numLengths, | |
117 PngHuffmanTable lengthsTable, | |
118 int tableSize) | |
119 { | |
120 int[] lengths = new int[tableSize]; | |
121 | |
122 for (int index = 0; index < numLengths;) { | |
123 int value = lengthsTable.getNextValue(stream); | |
124 if (value < 16) { | |
125 // Literal value | |
126 lengths[index] = value; | |
127 index++; | |
128 } else if (value is 16) { | |
129 // Repeat the previous code 3-6 times. | |
130 int count = stream.getNextIdatBits(2) + 3; | |
131 for (int i = 0; i < count; i++) { | |
132 lengths[index] = lengths [index - 1]; | |
133 index++; | |
134 } | |
135 } else if (value is 17) { | |
136 // Repeat 0 3-10 times. | |
137 int count = stream.getNextIdatBits(3) + 3; | |
138 for (int i = 0; i < count; i++) { | |
139 lengths[index] = 0; | |
140 index++; | |
141 } | |
142 } else if (value is 18) { | |
143 // Repeat 0 11-138 times. | |
144 int count = stream.getNextIdatBits(7) + 11; | |
145 for (int i = 0; i < count; i++) { | |
146 lengths[index] = 0; | |
147 index++; | |
148 } | |
149 } else { | |
150 stream.error(); | |
151 } | |
152 } | |
153 return lengths; | |
154 } | |
155 | |
156 int getNextLiteralValue(PngDecodingDataStream stream) { | |
157 return literalTable.getNextValue(stream); | |
158 } | |
159 | |
160 int getNextDistanceValue(PngDecodingDataStream stream) { | |
161 return distanceTable.getNextValue(stream); | |
162 } | |
163 | |
164 } |