Changeset 213:36f5cb12e1a2 for dwt/graphics/Image.d
- Timestamp:
- 05/17/08 11:34:28 (8 months ago)
- Files:
-
- dwt/graphics/Image.d (modified) (29 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
dwt/graphics/Image.d
r212 r213 89 89 public final class Image : Resource, Drawable { 90 90 91 alias Resource.init_ init_; 92 91 93 /** 92 94 * specifies whether the receiver is a bitmap or an icon … … 157 159 * Prevents uninitialized instances from being created outside the package. 158 160 */ 159 this () { 161 this (Device device) { 162 super(device); 160 163 } 161 164 … … 191 194 */ 192 195 public this(Device device, int width, int height) { 193 if (device is null) device = Device.getDevice(); 194 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 195 init_(device, width, height); 196 if (device.tracking) device.new_Object(this); 196 super(device); 197 init_(width, height); 198 init_(); 197 199 } 198 200 … … 229 231 */ 230 232 public this(Device device, Image srcImage, int flag) { 231 if (device is null) device = Device.getDevice(); 232 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 233 this.device = device; 233 super(device); 234 device = this.device; 234 235 if (srcImage is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 235 236 if (srcImage.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 236 237 Rectangle rect = srcImage.getBounds(); 238 this.type = srcImage.type; 237 239 switch (flag) { 238 240 case DWT.IMAGE_COPY: { 239 this.type = srcImage.type;240 241 switch (type) { 241 242 case DWT.BITMAP: … … 270 271 case DWT.ICON: 271 272 static if (OS.IsWinCE) { 272 init_( device,srcImage.data);273 init_(srcImage.data); 273 274 } else { 274 275 handle = OS.CopyImage(srcImage.handle, OS.IMAGE_ICON, rect.width, rect.height, 0); … … 279 280 DWT.error(DWT.ERROR_INVALID_IMAGE); 280 281 } 281 if (device.tracking) device.new_Object(this); 282 return; 282 break; 283 283 } 284 284 case DWT.IMAGE_DISABLE: { … … 338 338 } 339 339 } 340 init_ (device, newData); 341 if (device.tracking) device.new_Object(this); 342 return; 340 init_ (newData); 341 break; 343 342 } 344 343 case DWT.IMAGE_GRAY: { … … 403 402 } 404 403 } 405 init_ (device, newData); 406 if (device.tracking) device.new_Object(this); 407 return; 404 init_ (newData); 405 break; 408 406 } 409 407 default: 410 408 DWT.error(DWT.ERROR_INVALID_ARGUMENT); 411 409 } 410 init_(); 412 411 } 413 412 … … 443 442 */ 444 443 public this(Device device, Rectangle bounds) { 445 if (device is null) device = Device.getDevice(); 446 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 444 super(device); 447 445 if (bounds is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 448 init_( device,bounds.width, bounds.height);449 i f (device.tracking) device.new_Object(this);446 init_(bounds.width, bounds.height); 447 init_(); 450 448 } 451 449 … … 469 467 */ 470 468 public this(Device device, ImageData data) { 471 if (device is null) device = Device.getDevice(); 472 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 473 init_(device, data); 474 if (device.tracking) device.new_Object(this); 469 super(device); 470 init_(data); 471 init_(); 475 472 } 476 473 … … 501 498 */ 502 499 public this(Device device, ImageData source, ImageData mask) { 503 if (device is null) device = Device.getDevice(); 504 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 500 super(device); 505 501 if (source is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 506 502 if (mask is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); … … 509 505 } 510 506 mask = ImageData.convertMask(mask); 511 init_( device, this, source, mask);512 i f (device.tracking) device.new_Object(this);507 init_(this.device, this, source, mask); 508 init_(); 513 509 } 514 510 … … 562 558 */ 563 559 public this (Device device, InputStream stream) { 564 if (device is null) device = Device.getDevice(); 565 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 566 init_(device, new ImageData(stream)); 567 if (device.tracking) device.new_Object(this); 560 super(device); 561 init_(new ImageData(stream)); 562 init_(); 568 563 } 569 564 … … 596 591 */ 597 592 public this (Device device, String filename) { 598 if (device is null) device = Device.getDevice();599 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);593 super(device); 594 device = this.device; 600 595 if (filename is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 601 this.device = device;596 bool gdip = true; 602 597 try { 603 598 device.checkGDIP(); 599 } catch (DWTException e) { 600 gdip = false; 601 } 602 /* 603 * Bug in GDI+. For some reason, Bitmap.LockBits() segment faults 604 * when loading GIF files in 64-bit Windows. The fix is to not use 605 * GDI+ image loading in this case. 606 */ 607 if (gdip && (void*).sizeof is 8 && filename.toLowerCase().endsWith(".gif")) gdip = false; 608 if (gdip) { 604 609 int length = filename.length; 605 610 char[] chars = new char[length+1]; … … 742 747 img.transparentPixel = transparentPixel; 743 748 img.alphaData = alphaData; 744 init_( device,img);749 init_(img); 745 750 } 746 751 } … … 754 759 } 755 760 } 756 } catch (DWTException e) {}757 init_( device,new ImageData(filename));758 i f(device.tracking) device.new_Object(this);761 } 762 init_(new ImageData(filename)); 763 init_(); 759 764 } 760 765 … … 854 859 } 855 860 } 856 intpBits;861 void* pBits; 857 862 HBITMAP hDib = OS.CreateDIBSection(null, cast(BITMAPINFO*)bmi.ptr, OS.DIB_RGB_COLORS, &pBits, null, 0); 858 863 if (hDib is null) DWT.error(DWT.ERROR_NO_HANDLES); … … 878 883 // function has them stored in the int array. 879 884 880 int [] createGdipImage() {885 int /*long*/ [] createGdipImage() { 881 886 switch (type) { 882 887 case DWT.BITMAP: { … … 997 1002 Gdip.Bitmap img; 998 1003 ubyte* pixels; 999 if (imgWidth > imgHeight) { 1004 /* 1005 * Bug in GDI+. Bitmap_new() segments fault if the image width 1006 * is greater than the image height. 1007 * 1008 * Note that it also fails to generated an appropriate alpha 1009 * channel when the icon depth is 32. 1010 */ 1011 if (imgWidth > imgHeight || bm.bmBitsPixel is 32) { 1000 1012 auto hDC = device.internal_new_GC(null); 1001 1013 auto srcHdc = OS.CreateCompatibleDC(hDC); … … 1014 1026 OS.DeleteObject(memDib); 1015 1027 OS.SelectObject(srcHdc, iconInfo.hbmMask); 1016 for (int y = 0, dp = 0; y < imgHeight; ++y) {1028 for (int y = 0, dp = 3; y < imgHeight; ++y) { 1017 1029 for (int x = 0; x < imgWidth; ++x) { 1018 if (OS.GetPixel(srcHdc, x, y) !is 0) { 1019 srcData[dp + 3] = cast(ubyte)0; 1020 } else { 1021 srcData[dp + 3] = cast(ubyte)0xFF; 1030 if (srcData[dp] is 0) { 1031 if (OS.GetPixel(srcHdc, x, y) !is 0) { 1032 srcData[dp] = cast(ubyte)0; 1033 } else { 1034 srcData[dp] = cast(ubyte)0xFF; 1035 } 1022 1036 } 1023 1037 dp += 4; … … 1044 1058 } 1045 1059 1046 /** 1047 * Disposes of the operating system resources associated with 1048 * the image. Applications must dispose of all images which 1049 * they allocate. 1050 */ 1051 override public void dispose () { 1052 if (handle is null) return; 1053 if (device.isDisposed()) return; 1060 void destroy () { 1054 1061 if (memGC !is null) memGC.dispose(); 1055 1062 if (type is DWT.ICON) { … … 1061 1068 handle = null; 1062 1069 memGC = null; 1063 if (device.tracking) device.dispose_Object(this);1064 device = null;1065 1070 } 1066 1071 … … 1580 1585 } 1581 1586 1582 void init_( Device device,int width, int height) {1587 void init_(int width, int height) { 1583 1588 if (width <= 0 || height <= 0) { 1584 1589 DWT.error (DWT.ERROR_INVALID_ARGUMENT); 1585 1590 } 1586 this.device = device;1587 1591 type = DWT.BITMAP; 1588 1592 auto hDC = device.internal_new_GC(null); … … 1645 1649 } 1646 1650 1647 int[1]pBits;1648 return OS.CreateDIBSection(null, cast(BITMAPINFO*)bmi.ptr, OS.DIB_RGB_COLORS, pBits.ptr, null, 0);1651 void* pBits; 1652 return OS.CreateDIBSection(null, cast(BITMAPINFO*)bmi.ptr, OS.DIB_RGB_COLORS, &pBits, null, 0); 1649 1653 } 1650 1654 … … 1667 1671 1668 1672 static int[] init_(Device device, Image image, ImageData i) { 1669 if (image !is null) image.device = device;1670 1673 1671 1674 /* … … 1834 1837 OS.MoveMemory(pBits, data.ptr, data.length); 1835 1838 1836 int [] result = null;1839 int /*long*/ [] result = null; 1837 1840 if (i.getTransparencyType() is DWT.TRANSPARENCY_MASK) { 1838 1841 /* Get the HDC for the device */ … … 1970 1973 return init_(device, image, imageData); 1971 1974 } 1972 void init_( Device device,ImageData i) {1975 void init_(ImageData i) { 1973 1976 if (i is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 1974 1977 init_(device, this, i); … … 2014 2017 data.device = device; 2015 2018 data.image = this; 2016 data. hFont = device.systemFont;2019 data.font = device.systemFont; 2017 2020 } 2018 2021 return imageDC; … … 2145 2148 */ 2146 2149 public static Image win32_new(Device device, int type, HGDIOBJ handle) { 2147 if (device is null) device = Device.getDevice(); 2148 Image image = new Image(); 2150 Image image = new Image(device); 2149 2151 image.type = type; 2150 2152 image.handle = handle; 2151 image.device = device;2152 2153 return image; 2153 2154 }
