diff dwt/internal/image/GIFFileFormat.d @ 213:36f5cb12e1a2

Update to SWT 3.4M7
author Frank Benoit <benoit@tionex.de>
date Sat, 17 May 2008 17:34:28 +0200
parents ab60f3309436
children fd9c62a2998e
line wrap: on
line diff
--- a/dwt/internal/image/GIFFileFormat.d	Mon May 05 00:12:38 2008 +0200
+++ b/dwt/internal/image/GIFFileFormat.d	Sat May 17 17:34:28 2008 +0200
@@ -22,9 +22,9 @@
 import dwt.graphics.ImageLoaderEvent;
 import dwt.graphics.ImageLoader;
 import tango.core.Exception;
-import dwt.dwthelper.System;
 import dwt.dwthelper.utils;
 
+
 final class GIFFileFormat : FileFormat {
     String signature;
     int screenWidth, screenHeight, backgroundPixel, bitsPerPixel, defaultDepth;
@@ -62,7 +62,7 @@
             byte[3] signature;
             stream.read(signature);
             stream.unread(signature);
-            return cast(String)signature == "GIF"; //$NON-NLS-1$
+            return signature[0] is 'G' && signature[1] is 'I' && signature[2] is 'F';
         } catch (Exception e) {
             return false;
         }
@@ -73,13 +73,12 @@
      * Return an array of ImageData representing the image(s).
      */
     override ImageData[] loadFromByteStream() {
-        byte[3] signatureBytes;
+        byte[3] signature;
         byte[3] versionBytes;
         byte[7] block;
         try {
-            inputStream.read(signatureBytes);
-            signature = cast(String)signatureBytes.dup;
-            if (signature != "GIF") //$NON-NLS-1$
+            inputStream.read(signature);
+            if (!(signature[0] is 'G' && signature[1] is 'I' && signature[2] is 'F'))
                 DWT.error(DWT.ERROR_INVALID_IMAGE);
 
             inputStream.read(versionBytes);
@@ -313,13 +312,11 @@
             // Read size of block = 0x0B.
             inputStream.read();
             // Read application identifier.
-            byte[] applicationBytes = new byte[8];
-            inputStream.read(applicationBytes);
-            String application = cast(String)(applicationBytes.dup);
+            byte[] application = new byte[8];
+            inputStream.read(application);
             // Read authentication code.
-            byte[] authenticationBytes = new byte[3];
-            inputStream.read(authenticationBytes);
-            String authentication = cast(String)(authenticationBytes.dup);
+            byte[] authentication = new byte[3];
+            inputStream.read(authentication);
             // Read application data.
             byte[] data = new byte[0];
             byte[] block = new byte[255];
@@ -333,7 +330,20 @@
                 size = inputStream.read();
             }
             // Look for the NETSCAPE 'repeat count' field for an animated GIF.
-            if (application=="NETSCAPE" && authentication=="2.0" && data[0] is 01) { //$NON-NLS-1$ //$NON-NLS-2$
+            bool netscape =
+                application[0] is 'N' &&
+                application[1] is 'E' &&
+                application[2] is 'T' &&
+                application[3] is 'S' &&
+                application[4] is 'C' &&
+                application[5] is 'A' &&
+                application[6] is 'P' &&
+                application[7] is 'E';
+            bool authentic =
+                authentication[0] is '2' &&
+                authentication[1] is '.' &&
+                authentication[2] is '0';
+            if (netscape && authentic && data[0] is 01) { //$NON-NLS-1$ //$NON-NLS-2$
                 repeatCount = (data[1] & 0xFF) | ((data[2] & 0xFF) << 8);
                 loader.repeatCount = repeatCount;
             }