comparison dwt/internal/image/PngChunk.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
comparison
equal deleted inserted replaced
212:ab60f3309436 213:36f5cb12e1a2
19 import dwt.internal.image.PngIhdrChunk; 19 import dwt.internal.image.PngIhdrChunk;
20 import dwt.internal.image.PngPlteChunk; 20 import dwt.internal.image.PngPlteChunk;
21 import dwt.internal.image.PngIdatChunk; 21 import dwt.internal.image.PngIdatChunk;
22 import dwt.internal.image.PngIendChunk; 22 import dwt.internal.image.PngIendChunk;
23 import dwt.internal.image.PngTrnsChunk; 23 import dwt.internal.image.PngTrnsChunk;
24 import dwt.dwthelper.utils;
24 25
25 import tango.core.Exception; 26 import tango.core.Exception;
26 import tango.text.convert.Format; 27 import tango.text.convert.Format;
27 import dwt.dwthelper.System;
28 import dwt.dwthelper.utils;
29 28
30 class PngChunk { 29 class PngChunk {
31 byte[] reference; 30 byte[] reference;
32 31
33 static const int LENGTH_OFFSET = 0; 32 static const int LENGTH_OFFSET = 0;
51 static const byte[] TYPE_PLTE = cast(byte[])"PLTE";//{(byte) 'P', (byte) 'L', (byte) 'T', (byte) 'E'}; 50 static const byte[] TYPE_PLTE = cast(byte[])"PLTE";//{(byte) 'P', (byte) 'L', (byte) 'T', (byte) 'E'};
52 static const byte[] TYPE_IDAT = cast(byte[])"IDAT";//{(byte) 'I', (byte) 'D', (byte) 'A', (byte) 'T'}; 51 static const byte[] TYPE_IDAT = cast(byte[])"IDAT";//{(byte) 'I', (byte) 'D', (byte) 'A', (byte) 'T'};
53 static const byte[] TYPE_IEND = cast(byte[])"IEND";//{(byte) 'I', (byte) 'E', (byte) 'N', (byte) 'D'}; 52 static const byte[] TYPE_IEND = cast(byte[])"IEND";//{(byte) 'I', (byte) 'E', (byte) 'N', (byte) 'D'};
54 static const byte[] TYPE_tRNS = cast(byte[])"tRNS";//{(byte) 't', (byte) 'R', (byte) 'N', (byte) 'S'}; 53 static const byte[] TYPE_tRNS = cast(byte[])"tRNS";//{(byte) 't', (byte) 'R', (byte) 'N', (byte) 'S'};
55 54
56 private static /+const+/ int[] CRC_TABLE; 55 static const int[] CRC_TABLE;
57 private static bool static_this_completed = false; 56 //public static void static_this() {
58 private static void static_this() { 57 static this() {
59 if( static_this_completed ){ 58 CRC_TABLE = new int[256];
60 return; 59 for (int i = 0; i < 256; i++) {
61 } 60 CRC_TABLE[i] = i;
62 synchronized { 61 for (int j = 0; j < 8; j++) {
63 if( static_this_completed ){ 62 if ((CRC_TABLE[i] & 0x1) is 0) {
64 return; 63 CRC_TABLE[i] = (CRC_TABLE[i] >> 1) & 0x7FFFFFFF;
65 } 64 } else {
66 CRC_TABLE = new int[256]; 65 CRC_TABLE[i] = 0xEDB88320 ^ ((CRC_TABLE[i] >> 1) & 0x7FFFFFFF);
67 for (int i = 0; i < 256; i++) {
68 CRC_TABLE[i] = i;
69 for (int j = 0; j < 8; j++) {
70 if ((CRC_TABLE[i] & 0x1) is 0) {
71 CRC_TABLE[i] = (CRC_TABLE[i] >> 1) & 0x7FFFFFFF;
72 } else {
73 CRC_TABLE[i] = 0xEDB88320 ^ ((CRC_TABLE[i] >> 1) & 0x7FFFFFFF);
74 }
75 } 66 }
76 } 67 }
77 static_this_completed = true;
78 } 68 }
79 } 69 }
80 70
81 int length; 71 int length;
82 72
83 /** 73 /**
84 * Construct a PngChunk using the reference bytes 74 * Construct a PngChunk using the reference bytes
85 * given. 75 * given.
86 */ 76 */
87 this(byte[] reference) { 77 this(byte[] reference) {
88 static_this();
89 setReference(reference); 78 setReference(reference);
90 if (reference.length < LENGTH_OFFSET + LENGTH_FIELD_LENGTH) DWT.error(DWT.ERROR_INVALID_IMAGE); 79 if (reference.length < LENGTH_OFFSET + LENGTH_FIELD_LENGTH) DWT.error(DWT.ERROR_INVALID_IMAGE);
91 length = getInt32(LENGTH_OFFSET); 80 length = getInt32(LENGTH_OFFSET);
92 } 81 }
93 82
383 * Returns a string containing a concise, human-readable 372 * Returns a string containing a concise, human-readable
384 * description of the receiver. 373 * description of the receiver.
385 * 374 *
386 * @return a string representation of the event 375 * @return a string representation of the event
387 */ 376 */
388 override public String toString() { 377 public override String toString() {
389 String buffer = Format( "{\n\tLength: {}\n\tType: {}{}\n\tCRC: {:X}\n}", 378 String buffer = Format( "{\n\tLength: {}\n\tType: {}{}\n\tCRC: {:X}\n}",
390 getLength(), 379 getLength(),
391 cast(String) getTypeBytes(), 380 cast(String) getTypeBytes(),
392 contributeToString(), 381 contributeToString(),
393 getCRC()); 382 getCRC());