1 |
/* gdkpixbufdecoder.c |
/* gdkpixbufdecoder.c |
2 |
Copyright (C) 1999, 2003 Free Software Foundation, Inc. |
Copyright (C) 1999, 2003, 2004 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
35 |
obligated to do so. If you do not wish to do so, delete this |
obligated to do so. If you do not wish to do so, delete this |
36 |
exception statement from your version. */ |
exception statement from your version. */ |
37 |
|
|
38 |
|
#include <gdk/gdk.h> |
|
#include <gtk/gtk.h> |
|
39 |
#include <gdk-pixbuf/gdk-pixbuf.h> |
#include <gdk-pixbuf/gdk-pixbuf.h> |
40 |
#include <gdk-pixbuf/gdk-pixbuf-loader.h> |
#include <gdk-pixbuf/gdk-pixbuf-loader.h> |
41 |
|
|
42 |
#include "gtkpeer.h" |
#include <jni.h> |
43 |
|
#include "native_state.h" |
44 |
#include "gnu_java_awt_peer_gtk_GdkPixbufDecoder.h" |
#include "gnu_java_awt_peer_gtk_GdkPixbufDecoder.h" |
45 |
|
|
46 |
|
#include <string.h> |
47 |
|
#include <stdlib.h> |
48 |
|
|
49 |
struct state_table *native_pixbufdecoder_state_table; |
struct state_table *native_pixbufdecoder_state_table; |
50 |
|
|
51 |
#define NSA_PB_INIT(env, clazz) \ |
#define NSA_PB_INIT(env, clazz) \ |
60 |
#define NSA_DEL_PB_PTR(env, obj) \ |
#define NSA_DEL_PB_PTR(env, obj) \ |
61 |
remove_state_slot (env, obj, native_pixbufdecoder_state_table) |
remove_state_slot (env, obj, native_pixbufdecoder_state_table) |
62 |
|
|
63 |
|
/* Union used for type punning. */ |
64 |
|
union env_union |
65 |
|
{ |
66 |
|
void **void_env; |
67 |
|
JNIEnv **jni_env; |
68 |
|
}; |
69 |
|
|
70 |
|
static JavaVM *vm; |
71 |
|
|
72 |
jmethodID areaPreparedID; |
static jmethodID areaPreparedID; |
73 |
jmethodID areaUpdatedID; |
static jmethodID areaUpdatedID; |
74 |
|
|
75 |
static void |
static void |
76 |
area_prepared (GdkPixbufLoader *loader, |
area_prepared (GdkPixbufLoader *loader, |
77 |
jobject *decoder) |
jobject *decoder) |
78 |
{ |
{ |
79 |
|
JNIEnv *env; |
80 |
|
union env_union e; |
81 |
jint width, height; |
jint width, height; |
82 |
|
|
83 |
GdkPixbuf *pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); |
GdkPixbuf *pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); |
91 |
|
|
92 |
g_assert (decoder != NULL); |
g_assert (decoder != NULL); |
93 |
|
|
94 |
(*gdk_env)->CallVoidMethod (gdk_env, |
e.jni_env = &env; |
95 |
*decoder, |
(*vm)->GetEnv (vm, e.void_env, JNI_VERSION_1_1); |
96 |
areaPreparedID, |
(*env)->CallVoidMethod (env, |
97 |
width, height); |
*decoder, |
98 |
|
areaPreparedID, |
99 |
|
width, height); |
100 |
|
|
101 |
gdk_threads_enter (); |
gdk_threads_enter (); |
102 |
} |
} |
103 |
|
|
107 |
gint width, gint height, |
gint width, gint height, |
108 |
jobject *decoder) |
jobject *decoder) |
109 |
{ |
{ |
110 |
|
JNIEnv *env; |
111 |
|
union env_union e; |
112 |
jint stride_bytes, stride_pixels, n_channels, n_pixels; |
jint stride_bytes, stride_pixels, n_channels, n_pixels; |
113 |
int i, px; |
int i, px; |
114 |
jintArray jpixels; |
jintArray jpixels; |
131 |
n_pixels = height * stride_pixels; |
n_pixels = height * stride_pixels; |
132 |
gdk_pixels = gdk_pixbuf_get_pixels (pixbuf); |
gdk_pixels = gdk_pixbuf_get_pixels (pixbuf); |
133 |
|
|
134 |
jpixels = (*gdk_env)->NewIntArray (gdk_env, n_pixels); |
e.jni_env = &env; |
135 |
java_pixels = (*gdk_env)->GetIntArrayElements (gdk_env, jpixels, NULL); |
(*vm)->GetEnv (vm, e.void_env, JNI_VERSION_1_1); |
136 |
|
jpixels = (*env)->NewIntArray (env, n_pixels); |
137 |
|
java_pixels = (*env)->GetIntArrayElements (env, jpixels, NULL); |
138 |
|
|
139 |
memcpy (java_pixels, |
memcpy (java_pixels, |
140 |
gdk_pixels + (y * stride_bytes), |
gdk_pixels + (y * stride_bytes), |
160 |
|
|
161 |
gdk_threads_leave (); |
gdk_threads_leave (); |
162 |
|
|
163 |
(*gdk_env)->ReleaseIntArrayElements (gdk_env, jpixels, java_pixels, 0); |
(*env)->ReleaseIntArrayElements (env, jpixels, java_pixels, 0); |
164 |
(*gdk_env)->CallVoidMethod (gdk_env, |
(*env)->CallVoidMethod (env, |
165 |
*decoder, |
*decoder, |
166 |
areaUpdatedID, |
areaUpdatedID, |
167 |
(jint) x, (jint) y, |
(jint) x, (jint) y, |
168 |
(jint) width, (jint) height, |
(jint) width, (jint) height, |
169 |
jpixels, |
jpixels, |
170 |
stride_pixels); |
stride_pixels); |
171 |
gdk_threads_enter (); |
gdk_threads_enter (); |
172 |
} |
} |
173 |
|
|
174 |
static void |
static void |
175 |
closed (GdkPixbufLoader *loader __attribute__((unused)), jobject *decoder) |
closed (GdkPixbufLoader *loader __attribute__((unused)), jobject *decoder) |
176 |
{ |
{ |
177 |
|
JNIEnv *env; |
178 |
|
union env_union e; |
179 |
|
e.jni_env = &env; |
180 |
|
(*vm)->GetEnv (vm, e.void_env, JNI_VERSION_1_1); |
181 |
|
|
182 |
gdk_threads_leave (); |
gdk_threads_leave (); |
183 |
(*gdk_env)->DeleteGlobalRef (gdk_env, *decoder); |
(*env)->DeleteGlobalRef (env, *decoder); |
184 |
free (decoder); |
free (decoder); |
185 |
gdk_threads_enter (); |
gdk_threads_enter (); |
186 |
} |
} |
211 |
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_initStaticState |
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_initStaticState |
212 |
(JNIEnv *env, jclass clazz) |
(JNIEnv *env, jclass clazz) |
213 |
{ |
{ |
214 |
|
(*env)->GetJavaVM(env, &vm); |
215 |
|
|
216 |
areaPreparedID = (*env)->GetMethodID (env, clazz, |
areaPreparedID = (*env)->GetMethodID (env, clazz, |
217 |
"areaPrepared", |
"areaPrepared", |
218 |
"(II)V"); |
"(II)V"); |
249 |
if (len < 1) |
if (len < 1) |
250 |
return; |
return; |
251 |
|
|
252 |
bytes = (*gdk_env)->GetByteArrayElements (gdk_env, jarr, NULL); |
bytes = (*env)->GetByteArrayElements (env, jarr, NULL); |
253 |
g_assert (bytes != NULL); |
g_assert (bytes != NULL); |
254 |
loader = (GdkPixbufLoader *)NSA_GET_PB_PTR (env, obj); |
loader = (GdkPixbufLoader *)NSA_GET_PB_PTR (env, obj); |
255 |
g_assert (loader != NULL); |
g_assert (loader != NULL); |
256 |
|
|
257 |
gdk_threads_enter (); |
gdk_threads_enter (); |
258 |
gdk_pixbuf_loader_write (loader, bytes, len, NULL); |
gdk_pixbuf_loader_write (loader, (const guchar *) bytes, len, NULL); |
259 |
gdk_threads_leave (); |
gdk_threads_leave (); |
260 |
|
|
261 |
(*gdk_env)->ReleaseByteArrayElements (gdk_env, jarr, bytes, 0); |
(*env)->ReleaseByteArrayElements (env, jarr, bytes, 0); |
262 |
} |
} |