[cairo-commit] CairoJava/jni CairoImageBuffer.cpp,1.1,1.2

Soorya Kuloor commit at pdx.freedesktop.org
Thu May 13 09:44:47 PDT 2004


Committed by: skuloor

Update of /cvs/cairo/CairoJava/jni
In directory pdx:/tmp/cvs-serv25849/jni

Modified Files:
	CairoImageBuffer.cpp 
Log Message:
Add method that draws the cairo image buffer onto a pixmap.

Index: CairoImageBuffer.cpp
===================================================================
RCS file: /cvs/cairo/CairoJava/jni/CairoImageBuffer.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** a/CairoImageBuffer.cpp	30 Apr 2004 17:46:37 -0000	1.1
--- b/CairoImageBuffer.cpp	13 May 2004 16:44:44 -0000	1.2
***************
*** 105,106 ****
--- 105,145 ----
  }
  
+ /*
+  * Class:     org_cairographics_cairo_CairoImageBuffer
+  * Method:    image_buffer_draw_on_pixmap
+  * Signature: (JJJIIIIII)V
+  */
+ JNIEXPORT void JNICALL Java_org_cairographics_cairo_CairoImageBuffer_image_1buffer_1draw_1on_1pixmap
+   (JNIEnv *env, jclass me, jlong imgp, jlong pixmap, jlong gcp, jint dst_x, jint dst_y, jint width, jint height)
+ {
+     GdkPixmap *drawable = (GdkPixmap *) (long) pixmap;
+     cairo_image_buffer_t *img = TO_PTR(cairo_image_buffer_t, imgp);
+     GdkGC* gdkgc = TO_PTR(GdkGC, gcp);
+ 
+     /*
+      * Un-premultiply alpha values
+      */
+     unsigned char *b = (unsigned char *) img->bytes;
+     unsigned char *end  = (unsigned char *) (img->bytes + width * height * 4);
+     while(b < end) {
+         unsigned int *p = (unsigned int *) b;
+         unsigned int pixel = *p;
+         unsigned char alpha = (pixel & 0xff000000) >> 24;
+         if (alpha == 0) {
+             *p = 0;
+         } else {
+             unsigned int alpha2 = 255 / alpha;
+             
+             *b++ = ((pixel & 0xff0000) >> 16) * alpha2;
+             *b++ = ((pixel & 0x00ff00) >>  8) * alpha2;
+             *b++ = ((pixel & 0x0000ff) >>  0) * alpha2;
+             *b++ = alpha;
+         }
+     }
+ 
+     gdk_draw_rgb_32_image(drawable,
+                           gdkgc,
+                           dst_x, dst_y,
+                           width, height, GDK_RGB_DITHER_NORMAL,
+                           (guchar *) img->bytes, img->stride);
+ }





More information about the cairo-commit mailing list