Mercurial > projects > dwt-mac
comparison dwt/graphics/Image.d @ 32:b9226997409c
Ported dwt.graphics.Image*
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Fri, 12 Sep 2008 13:44:30 +0200 |
parents | a9ab4c738ed8 |
children | 7d135fe0caf2 |
comparison
equal
deleted
inserted
replaced
31:9a3047e87f1d | 32:b9226997409c |
---|---|
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * | |
11 * Port to the D programming language: | |
12 * Jacob Carlborg <jacob.carlborg@gmail.com> | |
10 *******************************************************************************/ | 13 *******************************************************************************/ |
11 module dwt.graphics.Image; | 14 module dwt.graphics.Image; |
12 | 15 |
13 import dwt.dwthelper.utils; | |
14 | |
15 | 16 |
16 import java.io.InputStream; | 17 import dwt.dwthelper.InputStream; |
17 | 18 |
18 import dwt.DWT; | 19 import dwt.DWT; |
19 import dwt.DWTError; | 20 import dwt.DWTError; |
20 import dwt.DWTException; | 21 import dwt.DWTException; |
21 import dwt.internal.cocoa.NSAffineTransform; | 22 import dwt.internal.cocoa.NSAffineTransform; |
24 import dwt.internal.cocoa.NSImage; | 25 import dwt.internal.cocoa.NSImage; |
25 import dwt.internal.cocoa.NSImageRep; | 26 import dwt.internal.cocoa.NSImageRep; |
26 import dwt.internal.cocoa.NSSize; | 27 import dwt.internal.cocoa.NSSize; |
27 import dwt.internal.cocoa.NSString; | 28 import dwt.internal.cocoa.NSString; |
28 import dwt.internal.cocoa.OS; | 29 import dwt.internal.cocoa.OS; |
30 | |
31 import tango.text.convert.Format; | |
32 | |
33 import dwt.dwthelper.utils; | |
34 import dwt.graphics.Color; | |
35 import dwt.graphics.Device; | |
36 import dwt.graphics.Drawable; | |
37 import dwt.graphics.GC; | |
38 import dwt.graphics.GCData; | |
39 import dwt.graphics.ImageData; | |
40 import dwt.graphics.PaletteData; | |
41 import dwt.graphics.RGB; | |
42 import dwt.graphics.Rectangle; | |
43 import dwt.graphics.Resource; | |
44 import dwt.internal.cocoa.NSInteger; | |
45 import objc = dwt.internal.objc.runtime; | |
29 | 46 |
30 /** | 47 /** |
31 * Instances of this class are graphics which have been prepared | 48 * Instances of this class are graphics which have been prepared |
32 * for display on a specific device. That is, they are ready | 49 * for display on a specific device. That is, they are ready |
33 * to paint using methods such as <code>GC.drawImage()</code> | 50 * to paint using methods such as <code>GC.drawImage()</code> |
72 * | 89 * |
73 * @see Color | 90 * @see Color |
74 * @see ImageData | 91 * @see ImageData |
75 * @see ImageLoader | 92 * @see ImageLoader |
76 */ | 93 */ |
77 public final class Image : Resource , Drawable { | 94 public final class Image : Resource, Drawable { |
78 | 95 |
79 /** | 96 /** |
80 * specifies whether the receiver is a bitmap or an icon | 97 * specifies whether the receiver is a bitmap or an icon |
81 * (one of <code>DWT.BITMAP</code>, <code>DWT.ICON</code>) | 98 * (one of <code>DWT.BITMAP</code>, <code>DWT.ICON</code>) |
82 * <p> | 99 * <p> |
225 /* Get source image size */ | 242 /* Get source image size */ |
226 NSSize size = srcImage.handle.size(); | 243 NSSize size = srcImage.handle.size(); |
227 int width = cast(int)size.width; | 244 int width = cast(int)size.width; |
228 int height = cast(int)size.height; | 245 int height = cast(int)size.height; |
229 NSBitmapImageRep srcRep = srcImage.imageRep; | 246 NSBitmapImageRep srcRep = srcImage.imageRep; |
230 int bpr = srcRep.bytesPerRow(); | 247 NSInteger bpr = srcRep.bytesPerRow(); |
231 | 248 |
232 /* Copy transparent pixel and alpha data when necessary */ | 249 /* Copy transparent pixel and alpha data when necessary */ |
233 transparentPixel = srcImage.transparentPixel; | 250 transparentPixel = srcImage.transparentPixel; |
234 alpha = srcImage.alpha; | 251 alpha = srcImage.alpha; |
235 if (srcImage.alphaData !is null) { | 252 if (srcImage.alphaData !is null) { |
236 alphaData = new byte[srcImage.alphaData.length]; | 253 alphaData = new byte[srcImage.alphaData.length]; |
237 System.arraycopy(srcImage.alphaData, 0, alphaData, 0, alphaData.length); | 254 System.arraycopy(srcImage.alphaData, 0, alphaData, 0, alphaData.length); |
238 } | 255 } |
239 | 256 |
240 /* Create the image */ | 257 /* Create the image */ |
241 handle = cast(NSImage)new NSImage().alloc(); | 258 handle = cast(NSImage)(new NSImage()).alloc(); |
242 handle = handle.initWithSize(size); | 259 handle = handle.initWithSize(size); |
243 NSBitmapImageRep rep = imageRep = cast(NSBitmapImageRep)new NSBitmapImageRep().alloc(); | 260 NSBitmapImageRep rep = imageRep = cast(NSBitmapImageRep)(new NSBitmapImageRep()).alloc(); |
244 rep = rep.initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bitmapFormat_bytesPerRow_bitsPerPixel_(0, width, height, srcRep.bitsPerSample(), srcRep.samplesPerPixel(), srcRep.samplesPerPixel() is 4, srcRep.isPlanar(), new NSString(OS.NSDeviceRGBColorSpace()), OS.NSAlphaFirstBitmapFormat | OS.NSAlphaNonpremultipliedBitmapFormat, srcRep.bytesPerRow(), srcRep.bitsPerPixel()); | 261 rep = rep.initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bitmapFormat_bytesPerRow_bitsPerPixel_(null, cast(NSInteger) width, cast(NSInteger) height, srcRep.bitsPerSample(), srcRep.samplesPerPixel(), srcRep.samplesPerPixel() is 4, srcRep.isPlanar(), new NSString(OS.NSDeviceRGBColorSpace()), OS.NSAlphaFirstBitmapFormat | OS.NSAlphaNonpremultipliedBitmapFormat, srcRep.bytesPerRow(), srcRep.bitsPerPixel()); |
245 handle.addRepresentation(rep); | 262 handle.addRepresentation(rep); |
246 | 263 |
247 int data = rep.bitmapData(); | 264 objc.id data = rep.bitmapData(); |
248 OS.memmove(data, srcImage.imageRep.bitmapData(), width * height * 4); | 265 OS.memmove(data, srcImage.imageRep.bitmapData(), cast(size_t) (width * height * 4)); |
249 if (flag !is DWT.IMAGE_COPY) { | 266 if (flag !is DWT.IMAGE_COPY) { |
250 | 267 |
251 /* Apply transformation */ | 268 /* Apply transformation */ |
252 switch (flag) { | 269 switch (flag) { |
253 case DWT.IMAGE_DISABLE: { | 270 case DWT.IMAGE_DISABLE: { |
261 byte oneRed = cast(byte)oneRGB.red; | 278 byte oneRed = cast(byte)oneRGB.red; |
262 byte oneGreen = cast(byte)oneRGB.green; | 279 byte oneGreen = cast(byte)oneRGB.green; |
263 byte oneBlue = cast(byte)oneRGB.blue; | 280 byte oneBlue = cast(byte)oneRGB.blue; |
264 byte[] line = new byte[bpr]; | 281 byte[] line = new byte[bpr]; |
265 for (int y=0; y<height; y++) { | 282 for (int y=0; y<height; y++) { |
266 OS.memmove(line, data + (y * bpr), bpr); | 283 OS.memmove(line.ptr, data + (y * bpr), bpr); |
267 int offset = 0; | 284 int offset = 0; |
268 for (int x=0; x<width; x++) { | 285 for (int x=0; x<width; x++) { |
269 int red = line[offset+1] & 0xFF; | 286 int red = line[offset+1] & 0xFF; |
270 int green = line[offset+2] & 0xFF; | 287 int green = line[offset+2] & 0xFF; |
271 int blue = line[offset+3] & 0xFF; | 288 int blue = line[offset+3] & 0xFF; |
279 line[offset+2] = oneGreen; | 296 line[offset+2] = oneGreen; |
280 line[offset+3] = oneBlue; | 297 line[offset+3] = oneBlue; |
281 } | 298 } |
282 offset += 4; | 299 offset += 4; |
283 } | 300 } |
284 OS.memmove(data + (y * bpr), line, bpr); | 301 OS.memmove(data + (y * bpr), line.ptr, bpr); |
285 } | 302 } |
286 break; | 303 break; |
287 } | 304 } |
288 case DWT.IMAGE_GRAY: { | 305 case DWT.IMAGE_GRAY: { |
289 byte[] line = new byte[bpr]; | 306 byte[] line = new byte[bpr]; |
290 for (int y=0; y<height; y++) { | 307 for (int y=0; y<height; y++) { |
291 OS.memmove(line, data + (y * bpr), bpr); | 308 OS.memmove(line.ptr, data + (y * bpr), bpr); |
292 int offset = 0; | 309 int offset = 0; |
293 for (int x=0; x<width; x++) { | 310 for (int x=0; x<width; x++) { |
294 int red = line[offset+1] & 0xFF; | 311 int red = line[offset+1] & 0xFF; |
295 int green = line[offset+2] & 0xFF; | 312 int green = line[offset+2] & 0xFF; |
296 int blue = line[offset+3] & 0xFF; | 313 int blue = line[offset+3] & 0xFF; |
297 byte intensity = cast(byte)((red+red+green+green+green+green+green+blue) >> 3); | 314 byte intensity = cast(byte)((red+red+green+green+green+green+green+blue) >> 3); |
298 line[offset+1] = line[offset+2] = line[offset+3] = intensity; | 315 line[offset+1] = line[offset+2] = line[offset+3] = intensity; |
299 offset += 4; | 316 offset += 4; |
300 } | 317 } |
301 OS.memmove(data + (y * bpr), line, bpr); | 318 OS.memmove(data + (y * bpr), line.ptr, bpr); |
302 } | 319 } |
303 break; | 320 break; |
304 } | 321 } |
305 } | 322 } |
306 } | 323 } |
496 | 513 |
497 void createAlpha () { | 514 void createAlpha () { |
498 if (transparentPixel is -1 && alpha is -1 && alphaData is null) return; | 515 if (transparentPixel is -1 && alpha is -1 && alphaData is null) return; |
499 NSSize size = handle.size(); | 516 NSSize size = handle.size(); |
500 int height = cast(int)size.height; | 517 int height = cast(int)size.height; |
501 int bpr = imageRep.bytesPerRow(); | 518 NSInteger bpr = imageRep.bytesPerRow(); |
502 int dataSize = height * bpr; | 519 size_t dataSize = height * bpr; |
503 byte[] srcData = new byte[dataSize]; | 520 byte[] srcData = new byte[dataSize]; |
504 OS.memmove(srcData, imageRep.bitmapData(), dataSize); | 521 OS.memmove(srcData.ptr, imageRep.bitmapData(), dataSize); |
505 if (transparentPixel !is -1) { | 522 if (transparentPixel !is -1) { |
506 for (int i=0; i<dataSize; i+=4) { | 523 for (int i=0; i<dataSize; i+=4) { |
507 int pixel = ((srcData[i+1] & 0xFF) << 16) | ((srcData[i+2] & 0xFF) << 8) | (srcData[i+3] & 0xFF); | 524 int pixel = ((srcData[i+1] & 0xFF) << 16) | ((srcData[i+2] & 0xFF) << 8) | (srcData[i+3] & 0xFF); |
508 srcData[i] = cast(byte)(pixel is transparentPixel ? 0 : 0xFF); | 525 srcData[i] = cast(byte)(pixel is transparentPixel ? 0 : 0xFF); |
509 } | 526 } |
521 offset += 4; | 538 offset += 4; |
522 alphaOffset += 1; | 539 alphaOffset += 1; |
523 } | 540 } |
524 } | 541 } |
525 } | 542 } |
526 OS.memmove(imageRep.bitmapData(), srcData, dataSize); | 543 OS.memmove(imageRep.bitmapData(), srcData.ptr, dataSize); |
527 } | 544 } |
528 | 545 |
529 void destroy() { | 546 void destroy() { |
530 if (memGC !is null) memGC.dispose(); | 547 if (memGC !is null) memGC.dispose(); |
531 if (imageRep !is null) imageRep.release(); | 548 if (imageRep !is null) imageRep.release(); |
543 * @param object the object to compare with this object | 560 * @param object the object to compare with this object |
544 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise | 561 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise |
545 * | 562 * |
546 * @see #hashCode | 563 * @see #hashCode |
547 */ | 564 */ |
548 public bool equals (Object object) { | 565 public bool opEquals (Object object) { |
549 if (object is this) return true; | 566 if (object is this) return true; |
550 if (!( null !is cast(Image)object )) return false; | 567 if (!( null !is cast(Image)object )) return false; |
551 Image image = cast(Image)object; | 568 Image image = cast(Image)object; |
552 return device is image.device && handle is image.handle && | 569 return device is image.device && handle is image.handle && |
553 transparentPixel is image.transparentPixel; | 570 transparentPixel is image.transparentPixel; |
554 } | 571 } |
572 | |
573 alias opEquals equals; | |
555 | 574 |
556 /** | 575 /** |
557 * Returns the color to which to map the transparent pixel, or null if | 576 * Returns the color to which to map the transparent pixel, or null if |
558 * the receiver has no transparent pixel. | 577 * the receiver has no transparent pixel. |
559 * <p> | 578 * <p> |
575 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | 594 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); |
576 if (transparentPixel is -1) return null; | 595 if (transparentPixel is -1) return null; |
577 int red = (transparentPixel >> 16) & 0xFF; | 596 int red = (transparentPixel >> 16) & 0xFF; |
578 int green = (transparentPixel >> 8) & 0xFF; | 597 int green = (transparentPixel >> 8) & 0xFF; |
579 int blue = (transparentPixel >> 0) & 0xFF; | 598 int blue = (transparentPixel >> 0) & 0xFF; |
580 return Color.cocoa_new(device, new float[]{red / 255f, green / 255f, blue / 255f, 1}); | 599 return Color.cocoa_new(device, new float[][red / 255f, green / 255f, blue / 255f, 1]); |
581 } | 600 } |
582 | 601 |
583 /** | 602 /** |
584 * Returns the bounds of the receiver. The rectangle will always | 603 * Returns the bounds of the receiver. The rectangle will always |
585 * have x and y values of 0, and the width and height of the | 604 * have x and y values of 0, and the width and height of the |
620 | 639 |
621 NSSize size = handle.size(); | 640 NSSize size = handle.size(); |
622 int width = cast(int)size.width; | 641 int width = cast(int)size.width; |
623 int height = cast(int)size.height; | 642 int height = cast(int)size.height; |
624 NSBitmapImageRep imageRep = this.imageRep; | 643 NSBitmapImageRep imageRep = this.imageRep; |
625 int bpr = imageRep.bytesPerRow(); | 644 NSInteger bpr = imageRep.bytesPerRow(); |
626 int bpp = imageRep.bitsPerPixel(); | 645 NSInteger bpp = imageRep.bitsPerPixel(); |
627 int dataSize = height * bpr; | 646 size_t dataSize = height * bpr; |
628 byte[] srcData = new byte[dataSize]; | 647 byte[] srcData = new byte[dataSize]; |
629 OS.memmove(srcData, imageRep.bitmapData(), dataSize); | 648 OS.memmove(srcData.ptr, imageRep.bitmapData(), dataSize); |
630 | 649 |
631 PaletteData palette = new PaletteData(0xFF0000, 0xFF00, 0xFF); | 650 PaletteData palette = new PaletteData(0xFF0000, 0xFF00, 0xFF); |
632 ImageData data = new ImageData(width, height, bpp, palette); | 651 ImageData data = new ImageData(width, height, bpp, palette); |
633 data.data = srcData; | 652 data.data = srcData; |
634 data.bytesPerLine = bpr; | 653 data.bytesPerLine = bpr; |
686 Image image = new Image(device); | 705 Image image = new Image(device); |
687 image.type = type; | 706 image.type = type; |
688 image.handle = nsImage; | 707 image.handle = nsImage; |
689 NSImageRep rep = nsImage.bestRepresentationForDevice(null); | 708 NSImageRep rep = nsImage.bestRepresentationForDevice(null); |
690 if (rep.isKindOfClass(NSBitmapImageRep.static_class())) { | 709 if (rep.isKindOfClass(NSBitmapImageRep.static_class())) { |
691 image.imageRep = new NSBitmapImageRep(rep.id); | 710 image.imageRep = new NSBitmapImageRep(rep.id_); |
692 } | 711 } |
693 return image; | 712 return image; |
694 } | 713 } |
695 | 714 |
696 /** | 715 /** |
701 * | 720 * |
702 * @return the receiver's hash | 721 * @return the receiver's hash |
703 * | 722 * |
704 * @see #equals | 723 * @see #equals |
705 */ | 724 */ |
706 public int hashCode () { | 725 public hash_t toHash () { |
707 return handle !is null ? handle.id : 0; | 726 return handle !is null ? handle.id_ : null; |
708 } | 727 } |
728 | |
729 alias toHash hashCode; | |
709 | 730 |
710 void init(int width, int height) { | 731 void init(int width, int height) { |
711 if (width <= 0 || height <= 0) { | 732 if (width <= 0 || height <= 0) { |
712 DWT.error (DWT.ERROR_INVALID_ARGUMENT); | 733 DWT.error (DWT.ERROR_INVALID_ARGUMENT); |
713 } | 734 } |
714 this.type = DWT.BITMAP; | 735 this.type = DWT.BITMAP; |
715 this.width = width; | 736 this.width = width; |
716 this.height = height; | 737 this.height = height; |
717 | 738 |
718 handle = cast(NSImage)new NSImage().alloc(); | 739 handle = cast(NSImage)(new NSImage()).alloc(); |
719 NSSize size = new NSSize(); | 740 NSSize size = NSSize(); |
720 size.width = width; | 741 size.width = width; |
721 size.height = height; | 742 size.height = height; |
722 handle = handle.initWithSize(size); | 743 handle = handle.initWithSize(size); |
723 NSBitmapImageRep rep = imageRep = cast(NSBitmapImageRep)new NSBitmapImageRep().alloc(); | 744 NSBitmapImageRep rep = imageRep = cast(NSBitmapImageRep)(new NSBitmapImageRep()).alloc(); |
724 rep = rep.initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bitmapFormat_bytesPerRow_bitsPerPixel_(0, width, height, 8, 3, false, false, new NSString(OS.NSDeviceRGBColorSpace()), OS.NSAlphaFirstBitmapFormat | OS.NSAlphaNonpremultipliedBitmapFormat, width * 4, 32); | 745 rep = rep.initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bitmapFormat_bytesPerRow_bitsPerPixel_(0, cast(NSInteger) width, cast(NSInteger) height, 8, 3, false, false, new NSString(OS.NSDeviceRGBColorSpace()), OS.NSAlphaFirstBitmapFormat | OS.NSAlphaNonpremultipliedBitmapFormat, cast(NSInteger) (width * 4), 32); |
725 OS.memset(rep.bitmapData(), 0xFF, width * height * 4); | 746 OS.memset(rep.bitmapData(), 0xFF, cast(size_t) (width * height * 4)); |
726 handle.addRepresentation(rep); | 747 handle.addRepresentation(rep); |
727 // rep.release(); | 748 // rep.release(); |
728 } | 749 } |
729 | 750 |
730 void init(ImageData image) { | 751 void init(ImageData image) { |
735 if (!(((image.depth is 1 || image.depth is 2 || image.depth is 4 || image.depth is 8) && !palette.isDirect) || | 756 if (!(((image.depth is 1 || image.depth is 2 || image.depth is 4 || image.depth is 8) && !palette.isDirect) || |
736 ((image.depth is 8) || (image.depth is 16 || image.depth is 24 || image.depth is 32) && palette.isDirect))) | 757 ((image.depth is 8) || (image.depth is 16 || image.depth is 24 || image.depth is 32) && palette.isDirect))) |
737 DWT.error(DWT.ERROR_UNSUPPORTED_DEPTH); | 758 DWT.error(DWT.ERROR_UNSUPPORTED_DEPTH); |
738 | 759 |
739 /* Create the image */ | 760 /* Create the image */ |
740 int dataSize = width * height * 4; | 761 size_t dataSize = width * height * 4; |
741 | 762 |
742 /* Initialize data */ | 763 /* Initialize data */ |
743 int bpr = width * 4; | 764 int bpr = width * 4; |
744 byte[] buffer = new byte[dataSize]; | 765 byte[] buffer = new byte[dataSize]; |
745 if (palette.isDirect) { | 766 if (palette.isDirect) { |
822 alphaOffset += 1; | 843 alphaOffset += 1; |
823 } | 844 } |
824 } | 845 } |
825 } | 846 } |
826 } | 847 } |
827 handle = cast(NSImage)new NSImage().alloc(); | 848 handle = cast(NSImage)(new NSImage()).alloc(); |
828 NSSize size = new NSSize(); | 849 NSSize size = NSSize(); |
829 size.width = width; | 850 size.width = width; |
830 size.height = height; | 851 size.height = height; |
831 handle = handle.initWithSize(size); | 852 handle = handle.initWithSize(size); |
832 NSBitmapImageRep rep = imageRep = cast(NSBitmapImageRep)new NSBitmapImageRep().alloc(); | 853 NSBitmapImageRep rep = imageRep = cast(NSBitmapImageRep)(new NSBitmapImageRep()).alloc(); |
833 rep = rep.initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bitmapFormat_bytesPerRow_bitsPerPixel_( | 854 rep = rep.initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bitmapFormat_bytesPerRow_bitsPerPixel_( |
834 0, width, height, 8, hasAlpha ? 4 : 3, hasAlpha, false, new NSString(OS.NSDeviceRGBColorSpace()), OS.NSAlphaFirstBitmapFormat | OS.NSAlphaNonpremultipliedBitmapFormat, bpr, 32); | 855 null, cast(NSInteger) width, cast(NSInteger) height, 8, hasAlpha ? 4 : 3, hasAlpha, false, new NSString(OS.NSDeviceRGBColorSpace()), OS.NSAlphaFirstBitmapFormat | OS.NSAlphaNonpremultipliedBitmapFormat, cast(NSInteger) bpr, 32); |
835 OS.memmove(rep.bitmapData(), buffer, dataSize); | 856 OS.memmove(rep.bitmapData(), buffer.ptr, dataSize); |
836 handle.addRepresentation(rep); | 857 handle.addRepresentation(rep); |
837 // rep.release(); | 858 // rep.release(); |
838 } | 859 } |
839 | 860 |
840 /** | 861 /** |
856 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 877 DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
857 } | 878 } |
858 NSGraphicsContext current = NSGraphicsContext.currentContext(); | 879 NSGraphicsContext current = NSGraphicsContext.currentContext(); |
859 NSBitmapImageRep rep = imageRep; | 880 NSBitmapImageRep rep = imageRep; |
860 if (imageRep.hasAlpha()) { | 881 if (imageRep.hasAlpha()) { |
861 int bpr = width * 4; | 882 NSInteger bpr = width * 4; |
862 rep = cast(NSBitmapImageRep)new NSBitmapImageRep().alloc(); | 883 rep = cast(NSBitmapImageRep)(new NSBitmapImageRep()).alloc(); |
863 int bitmapData = imageRep.bitmapData(); | 884 int bitmapData = imageRep.bitmapData(); |
864 if (data.bitmapDataAddress !is 0) OS.free(data.bitmapDataAddress); | 885 if (data.bitmapDataAddress !is null) OS.free(data.bitmapDataAddress); |
865 data.bitmapDataAddress = OS.malloc(4); | 886 data.bitmapDataAddress = OS.malloc((void*).sizeof); |
866 OS.memmove(data.bitmapDataAddress, new int[] {bitmapData}, 4); | 887 OS.memmove(data.bitmapDataAddress, (new int[] (bitmapData)).ptr, (void*).sizeof); |
867 rep = rep.initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bitmapFormat_bytesPerRow_bitsPerPixel_( | 888 rep = rep.initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bitmapFormat_bytesPerRow_bitsPerPixel_( |
868 data.bitmapDataAddress, width, height, 8, 3, false, false, new NSString(OS.NSDeviceRGBColorSpace()), OS.NSAlphaFirstBitmapFormat , bpr, 32); | 889 &data.bitmapDataAddress, cast(NSInteger) width, cast(NSInteger) height, 8, 3, false, false, new NSString(OS.NSDeviceRGBColorSpace()), OS.NSAlphaFirstBitmapFormat , bpr, 32); |
869 rep.autorelease(); | 890 rep.autorelease(); |
870 } | 891 } |
871 NSGraphicsContext context = NSGraphicsContext.graphicsContextWithBitmapImageRep(rep); | 892 NSGraphicsContext context = NSGraphicsContext.graphicsContextWithBitmapImageRep(rep); |
872 NSGraphicsContext.setCurrentContext(context); | 893 NSGraphicsContext.setCurrentContext(context); |
873 NSAffineTransform transform = NSAffineTransform.transform(); | 894 NSAffineTransform transform = NSAffineTransform.transform(); |
902 * | 923 * |
903 * @param hDC the platform specific GC handle | 924 * @param hDC the platform specific GC handle |
904 * @param data the platform specific GC data | 925 * @param data the platform specific GC data |
905 */ | 926 */ |
906 public void internal_dispose_GC (int context, GCData data) { | 927 public void internal_dispose_GC (int context, GCData data) { |
907 if (data.bitmapDataAddress !is 0) OS.free(data.bitmapDataAddress); | 928 if (data.bitmapDataAddress !is null) OS.free(data.bitmapDataAddress); |
908 data.bitmapDataAddress = 0; | 929 data.bitmapDataAddress = null; |
909 } | 930 } |
910 | 931 |
911 /** | 932 /** |
912 * Returns <code>true</code> if the image has been disposed, | 933 * Returns <code>true</code> if the image has been disposed, |
913 * and <code>false</code> otherwise. | 934 * and <code>false</code> otherwise. |
990 * | 1011 * |
991 * @return a string representation of the receiver | 1012 * @return a string representation of the receiver |
992 */ | 1013 */ |
993 public String toString () { | 1014 public String toString () { |
994 if (isDisposed()) return "Image {*DISPOSED*}"; | 1015 if (isDisposed()) return "Image {*DISPOSED*}"; |
995 return "Image {" + handle + "}"; | 1016 return Format("Image {{}{}" , handle , "}"); |
996 } | 1017 } |
997 | 1018 |
998 } | 1019 } |