Mercurial > projects > dwt-mac
comparison dwt/internal/image/GIFFileFormat.d @ 7:e831403a80a9
Add 'cast' to casts
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 27 Aug 2008 14:30:35 +0200 |
parents | 380af2bdd8e5 |
children | 5123b17c98ef |
comparison
equal
deleted
inserted
replaced
6:b903c16b6f48 | 7:e831403a80a9 |
---|---|
33 static final int GIF_PLAIN_TEXT_BLOCK_ID = 0x01; | 33 static final int GIF_PLAIN_TEXT_BLOCK_ID = 0x01; |
34 static final int GIF_COMMENT_BLOCK_ID = 0xFE; | 34 static final int GIF_COMMENT_BLOCK_ID = 0xFE; |
35 static final int GIF_EXTENSION_BLOCK_ID = 0x21; | 35 static final int GIF_EXTENSION_BLOCK_ID = 0x21; |
36 static final int GIF_IMAGE_BLOCK_ID = 0x2C; | 36 static final int GIF_IMAGE_BLOCK_ID = 0x2C; |
37 static final int GIF_TRAILER_ID = 0x3B; | 37 static final int GIF_TRAILER_ID = 0x3B; |
38 static final byte [] GIF89a = new byte[] { (byte)'G', (byte)'I', (byte)'F', (byte)'8', (byte)'9', (byte)'a' }; | 38 static final byte [] GIF89a = new byte[] { cast(byte)'G', cast(byte)'I', cast(byte)'F', cast(byte)'8', cast(byte)'9', cast(byte)'a' }; |
39 static final byte [] NETSCAPE2_0 = new byte[] { (byte)'N', (byte)'E', (byte)'T', (byte)'S', (byte)'C', (byte)'A', (byte)'P', (byte)'E', (byte)'2', (byte)'.', (byte)'0' }; | 39 static final byte [] NETSCAPE2_0 = new byte[] { cast(byte)'N', cast(byte)'E', cast(byte)'T', cast(byte)'S', cast(byte)'C', cast(byte)'A', cast(byte)'P', cast(byte)'E', cast(byte)'2', cast(byte)'.', cast(byte)'0' }; |
40 | 40 |
41 /** | 41 /** |
42 * Answer a palette containing numGrays | 42 * Answer a palette containing numGrays |
43 * shades of gray, ranging from black to white. | 43 * shades of gray, ranging from black to white. |
44 */ | 44 */ |
45 static PaletteData grayRamp(int numGrays) { | 45 static PaletteData grayRamp(int numGrays) { |
46 int n = numGrays - 1; | 46 int n = numGrays - 1; |
47 RGB[] colors = new RGB[numGrays]; | 47 RGB[] colors = new RGB[numGrays]; |
48 for (int i = 0; i < numGrays; i++) { | 48 for (int i = 0; i < numGrays; i++) { |
49 int intensity = (byte)((i * 3) * 256 / n); | 49 int intensity = cast(byte)((i * 3) * 256 / n); |
50 colors[i] = new RGB(intensity, intensity, intensity); | 50 colors[i] = new RGB(intensity, intensity, intensity); |
51 } | 51 } |
52 return new PaletteData(colors); | 52 return new PaletteData(colors); |
53 } | 53 } |
54 | 54 |
119 try { | 119 try { |
120 /* Read the 0-byte terminator at the end of the image. */ | 120 /* Read the 0-byte terminator at the end of the image. */ |
121 id = inputStream.read(); | 121 id = inputStream.read(); |
122 if (id > 0) { | 122 if (id > 0) { |
123 /* We read the terminator earlier. */ | 123 /* We read the terminator earlier. */ |
124 inputStream.unread(new byte[] {(byte)id}); | 124 inputStream.unread(new byte[] {cast(byte)id}); |
125 } | 125 } |
126 } catch (IOException e) { | 126 } catch (IOException e) { |
127 DWT.error(DWT.ERROR_IO, e); | 127 DWT.error(DWT.ERROR_IO, e); |
128 } | 128 } |
129 getExtensions(); | 129 getExtensions(); |
162 } | 162 } |
163 id = readID(); | 163 id = readID(); |
164 } | 164 } |
165 if (id is GIF_IMAGE_BLOCK_ID || id is GIF_TRAILER_ID) { | 165 if (id is GIF_IMAGE_BLOCK_ID || id is GIF_TRAILER_ID) { |
166 try { | 166 try { |
167 inputStream.unread(new byte[] {(byte)id}); | 167 inputStream.unread(new byte[] {cast(byte)id}); |
168 } catch (IOException e) { | 168 } catch (IOException e) { |
169 DWT.error(DWT.ERROR_IO, e); | 169 DWT.error(DWT.ERROR_IO, e); |
170 } | 170 } |
171 } | 171 } |
172 } | 172 } |
481 | 481 |
482 try { | 482 try { |
483 /* Step 3: Write the GIF89a Header and Logical Screen Descriptor. */ | 483 /* Step 3: Write the GIF89a Header and Logical Screen Descriptor. */ |
484 outputStream.write(GIF89a); | 484 outputStream.write(GIF89a); |
485 int bitField = globalTable*128 + (depth-1)*16 + depth-1; | 485 int bitField = globalTable*128 + (depth-1)*16 + depth-1; |
486 outputStream.writeShort((short)logicalScreenWidth); | 486 outputStream.writeShort(cast(short)logicalScreenWidth); |
487 outputStream.writeShort((short)logicalScreenHeight); | 487 outputStream.writeShort(cast(short)logicalScreenHeight); |
488 outputStream.write(bitField); | 488 outputStream.write(bitField); |
489 outputStream.write(backgroundPixel); | 489 outputStream.write(backgroundPixel); |
490 outputStream.write(0); // Aspect ratio is 1:1 | 490 outputStream.write(0); // Aspect ratio is 1:1 |
491 } catch (IOException e) { | 491 } catch (IOException e) { |
492 DWT.error(DWT.ERROR_IO, e); | 492 DWT.error(DWT.ERROR_IO, e); |
505 outputStream.write(GIF_APPLICATION_EXTENSION_BLOCK_ID); | 505 outputStream.write(GIF_APPLICATION_EXTENSION_BLOCK_ID); |
506 outputStream.write(NETSCAPE2_0.length); | 506 outputStream.write(NETSCAPE2_0.length); |
507 outputStream.write(NETSCAPE2_0); | 507 outputStream.write(NETSCAPE2_0); |
508 outputStream.write(3); // Three bytes follow | 508 outputStream.write(3); // Three bytes follow |
509 outputStream.write(1); // Extension type | 509 outputStream.write(1); // Extension type |
510 outputStream.writeShort((short) repeatCount); | 510 outputStream.writeShort(cast(short) repeatCount); |
511 outputStream.write(0); // Block terminator | 511 outputStream.write(0); // Block terminator |
512 } catch (IOException e) { | 512 } catch (IOException e) { |
513 DWT.error(DWT.ERROR_IO, e); | 513 DWT.error(DWT.ERROR_IO, e); |
514 } | 514 } |
515 } | 515 } |
527 int width = data[frame].width; | 527 int width = data[frame].width; |
528 int height = data[frame].height; | 528 int height = data[frame].height; |
529 try { | 529 try { |
530 outputStream.write(GIF_IMAGE_BLOCK_ID); | 530 outputStream.write(GIF_IMAGE_BLOCK_ID); |
531 byte[] block = new byte[9]; | 531 byte[] block = new byte[9]; |
532 block[0] = (byte)(x & 0xFF); | 532 block[0] = cast(byte)(x & 0xFF); |
533 block[1] = (byte)((x >> 8) & 0xFF); | 533 block[1] = cast(byte)((x >> 8) & 0xFF); |
534 block[2] = (byte)(y & 0xFF); | 534 block[2] = cast(byte)(y & 0xFF); |
535 block[3] = (byte)((y >> 8) & 0xFF); | 535 block[3] = cast(byte)((y >> 8) & 0xFF); |
536 block[4] = (byte)(width & 0xFF); | 536 block[4] = cast(byte)(width & 0xFF); |
537 block[5] = (byte)((width >> 8) & 0xFF); | 537 block[5] = cast(byte)((width >> 8) & 0xFF); |
538 block[6] = (byte)(height & 0xFF); | 538 block[6] = cast(byte)(height & 0xFF); |
539 block[7] = (byte)((height >> 8) & 0xFF); | 539 block[7] = cast(byte)((height >> 8) & 0xFF); |
540 block[8] = (byte)(globalTable is 0 ? (depth-1) | 0x80 : 0x00); | 540 block[8] = cast(byte)(globalTable is 0 ? (depth-1) | 0x80 : 0x00); |
541 outputStream.write(block); | 541 outputStream.write(block); |
542 } catch (IOException e) { | 542 } catch (IOException e) { |
543 DWT.error(DWT.ERROR_IO, e); | 543 DWT.error(DWT.ERROR_IO, e); |
544 } | 544 } |
545 | 545 |
577 gcBlock[0] = 0; | 577 gcBlock[0] = 0; |
578 gcBlock[1] = 0; | 578 gcBlock[1] = 0; |
579 gcBlock[2] = 0; | 579 gcBlock[2] = 0; |
580 gcBlock[3] = 0; | 580 gcBlock[3] = 0; |
581 if (image.transparentPixel !is -1) { | 581 if (image.transparentPixel !is -1) { |
582 gcBlock[0] = (byte)0x01; | 582 gcBlock[0] = cast(byte)0x01; |
583 gcBlock[3] = (byte)image.transparentPixel; | 583 gcBlock[3] = cast(byte)image.transparentPixel; |
584 } | 584 } |
585 if (image.disposalMethod !is 0) { | 585 if (image.disposalMethod !is 0) { |
586 gcBlock[0] |= (byte)((image.disposalMethod & 0x07) << 2); | 586 gcBlock[0] |= cast(byte)((image.disposalMethod & 0x07) << 2); |
587 } | 587 } |
588 if (image.delayTime !is 0) { | 588 if (image.delayTime !is 0) { |
589 gcBlock[1] = (byte)(image.delayTime & 0xFF); | 589 gcBlock[1] = cast(byte)(image.delayTime & 0xFF); |
590 gcBlock[2] = (byte)((image.delayTime >> 8) & 0xFF); | 590 gcBlock[2] = cast(byte)((image.delayTime >> 8) & 0xFF); |
591 } | 591 } |
592 outputStream.write((byte)gcBlock.length); | 592 outputStream.write(cast(byte)gcBlock.length); |
593 outputStream.write(gcBlock); | 593 outputStream.write(gcBlock); |
594 outputStream.write(0); // Block terminator | 594 outputStream.write(0); // Block terminator |
595 } catch (IOException e) { | 595 } catch (IOException e) { |
596 DWT.error(DWT.ERROR_IO, e); | 596 DWT.error(DWT.ERROR_IO, e); |
597 } | 597 } |
603 void writePalette(PaletteData palette, int depth) { | 603 void writePalette(PaletteData palette, int depth) { |
604 byte[] bytes = new byte[(1 << depth) * 3]; | 604 byte[] bytes = new byte[(1 << depth) * 3]; |
605 int offset = 0; | 605 int offset = 0; |
606 for (int i = 0; i < palette.colors.length; i++) { | 606 for (int i = 0; i < palette.colors.length; i++) { |
607 RGB color = palette.colors[i]; | 607 RGB color = palette.colors[i]; |
608 bytes[offset] = (byte)color.red; | 608 bytes[offset] = cast(byte)color.red; |
609 bytes[offset + 1] = (byte)color.green; | 609 bytes[offset + 1] = cast(byte)color.green; |
610 bytes[offset + 2] = (byte)color.blue; | 610 bytes[offset + 2] = cast(byte)color.blue; |
611 offset += 3; | 611 offset += 3; |
612 } | 612 } |
613 try { | 613 try { |
614 outputStream.write(bytes); | 614 outputStream.write(bytes); |
615 } catch (IOException e) { | 615 } catch (IOException e) { |