Mercurial > projects > dwt2
comparison org.eclipse.swt.gtk.linux.x86/src/org/eclipse/swt/internal/image/PngDeflater.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 | c01d033c633a |
children |
comparison
equal
deleted
inserted
replaced
119:d00e8db0a568 | 120:536e43f63c81 |
---|---|
10 * Port to the D programming language: | 10 * Port to the D programming language: |
11 * Frank Benoit <benoit@tionex.de> | 11 * Frank Benoit <benoit@tionex.de> |
12 *******************************************************************************/ | 12 *******************************************************************************/ |
13 module org.eclipse.swt.internal.image.PngDeflater; | 13 module org.eclipse.swt.internal.image.PngDeflater; |
14 | 14 |
15 import java.io.ByteArrayOutputStream; | |
15 import java.lang.all; | 16 import java.lang.all; |
16 | |
17 import java.io.ByteArrayOutputStream; | |
18 | 17 |
19 public class PngDeflater { | 18 public class PngDeflater { |
20 | 19 |
21 static const int BASE = 65521; | 20 static const int BASE = 65521; |
22 static const int WINDOW = 32768; | 21 static const int WINDOW = 32768; |
23 static const int MIN_LENGTH = 3; | 22 static const int MIN_LENGTH = 3; |
24 static const int MAX_MATCHES = 32; | 23 static const int MAX_MATCHES = 32; |
25 static const int HASH = 8209; | 24 static const int HASH = 8209; |
26 | 25 |
27 byte[] istr; | 26 TryConst!(byte)[] istr; |
28 int inLength; | 27 int inLength; |
29 | 28 |
30 ByteArrayOutputStream bytes; | 29 ByteArrayOutputStream bytes; |
31 | 30 |
32 int adler32 = 1; | 31 int adler32 = 1; |
120 | 119 |
121 } | 120 } |
122 | 121 |
123 } | 122 } |
124 | 123 |
125 static /+const+/ Code lengthCodes[]; | 124 static TryConst!(Code[]) lengthCodes; |
126 static /+const+/ Code distanceCodes[]; | 125 static TryConst!(Code[]) distanceCodes; |
127 | 126 |
128 static this() { | 127 static this() { |
129 lengthCodes = [ | 128 lengthCodes = [ |
130 new Code(257, 0, 3, 3), | 129 new Code(257, 0, 3, 3), |
131 new Code(258, 0, 4, 4), | 130 new Code(258, 0, 4, 4), |
219 high = (low + high) % BASE; | 218 high = (low + high) % BASE; |
220 adler32 = (high << 16) | low; | 219 adler32 = (high << 16) | low; |
221 | 220 |
222 } | 221 } |
223 | 222 |
224 int hash(byte[] bytes) { | 223 int hash(in byte[] bytes) { |
225 | 224 |
226 int hash = ((bytes[0] & 0xff) << 24 | (bytes[1] & 0xff) << 16 | (bytes[2] & 0xff) << 8) % HASH; | 225 int hash = ((bytes[0] & 0xff) << 24 | (bytes[1] & 0xff) << 16 | (bytes[2] & 0xff) << 8) % HASH; |
227 if (hash < 0) { | 226 if (hash < 0) { |
228 hash = hash + HASH; | 227 hash = hash + HASH; |
229 } | 228 } |
268 writeBits(1 + 2 * mirrorBytes[0x90 - 144 + i], 9); | 267 writeBits(1 + 2 * mirrorBytes[0x90 - 144 + i], 9); |
269 } | 268 } |
270 | 269 |
271 } | 270 } |
272 | 271 |
273 Code findCode(int value, Code[] codes) { | 272 TryConst!(Code) findCode(int value, in Code[] codes) { |
274 | 273 |
275 int i, j, k; | 274 int i, j, k; |
276 | 275 |
277 i = -1; | 276 i = -1; |
278 j = codes.length; | 277 j = codes.length; |
291 | 290 |
292 } | 291 } |
293 | 292 |
294 void outputMatch(int length, int distance) { | 293 void outputMatch(int length, int distance) { |
295 | 294 |
296 Code d, l; | |
297 int thisLength; | 295 int thisLength; |
298 | 296 |
299 while (length > 0) { | 297 while (length > 0) { |
300 | 298 |
301 // we can transmit matches of lengths 3 through 258 inclusive | 299 // we can transmit matches of lengths 3 through 258 inclusive |
313 } | 311 } |
314 | 312 |
315 length = length - thisLength; | 313 length = length - thisLength; |
316 | 314 |
317 // find length code | 315 // find length code |
318 l = findCode(thisLength, lengthCodes); | 316 auto l = findCode(thisLength, lengthCodes); |
319 | 317 |
320 // transmit the length code | 318 // transmit the length code |
321 // 256 through 279 are 7 bits long starting at 0000000 | 319 // 256 through 279 are 7 bits long starting at 0000000 |
322 // 280 through 287 are 8 bits long starting at 11000000 | 320 // 280 through 287 are 8 bits long starting at 11000000 |
323 if (l.code <= 279) { | 321 if (l.code <= 279) { |
331 if (l.extraBits !is 0) { | 329 if (l.extraBits !is 0) { |
332 writeBits(thisLength - l.min, l.extraBits); | 330 writeBits(thisLength - l.min, l.extraBits); |
333 } | 331 } |
334 | 332 |
335 // find distance code | 333 // find distance code |
336 d = findCode(distance, distanceCodes); | 334 auto d = findCode(distance, distanceCodes); |
337 | 335 |
338 // transmit the distance code | 336 // transmit the distance code |
339 // 5 bits long starting at 00000 | 337 // 5 bits long starting at 00000 |
340 writeBits(mirrorBytes[d.code * 8], 5); | 338 writeBits(mirrorBytes[d.code * 8], 5); |
341 | 339 |
593 | 591 |
594 } | 592 } |
595 | 593 |
596 } | 594 } |
597 | 595 |
598 public byte[] deflate(byte[] input) { | 596 public byte[] deflate(in byte[] input) { |
599 | 597 |
600 istr = input; | 598 istr = input; |
601 inLength = input.length; | 599 inLength = input.length; |
602 | 600 |
603 // write zlib header | 601 // write zlib header |