comparison dwt/graphics/Image.d @ 33:27324bbbac70

changed to regenerated BCD bindings
author Frank Benoit <benoit@tionex.de>
date Thu, 10 Jan 2008 02:18:07 +0100
parents 10acbb123580
children 93981635e709
comparison
equal deleted inserted replaced
32:b7c28480e3e0 33:27324bbbac70
11 module dwt.graphics.Image; 11 module dwt.graphics.Image;
12 12
13 import dwt.internal.Converter; 13 import dwt.internal.Converter;
14 import dwt.internal.cairo.Cairo; 14 import dwt.internal.cairo.Cairo;
15 import dwt.internal.gtk.OS; 15 import dwt.internal.gtk.OS;
16 import dwt.internal.gtk.c.cairotypes;
17 import dwt.internal.gtk.c.gdktypes;
18 import dwt.SWT; 16 import dwt.SWT;
19 import dwt.SWTException; 17 import dwt.SWTException;
20 import dwt.graphics.Color; 18 import dwt.graphics.Color;
21 import dwt.graphics.Device; 19 import dwt.graphics.Device;
22 import dwt.graphics.Drawable; 20 import dwt.graphics.Drawable;
296 if (device.tracking) device.new_Object(this); 294 if (device.tracking) device.new_Object(this);
297 return; 295 return;
298 } 296 }
299 297
300 /* Retrieve the source pixmap data */ 298 /* Retrieve the source pixmap data */
301 auto pixbuf = OS.gdk_pixbuf_new(cast(GdkColorspace)OS.GDK_COLORSPACE_RGB, false, 8, width, height); 299 auto pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, width, height);
302 if (pixbuf is null) SWT.error(SWT.ERROR_NO_HANDLES); 300 if (pixbuf is null) SWT.error(SWT.ERROR_NO_HANDLES);
303 auto colormap = OS.gdk_colormap_get_system(); 301 auto colormap = OS.gdk_colormap_get_system();
304 OS.gdk_pixbuf_get_from_drawable(pixbuf, srcImage.pixmap, colormap, 0, 0, 0, 0, width, height); 302 OS.gdk_pixbuf_get_from_drawable(pixbuf, srcImage.pixmap, colormap, 0, 0, 0, 0, width, height);
305 int stride = OS.gdk_pixbuf_get_rowstride(pixbuf); 303 int stride = OS.gdk_pixbuf_get_rowstride(pixbuf);
306 auto pixels = OS.gdk_pixbuf_get_pixels(pixbuf); 304 auto pixels = OS.gdk_pixbuf_get_pixels(pixbuf);
358 break; 356 break;
359 } 357 }
360 } 358 }
361 359
362 /* Copy data back to destination pixmap */ 360 /* Copy data back to destination pixmap */
363 OS.gdk_pixbuf_render_to_drawable(pixbuf, pixmap, gdkGC, 0, 0, 0, 0, width, height, cast(GdkRgbDither)OS.GDK_RGB_DITHER_NORMAL, 0, 0); 361 OS.gdk_pixbuf_render_to_drawable(pixbuf, pixmap, gdkGC, 0, 0, 0, 0, width, height, OS.GDK_RGB_DITHER_NORMAL, 0, 0);
364 362
365 /* Free resources */ 363 /* Free resources */
366 OS.g_object_unref(pixbuf); 364 OS.g_object_unref(pixbuf);
367 OS.g_object_unref(gdkGC); 365 OS.g_object_unref(gdkGC);
368 if (device.tracking) device.new_Object(this); 366 if (device.tracking) device.new_Object(this);
661 if (transparentPixel != -1) createMask(); 659 if (transparentPixel != -1) createMask();
662 int w, h; 660 int w, h;
663 OS.gdk_drawable_get_size(pixmap, &w, &h); 661 OS.gdk_drawable_get_size(pixmap, &w, &h);
664 int width = w, height = h; 662 int width = w, height = h;
665 if (mask !is null || alpha != -1 || alphaData != null) { 663 if (mask !is null || alpha != -1 || alphaData != null) {
666 auto pixbuf = OS.gdk_pixbuf_new( cast(GdkColorspace)OS.GDK_COLORSPACE_RGB, true, 8, width, height); 664 auto pixbuf = OS.gdk_pixbuf_new( OS.GDK_COLORSPACE_RGB, true, 8, width, height);
667 if (pixbuf is null) SWT.error(SWT.ERROR_NO_HANDLES); 665 if (pixbuf is null) SWT.error(SWT.ERROR_NO_HANDLES);
668 auto colormap = OS.gdk_colormap_get_system(); 666 auto colormap = OS.gdk_colormap_get_system();
669 OS.gdk_pixbuf_get_from_drawable(pixbuf, pixmap, colormap, 0, 0, 0, 0, width, height); 667 OS.gdk_pixbuf_get_from_drawable(pixbuf, pixmap, colormap, 0, 0, 0, 0, width, height);
670 int stride = OS.gdk_pixbuf_get_rowstride(pixbuf); 668 int stride = OS.gdk_pixbuf_get_rowstride(pixbuf);
671 auto pixels = OS.gdk_pixbuf_get_pixels(pixbuf); 669 auto pixels = OS.gdk_pixbuf_get_pixels(pixbuf);
672 byte[] line = new byte[stride]; 670 byte[] line = new byte[stride];
673 if (mask !is null && OS.gdk_drawable_get_depth(mask) == 1) { 671 if (mask !is null && OS.gdk_drawable_get_depth(mask) == 1) {
674 auto maskPixbuf = OS.gdk_pixbuf_new(cast(GdkColorspace)OS.GDK_COLORSPACE_RGB, false, 8, width, height); 672 auto maskPixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, width, height);
675 if (maskPixbuf is null) SWT.error(SWT.ERROR_NO_HANDLES); 673 if (maskPixbuf is null) SWT.error(SWT.ERROR_NO_HANDLES);
676 OS.gdk_pixbuf_get_from_drawable(maskPixbuf, mask, null, 0, 0, 0, 0, width, height); 674 OS.gdk_pixbuf_get_from_drawable(maskPixbuf, mask, null, 0, 0, 0, 0, width, height);
677 int maskStride = OS.gdk_pixbuf_get_rowstride(maskPixbuf); 675 int maskStride = OS.gdk_pixbuf_get_rowstride(maskPixbuf);
678 auto maskPixels = OS.gdk_pixbuf_get_pixels(maskPixbuf); 676 auto maskPixels = OS.gdk_pixbuf_get_pixels(maskPixbuf);
679 byte[] maskLine = new byte[maskStride]; 677 byte[] maskLine = new byte[maskStride];
749 offset += stride; 747 offset += stride;
750 } 748 }
751 } 749 }
752 surfaceData = cast(cairo_surface_t*) OS.g_malloc(stride * height); 750 surfaceData = cast(cairo_surface_t*) OS.g_malloc(stride * height);
753 memmove(surfaceData, pixels, stride * height); 751 memmove(surfaceData, pixels, stride * height);
754 surface = Cairo.cairo_image_surface_create_for_data(cast(ubyte*)surfaceData, cast(cairo_format_t)Cairo.CAIRO_FORMAT_ARGB32, width, height, stride); 752 surface = Cairo.cairo_image_surface_create_for_data(cast(char*)surfaceData, Cairo.CAIRO_FORMAT_ARGB32, width, height, stride);
755 OS.g_object_unref(pixbuf); 753 OS.g_object_unref(pixbuf);
756 } else { 754 } else {
757 auto xDisplay = OS.GDK_DISPLAY(); 755 auto xDisplay = OS.GDK_DISPLAY();
758 auto xDrawable = OS.GDK_PIXMAP_XID(pixmap); 756 auto xDrawable = OS.GDK_PIXMAP_XID(pixmap);
759 auto xVisual = OS.gdk_x11_visual_get_xvisual(OS.gdk_visual_get_system()); 757 auto xVisual = OS.gdk_x11_visual_get_xvisual(OS.gdk_visual_get_system());
878 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); 876 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
879 877
880 int w, h; 878 int w, h;
881 OS.gdk_drawable_get_size(pixmap, &w, &h); 879 OS.gdk_drawable_get_size(pixmap, &w, &h);
882 int width = w, height = h; 880 int width = w, height = h;
883 auto pixbuf = OS.gdk_pixbuf_new(cast(GdkColorspace)OS.GDK_COLORSPACE_RGB, false, 8, width, height); 881 auto pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, width, height);
884 if (pixbuf is null) SWT.error(SWT.ERROR_NO_HANDLES); 882 if (pixbuf is null) SWT.error(SWT.ERROR_NO_HANDLES);
885 auto colormap = OS.gdk_colormap_get_system(); 883 auto colormap = OS.gdk_colormap_get_system();
886 OS.gdk_pixbuf_get_from_drawable(pixbuf, pixmap, colormap, 0, 0, 0, 0, width, height); 884 OS.gdk_pixbuf_get_from_drawable(pixbuf, pixmap, colormap, 0, 0, 0, 0, width, height);
887 int stride = OS.gdk_pixbuf_get_rowstride(pixbuf); 885 int stride = OS.gdk_pixbuf_get_rowstride(pixbuf);
888 auto pixels = OS.gdk_pixbuf_get_pixels(pixbuf); 886 auto pixels = OS.gdk_pixbuf_get_pixels(pixbuf);
1004 int height = image.height; 1002 int height = image.height;
1005 PaletteData palette = image.palette; 1003 PaletteData palette = image.palette;
1006 if (!(((image.depth == 1 || image.depth == 2 || image.depth == 4 || image.depth == 8) && !palette.isDirect) || 1004 if (!(((image.depth == 1 || image.depth == 2 || image.depth == 4 || image.depth == 8) && !palette.isDirect) ||
1007 ((image.depth == 8) || (image.depth == 16 || image.depth == 24 || image.depth == 32) && palette.isDirect))) 1005 ((image.depth == 8) || (image.depth == 16 || image.depth == 24 || image.depth == 32) && palette.isDirect)))
1008 SWT.error (SWT.ERROR_UNSUPPORTED_DEPTH); 1006 SWT.error (SWT.ERROR_UNSUPPORTED_DEPTH);
1009 auto pixbuf = OS.gdk_pixbuf_new(cast(GdkColorspace) OS.GDK_COLORSPACE_RGB, false, 8, width, height); 1007 auto pixbuf = OS.gdk_pixbuf_new( OS.GDK_COLORSPACE_RGB, false, 8, width, height);
1010 if (pixbuf is null) SWT.error(SWT.ERROR_NO_HANDLES); 1008 if (pixbuf is null) SWT.error(SWT.ERROR_NO_HANDLES);
1011 int stride = OS.gdk_pixbuf_get_rowstride(pixbuf); 1009 int stride = OS.gdk_pixbuf_get_rowstride(pixbuf);
1012 auto data = OS.gdk_pixbuf_get_pixels(pixbuf); 1010 auto data = OS.gdk_pixbuf_get_pixels(pixbuf);
1013 byte[] buffer = image.data; 1011 byte[] buffer = image.data;
1014 if (!palette.isDirect || image.depth != 24 || stride != image.bytesPerLine || palette.redMask != 0xFF0000 || palette.greenMask != 0xFF00 || palette.blueMask != 0xFF) { 1012 if (!palette.isDirect || image.depth != 24 || stride != image.bytesPerLine || palette.redMask != 0xFF0000 || palette.greenMask != 0xFF00 || palette.blueMask != 0xFF) {
1042 memmove(data, buffer.ptr, stride * height); 1040 memmove(data, buffer.ptr, stride * height);
1043 auto pixmap = cast(GdkDrawable*) OS.gdk_pixmap_new (cast(GdkDrawable*) OS.GDK_ROOT_PARENT(), width, height, -1); 1041 auto pixmap = cast(GdkDrawable*) OS.gdk_pixmap_new (cast(GdkDrawable*) OS.GDK_ROOT_PARENT(), width, height, -1);
1044 if (pixmap is null) SWT.error(SWT.ERROR_NO_HANDLES); 1042 if (pixmap is null) SWT.error(SWT.ERROR_NO_HANDLES);
1045 auto gdkGC = OS.gdk_gc_new(pixmap); 1043 auto gdkGC = OS.gdk_gc_new(pixmap);
1046 if (gdkGC is null) SWT.error(SWT.ERROR_NO_HANDLES); 1044 if (gdkGC is null) SWT.error(SWT.ERROR_NO_HANDLES);
1047 OS.gdk_pixbuf_render_to_drawable(pixbuf, pixmap, gdkGC, 0, 0, 0, 0, width, height, cast(GdkRgbDither)OS.GDK_RGB_DITHER_NORMAL, 0, 0); 1045 OS.gdk_pixbuf_render_to_drawable(pixbuf, pixmap, gdkGC, 0, 0, 0, 0, width, height, OS.GDK_RGB_DITHER_NORMAL, 0, 0);
1048 OS.g_object_unref(gdkGC); 1046 OS.g_object_unref(gdkGC);
1049 OS.g_object_unref(pixbuf); 1047 OS.g_object_unref(pixbuf);
1050 1048
1051 bool isIcon = image.getTransparencyType() == SWT.TRANSPARENCY_MASK; 1049 bool isIcon = image.getTransparencyType() == SWT.TRANSPARENCY_MASK;
1052 if (isIcon || image.transparentPixel != -1) { 1050 if (isIcon || image.transparentPixel != -1) {