comparison dwt/graphics/Image.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 e2affbeb686d
comparison
equal deleted inserted replaced
212:ab60f3309436 213:36f5cb12e1a2
86 * @see ImageLoader 86 * @see ImageLoader
87 */ 87 */
88 88
89 public final class Image : Resource, Drawable { 89 public final class Image : Resource, Drawable {
90 90
91 alias Resource.init_ init_;
92
91 /** 93 /**
92 * specifies whether the receiver is a bitmap or an icon 94 * specifies whether the receiver is a bitmap or an icon
93 * (one of <code>DWT.BITMAP</code>, <code>DWT.ICON</code>) 95 * (one of <code>DWT.BITMAP</code>, <code>DWT.ICON</code>)
94 * <p> 96 * <p>
95 * <b>IMPORTANT:</b> This field is <em>not</em> part of the DWT 97 * <b>IMPORTANT:</b> This field is <em>not</em> part of the DWT
154 static const int DEFAULT_SCANLINE_PAD = 4; 156 static const int DEFAULT_SCANLINE_PAD = 4;
155 157
156 /** 158 /**
157 * Prevents uninitialized instances from being created outside the package. 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
162 /** 165 /**
163 * Constructs an empty instance of this class with the 166 * Constructs an empty instance of this class with the
164 * specified width and height. The result may be drawn upon 167 * specified width and height. The result may be drawn upon
188 * @exception DWTError <ul> 191 * @exception DWTError <ul>
189 * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li> 192 * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
190 * </ul> 193 * </ul>
191 */ 194 */
192 public this(Device device, int width, int height) { 195 public this(Device device, int width, int height) {
193 if (device is null) device = Device.getDevice(); 196 super(device);
194 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 197 init_(width, height);
195 init_(device, width, height); 198 init_();
196 if (device.tracking) device.new_Object(this);
197 } 199 }
198 200
199 /** 201 /**
200 * Constructs a new instance of this class based on the 202 * Constructs a new instance of this class based on the
201 * provided image, with an appearance that varies depending 203 * provided image, with an appearance that varies depending
226 * @exception DWTError <ul> 228 * @exception DWTError <ul>
227 * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li> 229 * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
228 * </ul> 230 * </ul>
229 */ 231 */
230 public this(Device device, Image srcImage, int flag) { 232 public this(Device device, Image srcImage, int flag) {
231 if (device is null) device = Device.getDevice(); 233 super(device);
232 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 234 device = this.device;
233 this.device = device;
234 if (srcImage is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 235 if (srcImage is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
235 if (srcImage.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 236 if (srcImage.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
236 Rectangle rect = srcImage.getBounds(); 237 Rectangle rect = srcImage.getBounds();
238 this.type = srcImage.type;
237 switch (flag) { 239 switch (flag) {
238 case DWT.IMAGE_COPY: { 240 case DWT.IMAGE_COPY: {
239 this.type = srcImage.type;
240 switch (type) { 241 switch (type) {
241 case DWT.BITMAP: 242 case DWT.BITMAP:
242 /* Get the HDC for the device */ 243 /* Get the HDC for the device */
243 auto hDC = device.internal_new_GC(null); 244 auto hDC = device.internal_new_GC(null);
244 245
267 System.arraycopy(srcImage.alphaData, 0, alphaData, 0, alphaData.length); 268 System.arraycopy(srcImage.alphaData, 0, alphaData, 0, alphaData.length);
268 } 269 }
269 break; 270 break;
270 case DWT.ICON: 271 case DWT.ICON:
271 static if (OS.IsWinCE) { 272 static if (OS.IsWinCE) {
272 init_(device, srcImage.data); 273 init_(srcImage.data);
273 } else { 274 } else {
274 handle = OS.CopyImage(srcImage.handle, OS.IMAGE_ICON, rect.width, rect.height, 0); 275 handle = OS.CopyImage(srcImage.handle, OS.IMAGE_ICON, rect.width, rect.height, 0);
275 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES); 276 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES);
276 } 277 }
277 break; 278 break;
278 default: 279 default:
279 DWT.error(DWT.ERROR_INVALID_IMAGE); 280 DWT.error(DWT.ERROR_INVALID_IMAGE);
280 } 281 }
281 if (device.tracking) device.new_Object(this); 282 break;
282 return;
283 } 283 }
284 case DWT.IMAGE_DISABLE: { 284 case DWT.IMAGE_DISABLE: {
285 ImageData data = srcImage.getImageData(); 285 ImageData data = srcImage.getImageData();
286 PaletteData palette = data.palette; 286 PaletteData palette = data.palette;
287 RGB[] rgbs = new RGB[3]; 287 RGB[] rgbs = new RGB[3];
335 } 335 }
336 } 336 }
337 offset++; 337 offset++;
338 } 338 }
339 } 339 }
340 init_ (device, newData); 340 init_ (newData);
341 if (device.tracking) device.new_Object(this); 341 break;
342 return;
343 } 342 }
344 case DWT.IMAGE_GRAY: { 343 case DWT.IMAGE_GRAY: {
345 ImageData data = srcImage.getImageData(); 344 ImageData data = srcImage.getImageData();
346 PaletteData palette = data.palette; 345 PaletteData palette = data.palette;
347 ImageData newData = data; 346 ImageData newData = data;
400 } 399 }
401 offset++; 400 offset++;
402 } 401 }
403 } 402 }
404 } 403 }
405 init_ (device, newData); 404 init_ (newData);
406 if (device.tracking) device.new_Object(this); 405 break;
407 return;
408 } 406 }
409 default: 407 default:
410 DWT.error(DWT.ERROR_INVALID_ARGUMENT); 408 DWT.error(DWT.ERROR_INVALID_ARGUMENT);
411 } 409 }
410 init_();
412 } 411 }
413 412
414 /** 413 /**
415 * Constructs an empty instance of this class with the 414 * Constructs an empty instance of this class with the
416 * width and height of the specified rectangle. The result 415 * width and height of the specified rectangle. The result
440 * @exception DWTError <ul> 439 * @exception DWTError <ul>
441 * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li> 440 * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
442 * </ul> 441 * </ul>
443 */ 442 */
444 public this(Device device, Rectangle bounds) { 443 public this(Device device, Rectangle bounds) {
445 if (device is null) device = Device.getDevice(); 444 super(device);
446 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
447 if (bounds is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 445 if (bounds is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
448 init_(device, bounds.width, bounds.height); 446 init_(bounds.width, bounds.height);
449 if (device.tracking) device.new_Object(this); 447 init_();
450 } 448 }
451 449
452 /** 450 /**
453 * Constructs an instance of this class from the given 451 * Constructs an instance of this class from the given
454 * <code>ImageData</code>. 452 * <code>ImageData</code>.
466 * @exception DWTError <ul> 464 * @exception DWTError <ul>
467 * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li> 465 * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
468 * </ul> 466 * </ul>
469 */ 467 */
470 public this(Device device, ImageData data) { 468 public this(Device device, ImageData data) {
471 if (device is null) device = Device.getDevice(); 469 super(device);
472 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 470 init_(data);
473 init_(device, data); 471 init_();
474 if (device.tracking) device.new_Object(this);
475 } 472 }
476 473
477 /** 474 /**
478 * Constructs an instance of this class, whose type is 475 * Constructs an instance of this class, whose type is
479 * <code>DWT.ICON</code>, from the two given <code>ImageData</code> 476 * <code>DWT.ICON</code>, from the two given <code>ImageData</code>
498 * @exception DWTError <ul> 495 * @exception DWTError <ul>
499 * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li> 496 * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
500 * </ul> 497 * </ul>
501 */ 498 */
502 public this(Device device, ImageData source, ImageData mask) { 499 public this(Device device, ImageData source, ImageData mask) {
503 if (device is null) device = Device.getDevice(); 500 super(device);
504 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
505 if (source is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 501 if (source is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
506 if (mask is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 502 if (mask is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
507 if (source.width !is mask.width || source.height !is mask.height) { 503 if (source.width !is mask.width || source.height !is mask.height) {
508 DWT.error(DWT.ERROR_INVALID_ARGUMENT); 504 DWT.error(DWT.ERROR_INVALID_ARGUMENT);
509 } 505 }
510 mask = ImageData.convertMask(mask); 506 mask = ImageData.convertMask(mask);
511 init_(device, this, source, mask); 507 init_(this.device, this, source, mask);
512 if (device.tracking) device.new_Object(this); 508 init_();
513 } 509 }
514 510
515 /** 511 /**
516 * Constructs an instance of this class by loading its representation 512 * Constructs an instance of this class by loading its representation
517 * from the specified input stream. Throws an error if an error 513 * from the specified input stream. Throws an error if an error
559 * @exception DWTError <ul> 555 * @exception DWTError <ul>
560 * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li> 556 * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
561 * </ul> 557 * </ul>
562 */ 558 */
563 public this (Device device, InputStream stream) { 559 public this (Device device, InputStream stream) {
564 if (device is null) device = Device.getDevice(); 560 super(device);
565 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 561 init_(new ImageData(stream));
566 init_(device, new ImageData(stream)); 562 init_();
567 if (device.tracking) device.new_Object(this);
568 } 563 }
569 564
570 /** 565 /**
571 * Constructs an instance of this class by loading its representation 566 * Constructs an instance of this class by loading its representation
572 * from the file with the specified name. Throws an error if an error 567 * from the file with the specified name. Throws an error if an error
593 * @exception DWTError <ul> 588 * @exception DWTError <ul>
594 * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li> 589 * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
595 * </ul> 590 * </ul>
596 */ 591 */
597 public this (Device device, String filename) { 592 public this (Device device, String filename) {
598 if (device is null) device = Device.getDevice(); 593 super(device);
599 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 594 device = this.device;
600 if (filename is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 595 if (filename is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
601 this.device = device; 596 bool gdip = true;
602 try { 597 try {
603 device.checkGDIP(); 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 int length = filename.length; 609 int length = filename.length;
605 char[] chars = new char[length+1]; 610 char[] chars = new char[length+1];
606 filename.getChars(0, length, chars, 0); 611 filename.getChars(0, length, chars, 0);
607 auto bitmap = Gdip.Bitmap_new( .StrToWCHARz( filename ), false); 612 auto bitmap = Gdip.Bitmap_new( .StrToWCHARz( filename ), false);
608 if (bitmap !is null) { 613 if (bitmap !is null) {
739 Gdip.Bitmap_UnlockBits(bitmap, lockedBitmapData); 744 Gdip.Bitmap_UnlockBits(bitmap, lockedBitmapData);
740 Gdip.BitmapData_delete(lockedBitmapData); 745 Gdip.BitmapData_delete(lockedBitmapData);
741 ImageData img = new ImageData(width, height, depth, paletteData, scanlinePad, data); 746 ImageData img = new ImageData(width, height, depth, paletteData, scanlinePad, data);
742 img.transparentPixel = transparentPixel; 747 img.transparentPixel = transparentPixel;
743 img.alphaData = alphaData; 748 img.alphaData = alphaData;
744 init_(device, img); 749 init_(img);
745 } 750 }
746 } 751 }
747 } 752 }
748 } 753 }
749 } 754 }
751 if (status is 0) { 756 if (status is 0) {
752 if (this.handle is null) DWT.error(error); 757 if (this.handle is null) DWT.error(error);
753 return; 758 return;
754 } 759 }
755 } 760 }
756 } catch (DWTException e) {} 761 }
757 init_(device, new ImageData(filename)); 762 init_(new ImageData(filename));
758 if(device.tracking) device.new_Object(this); 763 init_();
759 } 764 }
760 765
761 /** 766 /**
762 * Create a DIB from a DDB without using GetDIBits. Note that 767 * Create a DIB from a DDB without using GetDIBits. Note that
763 * the DDB should not be selected into a HDC. 768 * the DDB should not be selected into a HDC.
851 bmi[offset + 2] = cast(byte)rgbs[j].red; 856 bmi[offset + 2] = cast(byte)rgbs[j].red;
852 bmi[offset + 3] = 0; 857 bmi[offset + 3] = 0;
853 offset += 4; 858 offset += 4;
854 } 859 }
855 } 860 }
856 int pBits; 861 void* pBits;
857 HBITMAP hDib = OS.CreateDIBSection(null, cast(BITMAPINFO*)bmi.ptr, OS.DIB_RGB_COLORS, &pBits, null, 0); 862 HBITMAP hDib = OS.CreateDIBSection(null, cast(BITMAPINFO*)bmi.ptr, OS.DIB_RGB_COLORS, &pBits, null, 0);
858 if (hDib is null) DWT.error(DWT.ERROR_NO_HANDLES); 863 if (hDib is null) DWT.error(DWT.ERROR_NO_HANDLES);
859 864
860 /* Bitblt DDB into DIB */ 865 /* Bitblt DDB into DIB */
861 auto hdcSource = OS.CreateCompatibleDC(hDC); 866 auto hdcSource = OS.CreateCompatibleDC(hDC);
875 // returning them in an int[]. Since the D GC does not and cannot scan int's for 880 // returning them in an int[]. Since the D GC does not and cannot scan int's for
876 // pointers, there is potential that the pointer's object could be collected while still 881 // pointers, there is potential that the pointer's object could be collected while still
877 // active, even though it might be unlikely given the short span of time that the 882 // active, even though it might be unlikely given the short span of time that the
878 // function has them stored in the int array. 883 // function has them stored in the int array.
879 884
880 int[] createGdipImage() { 885 int /*long*/ [] createGdipImage() {
881 switch (type) { 886 switch (type) {
882 case DWT.BITMAP: { 887 case DWT.BITMAP: {
883 if (alpha !is -1 || alphaData !is null || transparentPixel !is -1) { 888 if (alpha !is -1 || alphaData !is null || transparentPixel !is -1) {
884 BITMAP bm; 889 BITMAP bm;
885 OS.GetObject(handle, BITMAP.sizeof, &bm); 890 OS.GetObject(handle, BITMAP.sizeof, &bm);
994 OS.GetObject(hBitmap, BITMAP.sizeof, &bm); 999 OS.GetObject(hBitmap, BITMAP.sizeof, &bm);
995 int imgWidth = bm.bmWidth; 1000 int imgWidth = bm.bmWidth;
996 int imgHeight = hBitmap is iconInfo.hbmMask ? bm.bmHeight / 2 : bm.bmHeight; 1001 int imgHeight = hBitmap is iconInfo.hbmMask ? bm.bmHeight / 2 : bm.bmHeight;
997 Gdip.Bitmap img; 1002 Gdip.Bitmap img;
998 ubyte* pixels; 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 auto hDC = device.internal_new_GC(null); 1012 auto hDC = device.internal_new_GC(null);
1001 auto srcHdc = OS.CreateCompatibleDC(hDC); 1013 auto srcHdc = OS.CreateCompatibleDC(hDC);
1002 auto oldSrcBitmap = OS.SelectObject(srcHdc, hBitmap); 1014 auto oldSrcBitmap = OS.SelectObject(srcHdc, hBitmap);
1003 auto memHdc = OS.CreateCompatibleDC(hDC); 1015 auto memHdc = OS.CreateCompatibleDC(hDC);
1004 auto memDib = createDIB(imgWidth, imgHeight, 32); 1016 auto memDib = createDIB(imgWidth, imgHeight, 32);
1011 OS.DeleteObject(memHdc); 1023 OS.DeleteObject(memHdc);
1012 ubyte[] srcData = new ubyte[dibBM.bmWidthBytes * dibBM.bmHeight]; 1024 ubyte[] srcData = new ubyte[dibBM.bmWidthBytes * dibBM.bmHeight];
1013 OS.MoveMemory(srcData.ptr, dibBM.bmBits, srcData.length); 1025 OS.MoveMemory(srcData.ptr, dibBM.bmBits, srcData.length);
1014 OS.DeleteObject(memDib); 1026 OS.DeleteObject(memDib);
1015 OS.SelectObject(srcHdc, iconInfo.hbmMask); 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 for (int x = 0; x < imgWidth; ++x) { 1029 for (int x = 0; x < imgWidth; ++x) {
1018 if (OS.GetPixel(srcHdc, x, y) !is 0) { 1030 if (srcData[dp] is 0) {
1019 srcData[dp + 3] = cast(ubyte)0; 1031 if (OS.GetPixel(srcHdc, x, y) !is 0) {
1020 } else { 1032 srcData[dp] = cast(ubyte)0;
1021 srcData[dp + 3] = cast(ubyte)0xFF; 1033 } else {
1034 srcData[dp] = cast(ubyte)0xFF;
1035 }
1022 } 1036 }
1023 dp += 4; 1037 dp += 4;
1024 } 1038 }
1025 } 1039 }
1026 OS.SelectObject(srcHdc, oldSrcBitmap); 1040 OS.SelectObject(srcHdc, oldSrcBitmap);
1041 default: DWT.error(DWT.ERROR_INVALID_IMAGE); 1055 default: DWT.error(DWT.ERROR_INVALID_IMAGE);
1042 } 1056 }
1043 return null; 1057 return null;
1044 } 1058 }
1045 1059
1046 /** 1060 void destroy () {
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;
1054 if (memGC !is null) memGC.dispose(); 1061 if (memGC !is null) memGC.dispose();
1055 if (type is DWT.ICON) { 1062 if (type is DWT.ICON) {
1056 static if (OS.IsWinCE) data = null; 1063 static if (OS.IsWinCE) data = null;
1057 OS.DestroyIcon (handle); 1064 OS.DestroyIcon (handle);
1058 } else { 1065 } else {
1059 OS.DeleteObject (handle); 1066 OS.DeleteObject (handle);
1060 } 1067 }
1061 handle = null; 1068 handle = null;
1062 memGC = null; 1069 memGC = null;
1063 if (device.tracking) device.dispose_Object(this);
1064 device = null;
1065 } 1070 }
1066 1071
1067 /** 1072 /**
1068 * Compares the argument to the receiver, and returns true 1073 * Compares the argument to the receiver, and returns true
1069 * if they represent the <em>same</em> object using a class 1074 * if they represent the <em>same</em> object using a class
1577 */ 1582 */
1578 override public hash_t toHash () { 1583 override public hash_t toHash () {
1579 return cast(hash_t)handle; 1584 return cast(hash_t)handle;
1580 } 1585 }
1581 1586
1582 void init_(Device device, int width, int height) { 1587 void init_(int width, int height) {
1583 if (width <= 0 || height <= 0) { 1588 if (width <= 0 || height <= 0) {
1584 DWT.error (DWT.ERROR_INVALID_ARGUMENT); 1589 DWT.error (DWT.ERROR_INVALID_ARGUMENT);
1585 } 1590 }
1586 this.device = device;
1587 type = DWT.BITMAP; 1591 type = DWT.BITMAP;
1588 auto hDC = device.internal_new_GC(null); 1592 auto hDC = device.internal_new_GC(null);
1589 handle = OS.CreateCompatibleBitmap(hDC, width, height); 1593 handle = OS.CreateCompatibleBitmap(hDC, width, height);
1590 /* 1594 /*
1591 * Feature in Windows. CreateCompatibleBitmap() may fail 1595 * Feature in Windows. CreateCompatibleBitmap() may fail
1642 bmi[offset + 9] = cast(byte)((blueMask & 0xFF0000) >> 16); 1646 bmi[offset + 9] = cast(byte)((blueMask & 0xFF0000) >> 16);
1643 bmi[offset + 10] = cast(byte)((blueMask & 0xFF00) >> 8); 1647 bmi[offset + 10] = cast(byte)((blueMask & 0xFF00) >> 8);
1644 bmi[offset + 11] = cast(byte)((blueMask & 0xFF) >> 0); 1648 bmi[offset + 11] = cast(byte)((blueMask & 0xFF) >> 0);
1645 } 1649 }
1646 1650
1647 int[1] pBits; 1651 void* pBits;
1648 return OS.CreateDIBSection(null, cast(BITMAPINFO*)bmi.ptr, OS.DIB_RGB_COLORS, pBits.ptr, null, 0); 1652 return OS.CreateDIBSection(null, cast(BITMAPINFO*)bmi.ptr, OS.DIB_RGB_COLORS, &pBits, null, 0);
1649 } 1653 }
1650 1654
1651 /** 1655 /**
1652 * Feature in WinCE. GetIconInfo is not available in WinCE. 1656 * Feature in WinCE. GetIconInfo is not available in WinCE.
1653 * The workaround is to cache the object ImageData for images 1657 * The workaround is to cache the object ImageData for images
1664 info.hbmColor = cast(HBITMAP)result[0]; 1668 info.hbmColor = cast(HBITMAP)result[0];
1665 info.hbmMask = cast(HBITMAP)result[1]; 1669 info.hbmMask = cast(HBITMAP)result[1];
1666 } 1670 }
1667 1671
1668 static int[] init_(Device device, Image image, ImageData i) { 1672 static int[] init_(Device device, Image image, ImageData i) {
1669 if (image !is null) image.device = device;
1670 1673
1671 /* 1674 /*
1672 * BUG in Windows 98: 1675 * BUG in Windows 98:
1673 * A monochrome DIBSection will display as solid black 1676 * A monochrome DIBSection will display as solid black
1674 * on Windows 98 machines, even though it contains the 1677 * on Windows 98 machines, even though it contains the
1831 if (i.scanlinePad !is 4 && (i.bytesPerLine % 4 !is 0)) { 1834 if (i.scanlinePad !is 4 && (i.bytesPerLine % 4 !is 0)) {
1832 data = ImageData.convertPad(data, i.width, i.height, i.depth, i.scanlinePad, 4); 1835 data = ImageData.convertPad(data, i.width, i.height, i.depth, i.scanlinePad, 4);
1833 } 1836 }
1834 OS.MoveMemory(pBits, data.ptr, data.length); 1837 OS.MoveMemory(pBits, data.ptr, data.length);
1835 1838
1836 int[] result = null; 1839 int /*long*/ [] result = null;
1837 if (i.getTransparencyType() is DWT.TRANSPARENCY_MASK) { 1840 if (i.getTransparencyType() is DWT.TRANSPARENCY_MASK) {
1838 /* Get the HDC for the device */ 1841 /* Get the HDC for the device */
1839 auto hDC = device.internal_new_GC(null); 1842 auto hDC = device.internal_new_GC(null);
1840 1843
1841 /* Create the color bitmap */ 1844 /* Create the color bitmap */
1967 } 1970 }
1968 imageData.maskPad = mask.scanlinePad; 1971 imageData.maskPad = mask.scanlinePad;
1969 imageData.maskData = mask.data; 1972 imageData.maskData = mask.data;
1970 return init_(device, image, imageData); 1973 return init_(device, image, imageData);
1971 } 1974 }
1972 void init_(Device device, ImageData i) { 1975 void init_(ImageData i) {
1973 if (i is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 1976 if (i is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
1974 init_(device, this, i); 1977 init_(device, this, i);
1975 } 1978 }
1976 1979
1977 /** 1980 /**
2011 } else { 2014 } else {
2012 data.style |= DWT.LEFT_TO_RIGHT; 2015 data.style |= DWT.LEFT_TO_RIGHT;
2013 } 2016 }
2014 data.device = device; 2017 data.device = device;
2015 data.image = this; 2018 data.image = this;
2016 data.hFont = device.systemFont; 2019 data.font = device.systemFont;
2017 } 2020 }
2018 return imageDC; 2021 return imageDC;
2019 } 2022 }
2020 2023
2021 /** 2024 /**
2142 * @param type the type of the image (<code>DWT.BITMAP</code> or <code>DWT.ICON</code>) 2145 * @param type the type of the image (<code>DWT.BITMAP</code> or <code>DWT.ICON</code>)
2143 * @param handle the OS handle for the image 2146 * @param handle the OS handle for the image
2144 * @return a new image object containing the specified device, type and handle 2147 * @return a new image object containing the specified device, type and handle
2145 */ 2148 */
2146 public static Image win32_new(Device device, int type, HGDIOBJ handle) { 2149 public static Image win32_new(Device device, int type, HGDIOBJ handle) {
2147 if (device is null) device = Device.getDevice(); 2150 Image image = new Image(device);
2148 Image image = new Image();
2149 image.type = type; 2151 image.type = type;
2150 image.handle = handle; 2152 image.handle = handle;
2151 image.device = device;
2152 return image; 2153 return image;
2153 } 2154 }
2154 2155
2155 } 2156 }