comparison dwt/internal/image/PngChunk.d @ 7:e831403a80a9

Add 'cast' to casts
author Frank Benoit <benoit@tionex.de>
date Wed, 27 Aug 2008 14:30:35 +0200
parents 1a8b3cb347e0
children 5123b17c98ef
comparison
equal deleted inserted replaced
6:b903c16b6f48 7:e831403a80a9
33 static final int CHUNK_IDAT = 2; 33 static final int CHUNK_IDAT = 2;
34 static final int CHUNK_IEND = 3; 34 static final int CHUNK_IEND = 3;
35 // Non-critical chunks. 35 // Non-critical chunks.
36 static final int CHUNK_tRNS = 5; 36 static final int CHUNK_tRNS = 5;
37 37
38 static final byte[] TYPE_IHDR = {(byte) 'I', (byte) 'H', (byte) 'D', (byte) 'R'}; 38 static final byte[] TYPE_IHDR = {cast(byte) 'I', cast(byte) 'H', cast(byte) 'D', cast(byte) 'R'};
39 static final byte[] TYPE_PLTE = {(byte) 'P', (byte) 'L', (byte) 'T', (byte) 'E'}; 39 static final byte[] TYPE_PLTE = {cast(byte) 'P', cast(byte) 'L', cast(byte) 'T', cast(byte) 'E'};
40 static final byte[] TYPE_IDAT = {(byte) 'I', (byte) 'D', (byte) 'A', (byte) 'T'}; 40 static final byte[] TYPE_IDAT = {cast(byte) 'I', cast(byte) 'D', cast(byte) 'A', cast(byte) 'T'};
41 static final byte[] TYPE_IEND = {(byte) 'I', (byte) 'E', (byte) 'N', (byte) 'D'}; 41 static final byte[] TYPE_IEND = {cast(byte) 'I', cast(byte) 'E', cast(byte) 'N', cast(byte) 'D'};
42 static final byte[] TYPE_tRNS = {(byte) 't', (byte) 'R', (byte) 'N', (byte) 'S'}; 42 static final byte[] TYPE_tRNS = {cast(byte) 't', cast(byte) 'R', cast(byte) 'N', cast(byte) 'S'};
43 43
44 static final int[] CRC_TABLE; 44 static final int[] CRC_TABLE;
45 static { 45 static {
46 CRC_TABLE = new int[256]; 46 CRC_TABLE = new int[256];
47 for (int i = 0; i < 256; i++) { 47 for (int i = 0; i < 256; i++) {
106 /** 106 /**
107 * Set the 16-bit integer in the reference byte 107 * Set the 16-bit integer in the reference byte
108 * array at the given offset. 108 * array at the given offset.
109 */ 109 */
110 void setInt16(int offset, int value) { 110 void setInt16(int offset, int value) {
111 reference[offset] = (byte) ((value >> 8) & 0xFF); 111 reference[offset] = cast(byte) ((value >> 8) & 0xFF);
112 reference[offset + 1] = (byte) (value & 0xFF); 112 reference[offset + 1] = cast(byte) (value & 0xFF);
113 } 113 }
114 114
115 /** 115 /**
116 * Get the 32-bit integer from the reference byte 116 * Get the 32-bit integer from the reference byte
117 * array at the given offset. 117 * array at the given offset.
128 /** 128 /**
129 * Set the 32-bit integer in the reference byte 129 * Set the 32-bit integer in the reference byte
130 * array at the given offset. 130 * array at the given offset.
131 */ 131 */
132 void setInt32(int offset, int value) { 132 void setInt32(int offset, int value) {
133 reference[offset] = (byte) ((value >> 24) & 0xFF); 133 reference[offset] = cast(byte) ((value >> 24) & 0xFF);
134 reference[offset + 1] = (byte) ((value >> 16) & 0xFF); 134 reference[offset + 1] = cast(byte) ((value >> 16) & 0xFF);
135 reference[offset + 2] = (byte) ((value >> 8) & 0xFF); 135 reference[offset + 2] = cast(byte) ((value >> 8) & 0xFF);
136 reference[offset + 3] = (byte) (value & 0xFF); 136 reference[offset + 3] = cast(byte) (value & 0xFF);
137 } 137 }
138 138
139 /** 139 /**
140 * Get the length of the data component of this chunk. 140 * Get the length of the data component of this chunk.
141 * This is not the length of the entire chunk. 141 * This is not the length of the entire chunk.
271 } 271 }
272 return true; 272 return true;
273 } 273 }
274 274
275 bool isCritical() { 275 bool isCritical() {
276 char c = (char) getTypeBytes()[0]; 276 char c = cast(wchar) getTypeBytes()[0];
277 return 'A' <= c && c <= 'Z'; 277 return 'A' <= c && c <= 'Z';
278 } 278 }
279 279
280 int getChunkType() { 280 int getChunkType() {
281 if (typeMatchesArray(TYPE_IHDR)) return CHUNK_IHDR; 281 if (typeMatchesArray(TYPE_IHDR)) return CHUNK_IHDR;
331 if (reference.length < MIN_LENGTH) DWT.error(DWT.ERROR_INVALID_IMAGE); 331 if (reference.length < MIN_LENGTH) DWT.error(DWT.ERROR_INVALID_IMAGE);
332 332
333 byte[] type = getTypeBytes(); 333 byte[] type = getTypeBytes();
334 334
335 // The third character MUST be upper case. 335 // The third character MUST be upper case.
336 char c = (char) type[2]; 336 char c = cast(wchar) type[2];
337 if (!('A' <= c && c <= 'Z')) DWT.error(DWT.ERROR_INVALID_IMAGE); 337 if (!('A' <= c && c <= 'Z')) DWT.error(DWT.ERROR_INVALID_IMAGE);
338 338
339 // All characters must be letters. 339 // All characters must be letters.
340 for (int i = 0; i < TYPE_FIELD_LENGTH; i++) { 340 for (int i = 0; i < TYPE_FIELD_LENGTH; i++) {
341 c = (char) type[i]; 341 c = cast(wchar) type[i];
342 if (!(('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'))) { 342 if (!(('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'))) {
343 DWT.error(DWT.ERROR_INVALID_IMAGE); 343 DWT.error(DWT.ERROR_INVALID_IMAGE);
344 } 344 }
345 } 345 }
346 346
366 buffer.append("\n\tLength: "); 366 buffer.append("\n\tLength: ");
367 buffer.append(getLength()); 367 buffer.append(getLength());
368 buffer.append("\n\tType: "); 368 buffer.append("\n\tType: ");
369 byte[] type = getTypeBytes(); 369 byte[] type = getTypeBytes();
370 for(int i = 0; i < type.length; i++) { 370 for(int i = 0; i < type.length; i++) {
371 buffer.append((char) type[i]); 371 buffer.append(cast(wchar) type[i]);
372 } 372 }
373 373
374 contributeToString(buffer); 374 contributeToString(buffer);
375 375
376 buffer.append("\n\tCRC: "); 376 buffer.append("\n\tCRC: ");