diff options
author | Silenio Quarti <Silenio_Quarti@ca.ibm.com> | 2011-10-19 10:07:17 -0400 |
---|---|---|
committer | Silenio Quarti <Silenio_Quarti@ca.ibm.com> | 2011-10-19 10:13:37 -0400 |
commit | a3b02a04a381231f9082de077a6f17f8af5d2dad (patch) | |
tree | ddec64c5d38983933ab813feb8a2d9ba1c1907a3 | |
parent | 641df66d77688c7d9893fc22d380993faf531414 (diff) | |
download | eclipse.platform.swt-a3b02a04a381231f9082de077a6f17f8af5d2dad.tar.gz eclipse.platform.swt-a3b02a04a381231f9082de077a6f17f8af5d2dad.tar.xz eclipse.platform.swt-a3b02a04a381231f9082de077a6f17f8af5d2dad.zip |
shared copies of Display.createPixbuf
shared copies of Display.createPixbuf
10 files changed, 258 insertions, 368 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/DragSource.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/DragSource.java index 3874254e25..b9d52f63f6 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/DragSource.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/DragSource.java @@ -299,7 +299,7 @@ void drag(Event dragEvent) { Image image = event.image; int /*long*/ context = OS.gtk_drag_begin(control.handle, targetList, actions, 1, 0); if (context != 0 && image != null) { - int /*long*/ pixbuf = createPixbuf(image); + int /*long*/ pixbuf = ImageList.createPixbuf(image); OS.gtk_drag_set_icon_pixbuf(context, pixbuf, 0, 0); OS.g_object_unref(pixbuf); } @@ -574,60 +574,4 @@ public void setTransfer(Transfer[] transferAgents){ OS.g_free(targets[i].target); } } - -static int /*long*/ createPixbuf(Image image) { - int [] w = new int [1], h = new int [1]; - OS.gdk_drawable_get_size (image.pixmap, w, h); - int /*long*/ colormap = OS.gdk_colormap_get_system (); - int /*long*/ pixbuf; - boolean hasMask = image.mask != 0 && OS.gdk_drawable_get_depth (image.mask) == 1; - if (hasMask) { - pixbuf = OS.gdk_pixbuf_new (OS.GDK_COLORSPACE_RGB, true, 8, w [0], h [0]); - if (pixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES); - OS.gdk_pixbuf_get_from_drawable (pixbuf, image.pixmap, colormap, 0, 0, 0, 0, w [0], h [0]); - int /*long*/ maskPixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, w [0], h [0]); - if (maskPixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES); - OS.gdk_pixbuf_get_from_drawable(maskPixbuf, image.mask, 0, 0, 0, 0, 0, w [0], h [0]); - int stride = OS.gdk_pixbuf_get_rowstride(pixbuf); - int /*long*/ pixels = OS.gdk_pixbuf_get_pixels(pixbuf); - byte[] line = new byte[stride]; - int maskStride = OS.gdk_pixbuf_get_rowstride(maskPixbuf); - int /*long*/ maskPixels = OS.gdk_pixbuf_get_pixels(maskPixbuf); - byte[] maskLine = new byte[maskStride]; - for (int y=0; y<h[0]; y++) { - int /*long*/ offset = pixels + (y * stride); - OS.memmove(line, offset, stride); - int /*long*/ maskOffset = maskPixels + (y * maskStride); - OS.memmove(maskLine, maskOffset, maskStride); - for (int x=0; x<w[0]; x++) { - if (maskLine[x * 3] == 0) { - line[x * 4 + 3] = 0; - } - } - OS.memmove(offset, line, stride); - } - OS.g_object_unref(maskPixbuf); - } else { - ImageData data = image.getImageData (); - boolean hasAlpha = data.getTransparencyType () == SWT.TRANSPARENCY_ALPHA; - pixbuf = OS.gdk_pixbuf_new (OS.GDK_COLORSPACE_RGB, hasAlpha, 8, w [0], h [0]); - if (pixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES); - OS.gdk_pixbuf_get_from_drawable (pixbuf, image.pixmap, colormap, 0, 0, 0, 0, w [0], h [0]); - if (hasAlpha) { - byte [] alpha = data.alphaData; - int stride = OS.gdk_pixbuf_get_rowstride (pixbuf); - int /*long*/ pixels = OS.gdk_pixbuf_get_pixels (pixbuf); - byte [] line = new byte [stride]; - for (int y = 0; y < h [0]; y++) { - int /*long*/ offset = pixels + (y * stride); - OS.memmove (line, offset, stride); - for (int x = 0; x < w [0]; x++) { - line [x*4+3] = alpha [y*w [0]+x]; - } - OS.memmove (offset, line, stride); - } - } - } - return pixbuf; -} } diff --git a/bundles/org.eclipse.swt/Eclipse SWT Theme/gtk/org/eclipse/swt/internal/theme/DrawData.java b/bundles/org.eclipse.swt/Eclipse SWT Theme/gtk/org/eclipse/swt/internal/theme/DrawData.java index f4492b5fa6..9f52da3864 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Theme/gtk/org/eclipse/swt/internal/theme/DrawData.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Theme/gtk/org/eclipse/swt/internal/theme/DrawData.java @@ -85,7 +85,7 @@ void drawImage(Theme theme, Image image, GC gc, Rectangle bounds) { if (state_type == OS.GTK_STATE_NORMAL) { gc.drawImage(image, 0, 0, rect.width, rect.height, bounds.x, bounds.y, bounds.width, bounds.height); } else { - int /*long*/ pixbuf = Theme.createPixbuf(image); + int /*long*/ pixbuf = ImageList.createPixbuf(image); int /*long*/ source = OS.gtk_icon_source_new(); if (source != 0) { OS.gtk_icon_source_set_pixbuf(source, pixbuf); diff --git a/bundles/org.eclipse.swt/Eclipse SWT Theme/gtk/org/eclipse/swt/internal/theme/Theme.java b/bundles/org.eclipse.swt/Eclipse SWT Theme/gtk/org/eclipse/swt/internal/theme/Theme.java index 72d817538e..7cca3a9a30 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Theme/gtk/org/eclipse/swt/internal/theme/Theme.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Theme/gtk/org/eclipse/swt/internal/theme/Theme.java @@ -67,63 +67,6 @@ public Theme(Device device) { OS.gtk_widget_realize (shellHandle); } -//TODO - share this code -static int /*long*/ createPixbuf(Image image) { - int [] w = new int [1], h = new int [1]; - OS.gdk_drawable_get_size (image.pixmap, w, h); - int /*long*/ colormap = OS.gdk_colormap_get_system (); - int /*long*/ pixbuf; - boolean hasMask = image.mask != 0 && OS.gdk_drawable_get_depth (image.mask) == 1; - if (hasMask) { - pixbuf = OS.gdk_pixbuf_new (OS.GDK_COLORSPACE_RGB, true, 8, w [0], h [0]); - if (pixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES); - OS.gdk_pixbuf_get_from_drawable (pixbuf, image.pixmap, colormap, 0, 0, 0, 0, w [0], h [0]); - int /*long*/ maskPixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, w [0], h [0]); - if (maskPixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES); - OS.gdk_pixbuf_get_from_drawable(maskPixbuf, image.mask, 0, 0, 0, 0, 0, w [0], h [0]); - int stride = OS.gdk_pixbuf_get_rowstride(pixbuf); - int /*long*/ pixels = OS.gdk_pixbuf_get_pixels(pixbuf); - byte[] line = new byte[stride]; - int maskStride = OS.gdk_pixbuf_get_rowstride(maskPixbuf); - int /*long*/ maskPixels = OS.gdk_pixbuf_get_pixels(maskPixbuf); - byte[] maskLine = new byte[maskStride]; - for (int y=0; y<h[0]; y++) { - int /*long*/ offset = pixels + (y * stride); - OS.memmove(line, offset, stride); - int /*long*/ maskOffset = maskPixels + (y * maskStride); - OS.memmove(maskLine, maskOffset, maskStride); - for (int x=0; x<w[0]; x++) { - if (maskLine[x * 3] == 0) { - line[x * 4 + 3] = 0; - } - } - OS.memmove(offset, line, stride); - } - OS.g_object_unref(maskPixbuf); - } else { - ImageData data = image.getImageData (); - boolean hasAlpha = data.getTransparencyType () == SWT.TRANSPARENCY_ALPHA; - pixbuf = OS.gdk_pixbuf_new (OS.GDK_COLORSPACE_RGB, hasAlpha, 8, w [0], h [0]); - if (pixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES); - OS.gdk_pixbuf_get_from_drawable (pixbuf, image.pixmap, colormap, 0, 0, 0, 0, w [0], h [0]); - if (hasAlpha) { - byte [] alpha = data.alphaData; - int stride = OS.gdk_pixbuf_get_rowstride (pixbuf); - int /*long*/ pixels = OS.gdk_pixbuf_get_pixels (pixbuf); - byte [] line = new byte [stride]; - for (int y = 0; y < h [0]; y++) { - int /*long*/ offset = pixels + (y * stride); - OS.memmove (line, offset, stride); - for (int x = 0; x < w [0]; x++) { - line [x*4+3] = alpha [y*w [0]+x]; - } - OS.memmove (offset, line, stride); - } - } - } - return pixbuf; -} - void checkTheme() { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/ImageList.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/ImageList.java new file mode 100644 index 0000000000..7890307512 --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/ImageList.java @@ -0,0 +1,249 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.internal; + + +import org.eclipse.swt.SWT; +import org.eclipse.swt.internal.gtk.*; +import org.eclipse.swt.graphics.*; + +public class ImageList { + int /*long*/ [] pixbufs; + int width = -1, height = -1; + Image [] images; + +public ImageList() { + images = new Image [4]; + pixbufs = new int /*long*/ [4]; +} + +public static int /*long*/ createPixbuf(Image image) { + int /*long*/ pixbuf; + if (OS.USE_CAIRO_SURFACE) { + Rectangle bounds = image.getBounds(); + int w = bounds.width, h = bounds.height; + pixbuf = OS.gdk_pixbuf_new (OS.GDK_COLORSPACE_RGB, true, 8, w, h); + if (pixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES); + int stride = OS.gdk_pixbuf_get_rowstride (pixbuf); + int /*long*/ pixels = OS.gdk_pixbuf_get_pixels (pixbuf); + byte[] line = new byte[stride]; + int /*long*/ ptr = OS.malloc(4); + OS.memmove(ptr, new int[]{1}, 4); + OS.memmove(line, ptr, 1); + OS.free(ptr); + int oa, or, og, ob; + boolean bigendian = line[0] == 0; + if (bigendian) { + oa = 0; or = 1; og = 2; ob = 3; + } else { + oa = 3; or = 2; og = 1; ob = 0; + } + int /*long*/ surfaceData = image.surfaceData; + for (int y = 0; y < h; y++) { + OS.memmove (line, surfaceData + (y * stride), stride); + for (int x = 0, offset = 0; x < w; x++, offset += 4) { + int a = line[offset + oa] & 0xFF; + int r = line[offset + or] & 0xFF; + int g = line[offset + og] & 0xFF; + int b = line[offset + ob] & 0xFF; + line[offset + 3] = (byte)a; + if (a != 0) { + line[offset + 0] = (byte)(((r) / (float)a) * 0xFF); + line[offset + 1] = (byte)(((g) / (float)a) * 0xFF); + line[offset + 2] = (byte)(((b) / (float)a) * 0xFF); + } + } + OS.memmove (pixels + (y * stride), line, stride); + } + } else { + int [] w = new int [1], h = new int [1]; + OS.gdk_drawable_get_size (image.pixmap, w, h); + int /*long*/ colormap = OS.gdk_colormap_get_system (); + boolean hasMask = image.mask != 0 && OS.gdk_drawable_get_depth (image.mask) == 1; + if (hasMask) { + pixbuf = OS.gdk_pixbuf_new (OS.GDK_COLORSPACE_RGB, true, 8, w [0], h [0]); + if (pixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES); + OS.gdk_pixbuf_get_from_drawable (pixbuf, image.pixmap, colormap, 0, 0, 0, 0, w [0], h [0]); + int /*long*/ maskPixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, w [0], h [0]); + if (maskPixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES); + OS.gdk_pixbuf_get_from_drawable(maskPixbuf, image.mask, 0, 0, 0, 0, 0, w [0], h [0]); + int stride = OS.gdk_pixbuf_get_rowstride(pixbuf); + int /*long*/ pixels = OS.gdk_pixbuf_get_pixels(pixbuf); + byte[] line = new byte[stride]; + int maskStride = OS.gdk_pixbuf_get_rowstride(maskPixbuf); + int /*long*/ maskPixels = OS.gdk_pixbuf_get_pixels(maskPixbuf); + byte[] maskLine = new byte[maskStride]; + for (int y=0; y<h[0]; y++) { + int /*long*/ offset = pixels + (y * stride); + OS.memmove(line, offset, stride); + int /*long*/ maskOffset = maskPixels + (y * maskStride); + OS.memmove(maskLine, maskOffset, maskStride); + for (int x=0; x<w[0]; x++) { + if (maskLine[x * 3] == 0) { + line[x * 4 + 3] = 0; + } + } + OS.memmove(offset, line, stride); + } + OS.g_object_unref(maskPixbuf); + } else { + ImageData data = image.getImageData (); + boolean hasAlpha = data.getTransparencyType () == SWT.TRANSPARENCY_ALPHA; + pixbuf = OS.gdk_pixbuf_new (OS.GDK_COLORSPACE_RGB, hasAlpha, 8, w [0], h [0]); + if (pixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES); + OS.gdk_pixbuf_get_from_drawable (pixbuf, image.pixmap, colormap, 0, 0, 0, 0, w [0], h [0]); + if (hasAlpha) { + byte [] alpha = data.alphaData; + int stride = OS.gdk_pixbuf_get_rowstride (pixbuf); + int /*long*/ pixels = OS.gdk_pixbuf_get_pixels (pixbuf); + byte [] line = new byte [stride]; + for (int y = 0; y < h [0]; y++) { + int /*long*/ offset = pixels + (y * stride); + OS.memmove (line, offset, stride); + for (int x = 0; x < w [0]; x++) { + line [x*4+3] = alpha [y*w [0]+x]; + } + OS.memmove (offset, line, stride); + } + } + } + } + return pixbuf; +} + +public int add (Image image) { + int index = 0; + while (index < images.length) { + if (images [index] != null) { + if (images [index].isDisposed ()) { + OS.g_object_unref (pixbufs [index]); + images [index] = null; + pixbufs [index] = 0; + } + } + if (images [index] == null) break; + index++; + } + if (index == images.length) { + Image [] newImages = new Image [images.length + 4]; + System.arraycopy (images, 0, newImages, 0, images.length); + images = newImages; + int /*long*/ [] newPixbufs = new int /*long*/ [pixbufs.length + 4]; + System.arraycopy (pixbufs, 0, newPixbufs, 0, pixbufs.length); + pixbufs = newPixbufs; + } + set (index, image); + return index; +} + +public void dispose () { + if (pixbufs == null) return; + for (int index=0; index<pixbufs.length; index++) { + if (pixbufs [index] != 0) OS.g_object_unref (pixbufs [index]); + } + images = null; + pixbufs = null; +} + +public Image get (int index) { + return images [index]; +} + +public int /*long*/ getPixbuf (int index) { + return pixbufs [index]; +} + +public int indexOf (Image image) { + if (image == null) return -1; + for (int index=0; index<images.length; index++) { + if (image == images [index]) return index; + } + return -1; +} + +public int indexOf (int /*long*/ pixbuf) { + if (pixbuf == 0) return -1; + for (int index=0; index<images.length; index++) { + if (pixbuf == pixbufs [index]) return index; + } + return -1; +} + +public boolean isDisposed () { + return images == null; +} + +public void put (int index, Image image) { + int count = images.length; + if (!(0 <= index && index < count)) return; + if (image != null) { + set (index, image); + } else { + images [index] = null; + if (pixbufs [index] != 0) OS.g_object_unref (pixbufs [index]); + pixbufs [index] = 0; + } +} + +public void remove (Image image) { + if (image == null) return; + for (int index=0; index<images.length; index++) { + if (image == images [index]){ + OS.g_object_unref (pixbufs [index]); + images [index] = null; + pixbufs [index] = 0; + } + } +} + +void set (int index, Image image) { + int /*long*/ pixbuf = createPixbuf (image); + int w = OS.gdk_pixbuf_get_width(pixbuf); + int h = OS.gdk_pixbuf_get_height(pixbuf); + if (width == -1 || height == -1) { + width = w; + height = h; + } + if (w != width || h != height) { + int /*long*/ scaledPixbuf = OS.gdk_pixbuf_scale_simple(pixbuf, width, height, OS.GDK_INTERP_BILINEAR); + OS.g_object_unref (pixbuf); + pixbuf = scaledPixbuf; + } + int /*long*/ oldPixbuf = pixbufs [index]; + if (oldPixbuf != 0) { + if (images [index] == image) { + OS.gdk_pixbuf_copy_area (pixbuf, 0, 0, width, height, oldPixbuf, 0, 0); + OS.g_object_unref (pixbuf); + pixbuf = oldPixbuf; + } else { + OS.g_object_unref (oldPixbuf); + } + } + pixbufs [index] = pixbuf; + images [index] = image; +} + +public int size () { + int result = 0; + for (int index=0; index<images.length; index++) { + if (images [index] != null) { + if (images [index].isDisposed ()) { + OS.g_object_unref (pixbufs [index]); + images [index] = null; + pixbufs [index] = 0; + } + if (images [index] != null) result++; + } + } + return result; +} + +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java index 97f3422fba..19fa5cfde1 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java @@ -11,6 +11,7 @@ package org.eclipse.swt.widgets; import org.eclipse.swt.*; +import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.gtk.*; import org.eclipse.swt.graphics.*; @@ -175,7 +176,7 @@ void _setImages (Image [] images) { if (images != null) { for (int i = 0; i < images.length; i++) { Image image = images [i]; - int /*long*/ pixbuf = Display.createPixbuf (image); + int /*long*/ pixbuf = ImageList.createPixbuf (image); pixbufs = OS.g_list_append (pixbufs, pixbuf); } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java index 094e3a9718..7385f7e81a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java @@ -1058,100 +1058,6 @@ Image createImage (String name) { return new Image (this, imageData); } -static int /*long*/ createPixbuf(Image image) { - int /*long*/ pixbuf; - if (OS.USE_CAIRO_SURFACE) { - Rectangle bounds = image.getBounds(); - int w = bounds.width, h = bounds.height; - pixbuf = OS.gdk_pixbuf_new (OS.GDK_COLORSPACE_RGB, true, 8, w, h); - if (pixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES); - int stride = OS.gdk_pixbuf_get_rowstride (pixbuf); - int /*long*/ pixels = OS.gdk_pixbuf_get_pixels (pixbuf); - byte[] line = new byte[stride]; - int /*long*/ ptr = OS.malloc(4); - OS.memmove(ptr, new int[]{1}, 4); - OS.memmove(line, ptr, 1); - OS.free(ptr); - int oa, or, og, ob; - boolean bigendian = line[0] == 0; - if (bigendian) { - oa = 0; or = 1; og = 2; ob = 3; - } else { - oa = 3; or = 2; og = 1; ob = 0; - } - int /*long*/ surfaceData = image.surfaceData; - for (int y = 0; y < h; y++) { - OS.memmove (line, surfaceData + (y * stride), stride); - for (int x = 0, offset = 0; x < w; x++, offset += 4) { - int a = line[offset + oa] & 0xFF; - int r = line[offset + or] & 0xFF; - int g = line[offset + og] & 0xFF; - int b = line[offset + ob] & 0xFF; - line[offset + 3] = (byte)a; - if (a != 0) { - line[offset + 0] = (byte)(((r) / (float)a) * 0xFF); - line[offset + 1] = (byte)(((g) / (float)a) * 0xFF); - line[offset + 2] = (byte)(((b) / (float)a) * 0xFF); - } - } - OS.memmove (pixels + (y * stride), line, stride); - } - } else { - int [] w = new int [1], h = new int [1]; - OS.gdk_drawable_get_size (image.pixmap, w, h); - int /*long*/ colormap = OS.gdk_colormap_get_system (); - boolean hasMask = image.mask != 0 && OS.gdk_drawable_get_depth (image.mask) == 1; - if (hasMask) { - pixbuf = OS.gdk_pixbuf_new (OS.GDK_COLORSPACE_RGB, true, 8, w [0], h [0]); - if (pixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES); - OS.gdk_pixbuf_get_from_drawable (pixbuf, image.pixmap, colormap, 0, 0, 0, 0, w [0], h [0]); - int /*long*/ maskPixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, w [0], h [0]); - if (maskPixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES); - OS.gdk_pixbuf_get_from_drawable(maskPixbuf, image.mask, 0, 0, 0, 0, 0, w [0], h [0]); - int stride = OS.gdk_pixbuf_get_rowstride(pixbuf); - int /*long*/ pixels = OS.gdk_pixbuf_get_pixels(pixbuf); - byte[] line = new byte[stride]; - int maskStride = OS.gdk_pixbuf_get_rowstride(maskPixbuf); - int /*long*/ maskPixels = OS.gdk_pixbuf_get_pixels(maskPixbuf); - byte[] maskLine = new byte[maskStride]; - for (int y=0; y<h[0]; y++) { - int /*long*/ offset = pixels + (y * stride); - OS.memmove(line, offset, stride); - int /*long*/ maskOffset = maskPixels + (y * maskStride); - OS.memmove(maskLine, maskOffset, maskStride); - for (int x=0; x<w[0]; x++) { - if (maskLine[x * 3] == 0) { - line[x * 4 + 3] = 0; - } - } - OS.memmove(offset, line, stride); - } - OS.g_object_unref(maskPixbuf); - } else { - ImageData data = image.getImageData (); - boolean hasAlpha = data.getTransparencyType () == SWT.TRANSPARENCY_ALPHA; - pixbuf = OS.gdk_pixbuf_new (OS.GDK_COLORSPACE_RGB, hasAlpha, 8, w [0], h [0]); - if (pixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES); - OS.gdk_pixbuf_get_from_drawable (pixbuf, image.pixmap, colormap, 0, 0, 0, 0, w [0], h [0]); - if (hasAlpha) { - byte [] alpha = data.alphaData; - int stride = OS.gdk_pixbuf_get_rowstride (pixbuf); - int /*long*/ pixels = OS.gdk_pixbuf_get_pixels (pixbuf); - byte [] line = new byte [stride]; - for (int y = 0; y < h [0]; y++) { - int /*long*/ offset = pixels + (y * stride); - OS.memmove (line, offset, stride); - for (int x = 0; x < w [0]; x++) { - line [x*4+3] = alpha [y*w [0]+x]; - } - OS.memmove (offset, line, stride); - } - } - } - } - return pixbuf; -} - static void deregister (Display display) { synchronized (Device.class) { for (int i=0; i<Displays.length; i++) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ImageList.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ImageList.java deleted file mode 100644 index f7a098e53e..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ImageList.java +++ /dev/null @@ -1,154 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.graphics.*; - -class ImageList { - int /*long*/ [] pixbufs; - int width = -1, height = -1; - Image [] images; - -public ImageList() { - images = new Image [4]; - pixbufs = new int /*long*/ [4]; -} - -public int add (Image image) { - int index = 0; - while (index < images.length) { - if (images [index] != null) { - if (images [index].isDisposed ()) { - OS.g_object_unref (pixbufs [index]); - images [index] = null; - pixbufs [index] = 0; - } - } - if (images [index] == null) break; - index++; - } - if (index == images.length) { - Image [] newImages = new Image [images.length + 4]; - System.arraycopy (images, 0, newImages, 0, images.length); - images = newImages; - int /*long*/ [] newPixbufs = new int /*long*/ [pixbufs.length + 4]; - System.arraycopy (pixbufs, 0, newPixbufs, 0, pixbufs.length); - pixbufs = newPixbufs; - } - set (index, image); - return index; -} - -public void dispose () { - if (pixbufs == null) return; - for (int index=0; index<pixbufs.length; index++) { - if (pixbufs [index] != 0) OS.g_object_unref (pixbufs [index]); - } - images = null; - pixbufs = null; -} - -public Image get (int index) { - return images [index]; -} - -int /*long*/ getPixbuf (int index) { - return pixbufs [index]; -} - -public int indexOf (Image image) { - if (image == null) return -1; - for (int index=0; index<images.length; index++) { - if (image == images [index]) return index; - } - return -1; -} - -int indexOf (int /*long*/ pixbuf) { - if (pixbuf == 0) return -1; - for (int index=0; index<images.length; index++) { - if (pixbuf == pixbufs [index]) return index; - } - return -1; -} - -public boolean isDisposed () { - return images == null; -} - -public void put (int index, Image image) { - int count = images.length; - if (!(0 <= index && index < count)) return; - if (image != null) { - set (index, image); - } else { - images [index] = null; - if (pixbufs [index] != 0) OS.g_object_unref (pixbufs [index]); - pixbufs [index] = 0; - } -} - -public void remove (Image image) { - if (image == null) return; - for (int index=0; index<images.length; index++) { - if (image == images [index]){ - OS.g_object_unref (pixbufs [index]); - images [index] = null; - pixbufs [index] = 0; - } - } -} - -void set (int index, Image image) { - int /*long*/ pixbuf = Display.createPixbuf (image); - int w = OS.gdk_pixbuf_get_width(pixbuf); - int h = OS.gdk_pixbuf_get_height(pixbuf); - if (width == -1 || height == -1) { - width = w; - height = h; - } - if (w != width || h != height) { - int /*long*/ scaledPixbuf = OS.gdk_pixbuf_scale_simple(pixbuf, width, height, OS.GDK_INTERP_BILINEAR); - OS.g_object_unref (pixbuf); - pixbuf = scaledPixbuf; - } - int /*long*/ oldPixbuf = pixbufs [index]; - if (oldPixbuf != 0) { - if (images [index] == image) { - OS.gdk_pixbuf_copy_area (pixbuf, 0, 0, width, height, oldPixbuf, 0, 0); - OS.g_object_unref (pixbuf); - pixbuf = oldPixbuf; - } else { - OS.g_object_unref (oldPixbuf); - } - } - pixbufs [index] = pixbuf; - images [index] = image; -} - -public int size () { - int result = 0; - for (int index=0; index<images.length; index++) { - if (images [index] != null) { - if (images [index].isDisposed ()) { - OS.g_object_unref (pixbufs [index]); - images [index] = null; - pixbufs [index] = 0; - } - if (images [index] != null) result++; - } - } - return result; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java index e09761c847..7302454dc9 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java @@ -12,6 +12,7 @@ package org.eclipse.swt.widgets; import org.eclipse.swt.*; +import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.gtk.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.events.*; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java index 771173ef41..cd3f6ee6d8 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java @@ -212,8 +212,8 @@ int /*long*/ cellDataProc (int /*long*/ tree_column, int /*long*/ cell, int /*lo /* Give an image from the image list to make sure the row has * the correct height. */ - if (imageList != null && imageList.pixbufs.length > 0) { - if (isPixbuf) OS.g_object_set (cell, OS.pixbuf, imageList.pixbufs [0], 0); + if (imageList != null && imageList.size () > 0) { + if (isPixbuf) OS.g_object_set (cell, OS.pixbuf, imageList.getPixbuf (0), 0); } return 0; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java index 513622771a..eb1bc40ad7 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java @@ -257,8 +257,8 @@ int /*long*/ cellDataProc (int /*long*/ tree_column, int /*long*/ cell, int /*lo /* Give an image from the image list to make sure the row has * the correct height. */ - if (imageList != null && imageList.pixbufs.length > 0) { - if (isPixbuf) OS.g_object_set (cell, OS.pixbuf, imageList.pixbufs [0], 0); + if (imageList != null && imageList.size () > 0) { + if (isPixbuf) OS.g_object_set (cell, OS.pixbuf, imageList.getPixbuf (0), 0); } return 0; } |