[cairo-commit] cairo-java/src/jni org_freedesktop_cairo_Surface.c, 1.12, 1.13

Jeffrey Morgan commit at pdx.freedesktop.org
Tue Aug 16 17:34:35 PDT 2005


Committed by: kuzman

Update of /cvs/cairo/cairo-java/src/jni
In directory gabe:/tmp/cvs-serv19721/src/jni

Modified Files:
	org_freedesktop_cairo_Surface.c 
Log Message:
Applied a patch from Owen and updated the examples.

Index: org_freedesktop_cairo_Surface.c
===================================================================
RCS file: /cvs/cairo/cairo-java/src/jni/org_freedesktop_cairo_Surface.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- org_freedesktop_cairo_Surface.c	17 Aug 2005 00:23:44 -0000	1.12
+++ org_freedesktop_cairo_Surface.c	17 Aug 2005 00:34:31 -0000	1.13
@@ -83,6 +83,83 @@
 	return status;
 }
 
+typedef struct
+{
+	JNIEnv *env;
+	jobject ostream;
+	jmethodID methodID;
+} write_to_png_closure_t;
+
+static cairo_status_t
+write_to_png_func (void                *closure,
+		   const unsigned char *data,
+		   unsigned int         length)
+{
+	write_to_png_closure_t *png_closure = closure;
+	JNIEnv *env = png_closure->env;
+	jbyte *bytes;
+	jboolean isCopy;
+	cairo_status_t status = CAIRO_STATUS_SUCCESS;
+
+	jbyteArray array = (*env)->NewByteArray (env, length);
+	if (!array)
+		return CAIRO_STATUS_NO_MEMORY;
+
+	bytes = (*env)->GetByteArrayElements (env, array, &isCopy);
+	if (!bytes) {
+		status = CAIRO_STATUS_NO_MEMORY;
+		goto cleanup;
+	}
+
+	memcpy (bytes, data, length);
+
+	(*env)->ReleaseByteArrayElements(env, array, bytes, 0);
+
+	(*env)->CallVoidMethod(env,
+			       png_closure->ostream, png_closure->methodID,
+			       array);
+
+	if ((*env)->ExceptionOccurred(env))
+		status = CAIRO_STATUS_WRITE_ERROR;
+
+ cleanup:
+	/* need to explicitely Delete since we create objects in a loop
+	 * without returning control to Java/
+	 */
+	(*env)->DeleteLocalRef (env, array);
+	
+	return status;
+}
+
+/*
+ * Class:     org_freedesktop_cairo_Surface
+ * Method:    cairo_surface_write_to_png_stream
+ * Signature: (Lorg/gnu/javagnome/Handle;Ljava/io/OutputStream;)I
+ */
+JNIEXPORT jint JNICALL Java_org_freedesktop_cairo_Surface_cairo_1surface_1write_1to_1png_1stream
+  (JNIEnv *env, jclass cls, jobject obj, jobject ostream)
+{
+	cairo_surface_t *surface;
+	char *png_g;
+	cairo_status_t status;
+	write_to_png_closure_t png_closure;
+	jclass ostreamClass;
+
+	surface = (cairo_surface_t*)getPointerFromHandle(env, obj);
+	
+	png_closure.env = env;
+	png_closure.ostream = ostream;
+	
+	ostreamClass = (*env)->FindClass(env, "java/io/OutputStream");
+	if (!ostreamClass)
+		return CAIRO_STATUS_WRITE_ERROR;
+
+	png_closure.methodID = (*env)->GetMethodID(env, ostreamClass, "write", "([B)V");
+	if (!png_closure.methodID)
+		return CAIRO_STATUS_WRITE_ERROR;
+
+	return cairo_surface_write_to_png_stream(surface, write_to_png_func, &png_closure);
+}
 
 /*
  * Class:     org_freedesktop_cairo_Surface



More information about the cairo-commit mailing list