Mercurial > projects > dwt-linux
comparison dwt/internal/image/GIFFileFormat.d @ 240:ce446666f5a2
Update to SWT 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 12 May 2008 19:13:01 +0200 |
parents | 380bad9f6852 |
children | c0d810de7093 |
comparison
equal
deleted
inserted
replaced
239:06a1f6829310 | 240:ce446666f5a2 |
---|---|
22 import dwt.graphics.ImageLoaderEvent; | 22 import dwt.graphics.ImageLoaderEvent; |
23 import dwt.graphics.ImageLoader; | 23 import dwt.graphics.ImageLoader; |
24 import tango.core.Exception; | 24 import tango.core.Exception; |
25 import dwt.dwthelper.utils; | 25 import dwt.dwthelper.utils; |
26 | 26 |
27 ///FORTING_TYPE | |
28 class Image{} | |
29 | 27 |
30 final class GIFFileFormat : FileFormat { | 28 final class GIFFileFormat : FileFormat { |
31 String signature; | 29 String signature; |
32 int screenWidth, screenHeight, backgroundPixel, bitsPerPixel, defaultDepth; | 30 int screenWidth, screenHeight, backgroundPixel, bitsPerPixel, defaultDepth; |
33 int disposalMethod = 0; | 31 int disposalMethod = 0; |
62 override bool isFileFormat(LEDataInputStream stream) { | 60 override bool isFileFormat(LEDataInputStream stream) { |
63 try { | 61 try { |
64 byte[3] signature; | 62 byte[3] signature; |
65 stream.read(signature); | 63 stream.read(signature); |
66 stream.unread(signature); | 64 stream.unread(signature); |
67 return cast(String)signature == "GIF"; //$NON-NLS-1$ | 65 return signature[0] is 'G' && signature[1] is 'I' && signature[2] is 'F'; |
68 } catch (Exception e) { | 66 } catch (Exception e) { |
69 return false; | 67 return false; |
70 } | 68 } |
71 } | 69 } |
72 | 70 |
73 /** | 71 /** |
74 * Load the GIF image(s) stored in the input stream. | 72 * Load the GIF image(s) stored in the input stream. |
75 * Return an array of ImageData representing the image(s). | 73 * Return an array of ImageData representing the image(s). |
76 */ | 74 */ |
77 override ImageData[] loadFromByteStream() { | 75 override ImageData[] loadFromByteStream() { |
78 byte[3] signatureBytes; | 76 byte[3] signature; |
79 byte[3] versionBytes; | 77 byte[3] versionBytes; |
80 byte[7] block; | 78 byte[7] block; |
81 try { | 79 try { |
82 inputStream.read(signatureBytes); | 80 inputStream.read(signature); |
83 signature = cast(String)signatureBytes.dup; | 81 if (!(signature[0] is 'G' && signature[1] is 'I' && signature[2] is 'F')) |
84 if (signature != "GIF") //$NON-NLS-1$ | |
85 DWT.error(DWT.ERROR_INVALID_IMAGE); | 82 DWT.error(DWT.ERROR_INVALID_IMAGE); |
86 | 83 |
87 inputStream.read(versionBytes); | 84 inputStream.read(versionBytes); |
88 | 85 |
89 inputStream.read(block); | 86 inputStream.read(block); |
313 byte[] readApplicationExtension() { | 310 byte[] readApplicationExtension() { |
314 try { | 311 try { |
315 // Read size of block = 0x0B. | 312 // Read size of block = 0x0B. |
316 inputStream.read(); | 313 inputStream.read(); |
317 // Read application identifier. | 314 // Read application identifier. |
318 byte[] applicationBytes = new byte[8]; | 315 byte[] application = new byte[8]; |
319 inputStream.read(applicationBytes); | 316 inputStream.read(application); |
320 String application = cast(String)(applicationBytes.dup); | |
321 // Read authentication code. | 317 // Read authentication code. |
322 byte[] authenticationBytes = new byte[3]; | 318 byte[] authentication = new byte[3]; |
323 inputStream.read(authenticationBytes); | 319 inputStream.read(authentication); |
324 String authentication = cast(String)(authenticationBytes.dup); | |
325 // Read application data. | 320 // Read application data. |
326 byte[] data = new byte[0]; | 321 byte[] data = new byte[0]; |
327 byte[] block = new byte[255]; | 322 byte[] block = new byte[255]; |
328 int size = inputStream.read(); | 323 int size = inputStream.read(); |
329 while ((size > 0) && (inputStream.read(block, 0, size) !is -1)) { | 324 while ((size > 0) && (inputStream.read(block, 0, size) !is -1)) { |
333 System.arraycopy(block, 0, data, oldData.length, size); | 328 System.arraycopy(block, 0, data, oldData.length, size); |
334 //data ~= block[ 0 .. size ]; | 329 //data ~= block[ 0 .. size ]; |
335 size = inputStream.read(); | 330 size = inputStream.read(); |
336 } | 331 } |
337 // Look for the NETSCAPE 'repeat count' field for an animated GIF. | 332 // Look for the NETSCAPE 'repeat count' field for an animated GIF. |
338 if (application=="NETSCAPE" && authentication=="2.0" && data[0] is 01) { //$NON-NLS-1$ //$NON-NLS-2$ | 333 bool netscape = |
334 application[0] is 'N' && | |
335 application[1] is 'E' && | |
336 application[2] is 'T' && | |
337 application[3] is 'S' && | |
338 application[4] is 'C' && | |
339 application[5] is 'A' && | |
340 application[6] is 'P' && | |
341 application[7] is 'E'; | |
342 bool authentic = | |
343 authentication[0] is '2' && | |
344 authentication[1] is '.' && | |
345 authentication[2] is '0'; | |
346 if (netscape && authentic && data[0] is 01) { //$NON-NLS-1$ //$NON-NLS-2$ | |
339 repeatCount = (data[1] & 0xFF) | ((data[2] & 0xFF) << 8); | 347 repeatCount = (data[1] & 0xFF) | ((data[2] & 0xFF) << 8); |
340 loader.repeatCount = repeatCount; | 348 loader.repeatCount = repeatCount; |
341 } | 349 } |
342 return data; | 350 return data; |
343 } catch (Exception e) { | 351 } catch (Exception e) { |