Mercurial > projects > dwt-linux
diff 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 |
line wrap: on
line diff
--- a/dwt/internal/image/GIFFileFormat.d Mon May 12 15:36:37 2008 +0200 +++ b/dwt/internal/image/GIFFileFormat.d Mon May 12 19:13:01 2008 +0200 @@ -24,8 +24,6 @@ import tango.core.Exception; import dwt.dwthelper.utils; -///FORTING_TYPE -class Image{} final class GIFFileFormat : FileFormat { String signature; @@ -64,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; } @@ -75,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); @@ -315,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]; @@ -335,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; }