GdkGraphics2D.java, [...]: New files.
2003-09-17 Graydon Hoare <graydon@redhat.com> * gnu/java/awt/peer/gtk/GdkGraphics2D.java, gnu/java/awt/peer/gtk/GdkPixbufDecoder.java, jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c, jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c: New files. From-SVN: r71475
This commit is contained in:
parent
eeae7b417a
commit
1fe2d5fb09
@ -1,3 +1,11 @@
|
||||
2003-09-17 Graydon Hoare <graydon@redhat.com>
|
||||
|
||||
* gnu/java/awt/peer/gtk/GdkGraphics2D.java,
|
||||
gnu/java/awt/peer/gtk/GdkPixbufDecoder.java,
|
||||
jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c,
|
||||
jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c:
|
||||
New files.
|
||||
|
||||
2003-09-16 Graydon Hoare <graydon@redhat.com>
|
||||
|
||||
* java/awt/BufferedImage.java (setData): Support non-component
|
||||
|
1146
libjava/gnu/java/awt/peer/gtk/GdkGraphics2D.java
Normal file
1146
libjava/gnu/java/awt/peer/gtk/GdkGraphics2D.java
Normal file
File diff suppressed because it is too large
Load Diff
217
libjava/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java
Normal file
217
libjava/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java
Normal file
@ -0,0 +1,217 @@
|
||||
/* GdkPixbufDecoder.java -- Image data decoding object
|
||||
Copyright (C) 2003 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package gnu.java.awt.peer.gtk;
|
||||
|
||||
import java.awt.image.*;
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Vector;
|
||||
import java.util.Hashtable;
|
||||
import gnu.classpath.Configuration;
|
||||
|
||||
public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder
|
||||
{
|
||||
static
|
||||
{
|
||||
if (Configuration.INIT_LOAD_LIBRARY)
|
||||
{
|
||||
System.loadLibrary("gtkpeer");
|
||||
}
|
||||
initStaticState ();
|
||||
}
|
||||
native static void initStaticState ();
|
||||
private final int native_state = GtkGenericPeer.getUniqueInteger ();
|
||||
|
||||
// the current set of ImageConsumers for this decoder
|
||||
Vector curr;
|
||||
|
||||
// interface to GdkPixbuf
|
||||
native void initState ();
|
||||
native void pumpBytes (byte bytes[], int len);
|
||||
native void finish ();
|
||||
|
||||
// gdk-pixbuf provids data in RGBA format
|
||||
static final ColorModel cm = new DirectColorModel (32, 0xff000000,
|
||||
0x00ff0000,
|
||||
0x0000ff00,
|
||||
0x000000ff);
|
||||
public GdkPixbufDecoder (String filename)
|
||||
{
|
||||
super (filename);
|
||||
initState ();
|
||||
}
|
||||
|
||||
public GdkPixbufDecoder (URL url)
|
||||
{
|
||||
super (url);
|
||||
initState ();
|
||||
}
|
||||
|
||||
// called back by native side
|
||||
void areaPrepared (int width, int height)
|
||||
{
|
||||
|
||||
if (curr == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < curr.size (); i++)
|
||||
{
|
||||
ImageConsumer ic = (ImageConsumer) curr.elementAt (i);
|
||||
ic.setDimensions (width, height);
|
||||
ic.setColorModel (cm);
|
||||
ic.setHints (ImageConsumer.RANDOMPIXELORDER);
|
||||
}
|
||||
}
|
||||
|
||||
// called back by native side
|
||||
void areaUpdated (int x, int y, int width, int height,
|
||||
int pixels[], int scansize)
|
||||
{
|
||||
if (curr == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < curr.size (); i++)
|
||||
{
|
||||
ImageConsumer ic = (ImageConsumer) curr.elementAt (i);
|
||||
ic.setPixels (x, y, width, height, cm, pixels, 0, scansize);
|
||||
}
|
||||
}
|
||||
|
||||
// called from an async image loader of one sort or another, this method
|
||||
// repeatedly reads bytes from the input stream and passes them through a
|
||||
// GdkPixbufLoader using the native method pumpBytes. pumpBytes in turn
|
||||
// decodes the image data and calls back areaPrepared and areaUpdated on
|
||||
// this object, feeding back decoded pixel blocks, which we pass to each
|
||||
// of the ImageConsumers in the provided Vector.
|
||||
|
||||
void produce (Vector v, FileInputStream is) throws IOException
|
||||
{
|
||||
curr = v;
|
||||
|
||||
byte bytes[] = new byte[4096];
|
||||
int len = 0;
|
||||
while ((len = is.read (bytes)) != -1)
|
||||
pumpBytes (bytes, len);
|
||||
|
||||
for (int i = 0; i < curr.size (); i++)
|
||||
{
|
||||
ImageConsumer ic = (ImageConsumer) curr.elementAt (i);
|
||||
ic.imageComplete (ImageConsumer.STATICIMAGEDONE);
|
||||
}
|
||||
|
||||
curr = null;
|
||||
}
|
||||
|
||||
// remaining helper class and static method is a convenience for the Gtk
|
||||
// peers, for loading a BufferedImage in off a disk file. one would think
|
||||
// this ought to be fairly straightforward, but it does not appear
|
||||
// anywhere else I can find.
|
||||
|
||||
private class BufferedImageBuilder implements ImageConsumer
|
||||
{
|
||||
BufferedImage bufferedImage;
|
||||
ColorModel defaultModel;
|
||||
|
||||
public BufferedImage getBufferedImage()
|
||||
{
|
||||
return bufferedImage;
|
||||
}
|
||||
|
||||
public void setDimensions(int width, int height)
|
||||
{
|
||||
bufferedImage = new BufferedImage (width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
|
||||
public void setProperties(Hashtable props) {}
|
||||
|
||||
public void setColorModel(ColorModel model)
|
||||
{
|
||||
defaultModel = model;
|
||||
}
|
||||
|
||||
public void setHints(int flags) {}
|
||||
|
||||
public void setPixels(int x, int y, int w, int h,
|
||||
ColorModel model, byte[] pixels,
|
||||
int offset, int scansize)
|
||||
{
|
||||
}
|
||||
|
||||
public void setPixels(int x, int y, int w, int h,
|
||||
ColorModel model, int[] pixels,
|
||||
int offset, int scansize)
|
||||
{
|
||||
if (bufferedImage != null)
|
||||
{
|
||||
|
||||
if (model == null)
|
||||
model = defaultModel;
|
||||
|
||||
int pixels2[];
|
||||
if (model != null)
|
||||
{
|
||||
pixels2 = new int[pixels.length];
|
||||
for (int yy = 0; yy < h; yy++)
|
||||
for (int xx = 0; xx < w; xx++)
|
||||
{
|
||||
int i = yy * scansize + xx;
|
||||
pixels2[i] = model.getRGB (pixels[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
pixels2 = pixels;
|
||||
|
||||
bufferedImage.setRGB (x, y, w, h, pixels2, offset, scansize);
|
||||
}
|
||||
}
|
||||
|
||||
public void imageComplete(int status) {}
|
||||
}
|
||||
|
||||
public static BufferedImage createBufferedImage (String filename)
|
||||
{
|
||||
BufferedImageBuilder bb = new BufferedImageBuilder ();
|
||||
GdkPixbufDecoder dec = new GdkPixbufDecoder (filename);
|
||||
dec.startProduction (bb);
|
||||
return bb.getBufferedImage ();
|
||||
}
|
||||
|
||||
}
|
1069
libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c
Normal file
1069
libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c
Normal file
File diff suppressed because it is too large
Load Diff
236
libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c
Normal file
236
libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c
Normal file
@ -0,0 +1,236 @@
|
||||
/* gdkpixbufdecoder.c
|
||||
Copyright (C) 1999, 2003 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
#include <gdk-pixbuf/gdk-pixbuf-loader.h>
|
||||
|
||||
#include "gtkpeer.h"
|
||||
#include "gnu_java_awt_peer_gtk_GdkPixbufDecoder.h"
|
||||
|
||||
struct state_table *native_pixbufdecoder_state_table;
|
||||
|
||||
#define NSA_PB_INIT(env, clazz) \
|
||||
native_pixbufdecoder_state_table = init_state_table (env, clazz)
|
||||
|
||||
#define NSA_GET_PB_PTR(env, obj) \
|
||||
get_state (env, obj, native_pixbufdecoder_state_table)
|
||||
|
||||
#define NSA_SET_PB_PTR(env, obj, ptr) \
|
||||
set_state (env, obj, native_pixbufdecoder_state_table, (void *)ptr)
|
||||
|
||||
#define NSA_DEL_PB_PTR(env, obj) \
|
||||
remove_state_slot (env, obj, native_pixbufdecoder_state_table)
|
||||
|
||||
|
||||
jmethodID areaPreparedID;
|
||||
jmethodID areaUpdatedID;
|
||||
|
||||
static void
|
||||
area_prepared (GdkPixbufLoader *loader,
|
||||
jobject *decoder)
|
||||
{
|
||||
jint width, height;
|
||||
|
||||
GdkPixbuf *pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
|
||||
if (pixbuf == NULL)
|
||||
return;
|
||||
|
||||
width = gdk_pixbuf_get_width (pixbuf);
|
||||
height = gdk_pixbuf_get_height (pixbuf),
|
||||
|
||||
gdk_threads_leave ();
|
||||
|
||||
g_assert (decoder != NULL);
|
||||
|
||||
(*gdk_env)->CallVoidMethod (gdk_env,
|
||||
*decoder,
|
||||
areaPreparedID,
|
||||
width, height);
|
||||
|
||||
gdk_threads_enter ();
|
||||
}
|
||||
|
||||
static void
|
||||
area_updated (GdkPixbufLoader *loader,
|
||||
gint x, gint y,
|
||||
gint width, gint height,
|
||||
jobject *decoder)
|
||||
{
|
||||
jint stride_bytes, stride_pixels, n_channels, n_pixels;
|
||||
int i, px;
|
||||
jintArray jpixels;
|
||||
jint *java_pixels;
|
||||
guchar *gdk_pixels;
|
||||
|
||||
GdkPixbuf *pixbuf_no_alpha = NULL;
|
||||
GdkPixbuf *pixbuf = NULL;
|
||||
|
||||
pixbuf_no_alpha = gdk_pixbuf_loader_get_pixbuf (loader);
|
||||
if (pixbuf_no_alpha == NULL)
|
||||
return;
|
||||
|
||||
pixbuf = gdk_pixbuf_add_alpha(pixbuf_no_alpha, FALSE, 0, 0, 0);
|
||||
g_assert (gdk_pixbuf_get_has_alpha (pixbuf));
|
||||
|
||||
stride_bytes = gdk_pixbuf_get_rowstride (pixbuf);
|
||||
n_channels = gdk_pixbuf_get_n_channels (pixbuf);
|
||||
stride_pixels = stride_bytes / n_channels;
|
||||
n_pixels = height * stride_pixels;
|
||||
gdk_pixels = gdk_pixbuf_get_pixels (pixbuf);
|
||||
|
||||
jpixels = (*gdk_env)->NewIntArray (gdk_env, n_pixels);
|
||||
java_pixels = (*gdk_env)->GetIntArrayElements (gdk_env, jpixels, NULL);
|
||||
|
||||
memcpy (java_pixels,
|
||||
gdk_pixels + (y * stride_bytes),
|
||||
(height * stride_bytes));
|
||||
|
||||
for (i = 0; i < n_pixels; ++i)
|
||||
{
|
||||
px = java_pixels[i];
|
||||
|
||||
/* move alpha around (GdkPixbufLoader results are AGBR not GBRA, in
|
||||
the lsb sense) */
|
||||
/* px = ((px >> 24) & 0xff) | ((px << 8) & 0xffffff00); */
|
||||
|
||||
/* it appears to require a full byte swap, now, not just a shift to
|
||||
the A channel. why did this change? don't know. */
|
||||
px = ((px >> 8) & 0x00ff00ff) | ((px << 8) & 0xff00ff00);
|
||||
px = ((px >> 16) & 0x0000ffff) | ((px << 16) & 0xffff0000);
|
||||
|
||||
java_pixels[i] = px;
|
||||
}
|
||||
|
||||
g_object_unref (pixbuf);
|
||||
|
||||
gdk_threads_leave ();
|
||||
|
||||
(*gdk_env)->ReleaseIntArrayElements (gdk_env, jpixels, java_pixels, 0);
|
||||
(*gdk_env)->CallVoidMethod (gdk_env,
|
||||
*decoder,
|
||||
areaUpdatedID,
|
||||
(jint) x, (jint) y,
|
||||
(jint) width, (jint) height,
|
||||
jpixels,
|
||||
stride_pixels);
|
||||
gdk_threads_enter ();
|
||||
}
|
||||
|
||||
static void
|
||||
closed (GdkPixbufLoader *loader, jobject *decoder)
|
||||
{
|
||||
gdk_threads_leave ();
|
||||
(*gdk_env)->DeleteGlobalRef (gdk_env, *decoder);
|
||||
free (decoder);
|
||||
gdk_threads_enter ();
|
||||
}
|
||||
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_initState
|
||||
(JNIEnv *env, jobject obj)
|
||||
{
|
||||
GdkPixbufLoader *loader = NULL;
|
||||
jobject *decoder = NULL;
|
||||
|
||||
decoder = (jobject *) malloc (sizeof (jobject));
|
||||
g_assert (decoder != NULL);
|
||||
*decoder = (*env)->NewGlobalRef (env, obj);
|
||||
|
||||
gdk_threads_enter ();
|
||||
loader = gdk_pixbuf_loader_new ();
|
||||
g_assert (loader != NULL);
|
||||
g_signal_connect (loader, "area-prepared", G_CALLBACK (area_prepared), decoder);
|
||||
g_signal_connect (loader, "area-updated", G_CALLBACK (area_updated), decoder);
|
||||
g_signal_connect (loader, "closed", G_CALLBACK (closed), decoder);
|
||||
gdk_threads_leave ();
|
||||
|
||||
NSA_SET_PB_PTR (env, obj, loader);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_initStaticState
|
||||
(JNIEnv *env, jclass clazz)
|
||||
{
|
||||
areaPreparedID = (*env)->GetMethodID (env, clazz,
|
||||
"areaPrepared",
|
||||
"(II)V");
|
||||
|
||||
areaUpdatedID = (*env)->GetMethodID (env, clazz,
|
||||
"areaUpdated",
|
||||
"(IIII[II)V");
|
||||
NSA_PB_INIT (env, clazz);
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_finish
|
||||
(JNIEnv *env, jobject obj)
|
||||
{
|
||||
GdkPixbufLoader *loader = NULL;
|
||||
|
||||
loader = (GdkPixbufLoader *)NSA_DEL_PB_PTR (env, obj);
|
||||
if (loader == NULL)
|
||||
return;
|
||||
|
||||
gdk_threads_enter ();
|
||||
gdk_pixbuf_loader_close (loader, NULL);
|
||||
g_object_unref (loader);
|
||||
gdk_threads_leave ();
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_pumpBytes
|
||||
(JNIEnv *env, jobject obj, jbyteArray jarr, jint len)
|
||||
{
|
||||
GdkPixbufLoader *loader = NULL;
|
||||
jbyte *bytes = NULL;
|
||||
|
||||
if (len < 1)
|
||||
return;
|
||||
|
||||
bytes = (*gdk_env)->GetByteArrayElements (gdk_env, jarr, NULL);
|
||||
g_assert (bytes != NULL);
|
||||
loader = (GdkPixbufLoader *)NSA_GET_PB_PTR (env, obj);
|
||||
g_assert (loader != NULL);
|
||||
|
||||
gdk_threads_enter ();
|
||||
gdk_pixbuf_loader_write (loader, bytes, len, NULL);
|
||||
gdk_threads_leave ();
|
||||
|
||||
(*gdk_env)->ReleaseByteArrayElements (gdk_env, jarr, bytes, 0);
|
||||
}
|
Loading…
Reference in New Issue
Block a user