2 Copyright (C) 1999, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 #include "gnu_java_awt_peer_gtk_GtkImagePainter.h"
40 #include <libart_lgpl/art_misc.h>
41 #include <libart_lgpl/art_rgb_affine.h>
44 JNIEXPORT void JNICALL
45 Java_gnu_java_awt_peer_gtk_GtkImagePainter_drawPixels
46 (JNIEnv *env, jobject obj __attribute__((unused)), jobject gc_obj,
47 jint bg_red, jint bg_green, jint bg_blue, jint x, jint y, jint width,
48 jint height, jintArray jpixels, jint offset, jint scansize,
56 guchar *j_rgba, *c_rgb;
58 g = (struct graphics *) NSA_GET_PTR (env, gc_obj);
63 elems = (*env)->GetIntArrayElements (env, jpixels, NULL);
64 num_pixels = (*env)->GetArrayLength (env, jpixels);
66 /* get a copy of the pixel data so we can modify it */
67 pixels = malloc (sizeof (jint) * num_pixels);
68 memcpy (pixels, elems, sizeof (jint) * num_pixels);
70 (*env)->ReleaseIntArrayElements (env, jpixels, elems, 0);
72 #ifndef WORDS_BIGENDIAN
73 /* convert pixels from 0xBBGGRRAA to 0xAARRGGBB */
74 for (i = 0; i < num_pixels; i++)
75 pixels[i] = SWAPU32 ((unsigned)pixels[i]);
78 packed = (guchar *) malloc (sizeof (guchar) * 3 * num_pixels);
79 j_rgba = (guchar *) pixels;
82 /* copy over pixels in DirectColorModel format to 24 bit RGB image data,
83 and process the alpha channel */
84 for (i = 0; i < num_pixels; i++)
86 jint ialpha = *j_rgba++;
90 case 0: /* full transparency */
96 case 255: /* opaque */
101 default: /* compositing required */
103 jfloat alpha = ialpha / 255.0;
104 jfloat comp_alpha = 1.0 - alpha;
106 *c_rgb++ = *j_rgba++ * alpha + bg_red * comp_alpha;
107 *c_rgb++ = *j_rgba++ * alpha + bg_green * comp_alpha;
108 *c_rgb++ = *j_rgba++ * alpha + bg_blue * comp_alpha;
117 ArtAlphaGamma *alphagamma = NULL;
119 int new_width, new_height;
121 affine = (*env)->GetDoubleArrayElements (env, jaffine, NULL);
123 new_width = abs (width * affine[0]);
124 new_height = abs (height * affine[3]);
126 dst = (art_u8 *) malloc (sizeof (art_u8) * 3 * (new_width * new_height));
130 new_width, new_height,
132 (art_u8 *) packed + offset * 3,
139 (*env)->ReleaseDoubleArrayElements (env, jaffine, affine, JNI_ABORT);
142 packed = (guchar *) dst;
144 width = scansize = new_width;
149 gdk_threads_enter ();
151 if (!g || !GDK_IS_DRAWABLE (g->drawable))
153 gdk_threads_leave ();
157 gdk_draw_rgb_image (g->drawable,
161 width, height, GDK_RGB_DITHER_NORMAL,
162 packed + offset * 3, scansize * 3);
164 gdk_threads_leave ();