97 |
NSA_SET_PTR (env, obj, g); |
NSA_SET_PTR (env, obj, g); |
98 |
} |
} |
99 |
|
|
100 |
|
JNIEXPORT void JNICALL |
101 |
|
Java_gnu_java_awt_peer_gtk_GdkGraphics_initFromImage |
102 |
|
(JNIEnv *env, jobject obj, jobject source) |
103 |
|
{ |
104 |
|
struct graphics *g; |
105 |
|
GdkPixmap *pixmap = |
106 |
|
gnu_java_awt_peer_gtk_GtkImage_getPixmap(env, source); |
107 |
|
g_assert(pixmap != NULL); |
108 |
|
gdk_pixmap_ref (pixmap); |
109 |
|
|
110 |
|
g = (struct graphics *) malloc (sizeof (struct graphics)); |
111 |
|
g->x_offset = g->y_offset = 0; |
112 |
|
|
113 |
|
gdk_threads_enter (); |
114 |
|
|
115 |
|
g->drawable = (GdkDrawable *)pixmap; |
116 |
|
|
117 |
|
g->cm = gdk_drawable_get_colormap (g->drawable); |
118 |
|
gdk_colormap_ref (g->cm); |
119 |
|
g->gc = gdk_gc_new (g->drawable); |
120 |
|
|
121 |
|
gdk_threads_leave (); |
122 |
|
|
123 |
|
NSA_SET_PTR (env, obj, g); |
124 |
|
} |
125 |
|
|
126 |
/* copy the native state of the peer (GtkWidget *) to the native state |
/* copy the native state of the peer (GtkWidget *) to the native state |
127 |
of the graphics object */ |
of the graphics object */ |
128 |
JNIEXPORT void JNICALL |
JNIEXPORT void JNICALL |
327 |
} |
} |
328 |
|
|
329 |
JNIEXPORT void JNICALL |
JNIEXPORT void JNICALL |
|
Java_gnu_java_awt_peer_gtk_GdkGraphics_copyPixmap |
|
|
(JNIEnv *env, jobject obj, jobject offscreen, |
|
|
jint x, jint y, jint width, jint height) |
|
|
{ |
|
|
struct graphics *g1, *g2; |
|
|
|
|
|
g1 = (struct graphics *) NSA_GET_PTR (env, obj); |
|
|
g2 = (struct graphics *) NSA_GET_PTR (env, offscreen); |
|
|
|
|
|
gdk_threads_enter (); |
|
|
gdk_window_copy_area ((GdkWindow *)g1->drawable, |
|
|
g1->gc, |
|
|
x + g1->x_offset, y + g1->y_offset, |
|
|
(GdkWindow *)g2->drawable, |
|
|
0 + g2->x_offset, 0 + g2->y_offset, |
|
|
width, height); |
|
|
gdk_flush (); |
|
|
gdk_threads_leave (); |
|
|
} |
|
|
|
|
|
static void flip_pixbuf (GdkPixbuf *pixbuf, |
|
|
jboolean flip_x, |
|
|
jboolean flip_y, |
|
|
jint width, |
|
|
jint height) |
|
|
{ |
|
|
gint src_rs; |
|
|
guchar *src_pix; |
|
|
|
|
|
src_rs = gdk_pixbuf_get_rowstride (pixbuf); |
|
|
src_pix = gdk_pixbuf_get_pixels (pixbuf); |
|
|
|
|
|
if (flip_x) |
|
|
{ |
|
|
gint i, channels; |
|
|
guchar buf[4]; |
|
|
|
|
|
channels = gdk_pixbuf_get_has_alpha (pixbuf) ? 4 : 3; |
|
|
|
|
|
for (i = 0; i < height; i++) |
|
|
{ |
|
|
guchar *left = src_pix + i * src_rs; |
|
|
guchar *right = left + channels * (width - 1); |
|
|
while (left < right) |
|
|
{ |
|
|
g_memmove (buf, left, channels); |
|
|
g_memmove (left, right, channels); |
|
|
g_memmove (right, buf, channels); |
|
|
left += channels; |
|
|
right -= channels; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
if (flip_y) |
|
|
{ |
|
|
guchar *top = src_pix; |
|
|
guchar *bottom = top + (height - 1) * src_rs; |
|
|
gpointer buf = g_malloc (src_rs); |
|
|
|
|
|
while (top < bottom) |
|
|
{ |
|
|
g_memmove (buf, top, src_rs); |
|
|
g_memmove (top, bottom, src_rs); |
|
|
g_memmove (bottom, buf, src_rs); |
|
|
top += src_rs; |
|
|
bottom -= src_rs; |
|
|
} |
|
|
|
|
|
g_free (buf); |
|
|
} |
|
|
} |
|
|
|
|
|
JNIEXPORT void JNICALL |
|
|
Java_gnu_java_awt_peer_gtk_GdkGraphics_copyAndScalePixmap |
|
|
(JNIEnv *env, jobject obj, jobject offscreen, jboolean flip_x, jboolean flip_y, |
|
|
jint src_x, jint src_y, jint src_width, jint src_height, |
|
|
jint dest_x, jint dest_y, jint dest_width, jint dest_height) |
|
|
{ |
|
|
struct graphics *g1, *g2; |
|
|
GdkPixbuf *buf_src, *buf_dest; |
|
|
|
|
|
g1 = (struct graphics *) NSA_GET_PTR (env, obj); |
|
|
g2 = (struct graphics *) NSA_GET_PTR (env, offscreen); |
|
|
|
|
|
gdk_threads_enter (); |
|
|
|
|
|
buf_src = gdk_pixbuf_get_from_drawable (NULL, |
|
|
g2->drawable, |
|
|
g2->cm, |
|
|
src_x, |
|
|
src_y, |
|
|
0, |
|
|
0, |
|
|
src_width, |
|
|
src_height); |
|
|
|
|
|
buf_dest = gdk_pixbuf_scale_simple (buf_src, |
|
|
dest_width, |
|
|
dest_height, |
|
|
GDK_INTERP_BILINEAR); |
|
|
|
|
|
if (flip_x || flip_y) |
|
|
{ |
|
|
flip_pixbuf (buf_dest, flip_x, flip_y, dest_width, dest_height); |
|
|
} |
|
|
|
|
|
gdk_pixbuf_render_to_drawable (buf_dest, |
|
|
g1->drawable, |
|
|
g1->gc, |
|
|
0, |
|
|
0, |
|
|
dest_x, |
|
|
dest_y, |
|
|
dest_width, |
|
|
dest_height, |
|
|
GDK_RGB_DITHER_NORMAL, |
|
|
0, |
|
|
0); |
|
|
|
|
|
g_object_unref (G_OBJECT (buf_src)); |
|
|
g_object_unref (G_OBJECT (buf_dest)); |
|
|
|
|
|
gdk_threads_leave (); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL |
|
330 |
Java_gnu_java_awt_peer_gtk_GdkGraphics_clearRect |
Java_gnu_java_awt_peer_gtk_GdkGraphics_clearRect |
331 |
(JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height) |
(JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height) |
332 |
{ |
{ |