From 641df66d77688c7d9893fc22d380993faf531414 Mon Sep 17 00:00:00 2001 From: Silenio Date: Tue, 18 Oct 2011 16:57:45 -0400 Subject: fix init(ImageData) for opaque images, make code have two code paths only --- .../gtk/org/eclipse/swt/graphics/Image.java | 235 ++++++++++++--------- 1 file changed, 140 insertions(+), 95 deletions(-) (limited to 'bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java') diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java index e3d7e970ae..52d900e3aa 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java @@ -1084,100 +1084,80 @@ void init(ImageData image) { if (!(((image.depth == 1 || image.depth == 2 || image.depth == 4 || image.depth == 8) && !palette.isDirect) || ((image.depth == 8) || (image.depth == 16 || image.depth == 24 || image.depth == 32) && palette.isDirect))) SWT.error (SWT.ERROR_UNSUPPORTED_DEPTH); - int stride, destDepth, redMask = 0xFF0000, greenMask = 0xFF00, blueMask = 0xFF, srcOrder = ImageData.MSB_FIRST; - int /*long*/ data, pixbuf = 0; - int oa = 0, or = 0, og = 0, ob = 0; if (OS.USE_CAIRO_SURFACE) { - stride = Cairo.cairo_format_stride_for_width(Cairo.CAIRO_FORMAT_ARGB32, width); - data = surfaceData = OS.g_malloc(stride * height); + int stride = Cairo.cairo_format_stride_for_width(Cairo.CAIRO_FORMAT_ARGB32, width); + int /*long*/ data = surfaceData = OS.g_malloc(stride * height); if (surfaceData == 0) SWT.error(SWT.ERROR_NO_HANDLES); surface = Cairo.cairo_image_surface_create_for_data(surfaceData, Cairo.CAIRO_FORMAT_ARGB32, width, height, stride); if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES); - destDepth = 32; - byte[] line = new byte[stride]; + byte[] buffer = new byte[4]; int /*long*/ ptr = OS.malloc(4); OS.memmove(ptr, new int[]{1}, 4); - OS.memmove(line, ptr, 1); + OS.memmove(buffer, ptr, 1); OS.free(ptr); - boolean bigendian = line[0] == 0; + boolean bigendian = buffer[0] == 0; + int oa = 0, or = 0, og = 0, ob = 0; + int redMask, greenMask, blueMask, destDepth = 32, destOrder; if (bigendian) { oa = 0; or = 1; og = 2; ob = 3; redMask = 0xFF00; greenMask = 0xFF0000; blueMask = 0xFF000000; + destOrder = ImageData.MSB_FIRST; } else { oa = 3; or = 2; og = 1; ob = 0; redMask = 0xFF0000; greenMask = 0xFF00; blueMask = 0xFF; - srcOrder = ImageData.LSB_FIRST; - } - } else { - pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, width, height); - if (pixbuf == 0) SWT.error(SWT.ERROR_NO_HANDLES); - stride = OS.gdk_pixbuf_get_rowstride(pixbuf); - data = OS.gdk_pixbuf_get_pixels(pixbuf); - destDepth = 24; - } - byte[] buffer = image.data; - if (!palette.isDirect || image.depth != destDepth || stride != image.bytesPerLine || palette.redMask != redMask || palette.greenMask != greenMask || palette.blueMask != blueMask) { - buffer = new byte[stride * height]; - if (palette.isDirect) { - ImageData.blit(ImageData.BLIT_SRC, - image.data, image.depth, image.bytesPerLine, image.getByteOrder(), 0, 0, width, height, palette.redMask, palette.greenMask, palette.blueMask, - ImageData.ALPHA_OPAQUE, null, 0, 0, 0, - buffer, destDepth, stride, srcOrder, 0, 0, width, height, redMask, greenMask, blueMask, - false, false); - } else { - RGB[] rgbs = palette.getRGBs(); - int length = rgbs.length; - byte[] srcReds = new byte[length]; - byte[] srcGreens = new byte[length]; - byte[] srcBlues = new byte[length]; - for (int i = 0; i < rgbs.length; i++) { - RGB rgb = rgbs[i]; - if (rgb == null) continue; - srcReds[i] = (byte)rgb.red; - srcGreens[i] = (byte)rgb.green; - srcBlues[i] = (byte)rgb.blue; - } - ImageData.blit(ImageData.BLIT_SRC, - image.data, image.depth, image.bytesPerLine, image.getByteOrder(), 0, 0, width, height, srcReds, srcGreens, srcBlues, - ImageData.ALPHA_OPAQUE, null, 0, 0, 0, - buffer, destDepth, stride, srcOrder, 0, 0, width, height, redMask, greenMask, blueMask, - false, false); + destOrder = ImageData.LSB_FIRST; } - } - OS.memmove(data, buffer, stride * height); - if (!OS.USE_CAIRO_SURFACE) { - int /*long*/ pixmap = OS.gdk_pixmap_new (OS.GDK_ROOT_PARENT(), width, height, -1); - if (pixmap == 0) SWT.error(SWT.ERROR_NO_HANDLES); - int /*long*/ gdkGC = OS.gdk_gc_new(pixmap); - if (gdkGC == 0) SWT.error(SWT.ERROR_NO_HANDLES); - OS.gdk_pixbuf_render_to_drawable(pixbuf, pixmap, gdkGC, 0, 0, 0, 0, width, height, OS.GDK_RGB_DITHER_NORMAL, 0, 0); - OS.g_object_unref(gdkGC); - OS.g_object_unref(pixbuf); - this.pixmap = pixmap; - } - boolean isIcon = image.getTransparencyType() == SWT.TRANSPARENCY_MASK; - if (isIcon || image.transparentPixel != -1) { - if (image.transparentPixel != -1) { - RGB rgb = null; + buffer = image.data; + if (!palette.isDirect || image.depth != destDepth || stride != image.bytesPerLine || palette.redMask != redMask || palette.greenMask != greenMask || palette.blueMask != blueMask) { + buffer = new byte[stride * height]; if (palette.isDirect) { - rgb = palette.getRGB(image.transparentPixel); + ImageData.blit(ImageData.BLIT_SRC, + image.data, image.depth, image.bytesPerLine, image.getByteOrder(), 0, 0, width, height, palette.redMask, palette.greenMask, palette.blueMask, + ImageData.ALPHA_OPAQUE, null, 0, 0, 0, + buffer, destDepth, stride, destOrder, 0, 0, width, height, redMask, greenMask, blueMask, + false, false); } else { - if (image.transparentPixel < palette.colors.length) { - rgb = palette.getRGB(image.transparentPixel); + RGB[] rgbs = palette.getRGBs(); + int length = rgbs.length; + byte[] srcReds = new byte[length]; + byte[] srcGreens = new byte[length]; + byte[] srcBlues = new byte[length]; + for (int i = 0; i < rgbs.length; i++) { + RGB rgb = rgbs[i]; + if (rgb == null) continue; + srcReds[i] = (byte)rgb.red; + srcGreens[i] = (byte)rgb.green; + srcBlues[i] = (byte)rgb.blue; } - } - if (rgb != null) { - transparentPixel = rgb.red << 16 | rgb.green << 8 | rgb.blue; + ImageData.blit(ImageData.BLIT_SRC, + image.data, image.depth, image.bytesPerLine, image.getByteOrder(), 0, 0, width, height, srcReds, srcGreens, srcBlues, + ImageData.ALPHA_OPAQUE, null, 0, 0, 0, + buffer, destDepth, stride, destOrder, 0, 0, width, height, redMask, greenMask, blueMask, + false, false); } } - if (OS.USE_CAIRO_SURFACE) { + boolean isIcon = image.getTransparencyType() == SWT.TRANSPARENCY_MASK; + this.type = isIcon ? SWT.ICON : SWT.BITMAP; + if (isIcon || image.transparentPixel != -1) { + if (image.transparentPixel != -1) { + RGB rgb = null; + if (palette.isDirect) { + rgb = palette.getRGB(image.transparentPixel); + } else { + if (image.transparentPixel < palette.colors.length) { + rgb = palette.getRGB(image.transparentPixel); + } + } + if (rgb != null) { + transparentPixel = rgb.red << 16 | rgb.green << 8 | rgb.blue; + } + } ImageData mask = image.getTransparencyMask(); - int offset = 0; - for (int y = 0; y < height; y++) { + for (int y = 0, offset = 0; y < height; y++) { for (int x=0; x