[libbluray-devel] J2SE: Added J2ME-compatible BufferedImage.

hpi1 git at videolan.org
Fri May 10 14:30:54 CEST 2013


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Fri May 10 14:48:21 2013 +0300| [131ed474c7d3d9921dfdd2596641e8cf8425bfaf] | committer: hpi1

J2SE: Added J2ME-compatible BufferedImage.
Set libbluray.jar to be first in classpath so that our own implementation is used instead of the one in JVM bootclasspath.

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=131ed474c7d3d9921dfdd2596641e8cf8425bfaf
---

 src/libbluray/bdj/bdj.c                            |    2 +-
 .../bdj/java-j2se/java/awt/BDGraphics.java         |   41 ++++++--
 src/libbluray/bdj/java-j2se/java/awt/BDImage.java  |    4 +-
 .../java-j2se/java/awt/image/BufferedImage.java    |  110 ++++++++++++++++++++
 .../java-j2se/sun/awt/image/BufferedImagePeer.java |   46 ++++++++
 5 files changed, 192 insertions(+), 11 deletions(-)

diff --git a/src/libbluray/bdj/bdj.c b/src/libbluray/bdj/bdj.c
index debdc6c..abbe10e 100644
--- a/src/libbluray/bdj/bdj.c
+++ b/src/libbluray/bdj/bdj.c
@@ -290,7 +290,7 @@ BDJAVA* bdj_open(const char *path, struct bluray *bd,
     option[n++].optionString = str_printf("-Dbluray.bindingunit.root=%s", _bdj_buda_root());
 
     option[n++].optionString = str_dup   ("-Dawt.toolkit=java.awt.BDToolkit");
-    option[n++].optionString = str_printf("-Xbootclasspath/a:%s", _find_libbluray_jar());
+    option[n++].optionString = str_printf("-Xbootclasspath/p:%s", _find_libbluray_jar());
     option[n++].optionString = str_dup   ("-Xms256M");
     option[n++].optionString = str_dup   ("-Xmx256M");
     option[n++].optionString = str_dup   ("-Xss2048k");
diff --git a/src/libbluray/bdj/java-j2se/java/awt/BDGraphics.java b/src/libbluray/bdj/java-j2se/java/awt/BDGraphics.java
index 4c61d68..8d47d02 100644
--- a/src/libbluray/bdj/java-j2se/java/awt/BDGraphics.java
+++ b/src/libbluray/bdj/java-j2se/java/awt/BDGraphics.java
@@ -86,7 +86,7 @@ class BDGraphics extends Graphics2D implements ConstrainableGraphics {
         fontMetrics = g.fontMetrics;
         originX = g.originX;
         originY = g.originY;
-        actualClip = g.clip;
+        actualClip = g.actualClip;
         clip = g.clip;
         constrainedRect = g.constrainedRect;
         if (clip == null)
@@ -683,16 +683,12 @@ class BDGraphics extends Graphics2D implements ConstrainableGraphics {
         if (img instanceof BDImage) {
             bdImage = (BDImage)img;
         } else if (img instanceof DVBBufferedImage) {
-            logger.unimplemented("drawImageN(DVBBufferedImage)");
-            //bdImage = (BDImage)getBufferedImagePeer(
-            //          (BufferedImage)(((DVBBufferedImage)img).getImage()));
-            bdImage = (BDImage)((DVBBufferedImage)img).getImage();
+            bdImage = (BDImage)getBufferedImagePeer(
+                      (BufferedImage)(((DVBBufferedImage)img).getImage()));
         } else if (img instanceof BufferedImage) {
-            logger.unimplemented("drawImageN(BufferedImage)");
-            //bdImage = (BDImage)getBufferedImagePeer((BufferedImage)img);
-            return false;
+            bdImage = (BDImage)getBufferedImagePeer((BufferedImage)img);
         } else {
-            logger.unimplemented("drawImageN(UNKNOWN)");
+            logger.unimplemented("drawImageN: unsupported image type " + img.getClass().getName());
             return false;
         }
         if (bdImage instanceof BDImageConsumer) {
@@ -764,5 +760,32 @@ class BDGraphics extends Graphics2D implements ConstrainableGraphics {
         return getClass().getName() + "[" + originX + "," + originY + "]";
     }
 
+    private static Image getBufferedImagePeer(BufferedImage image) {
+        try {
+            return (Image)bufferedImagePeer.get(image);
+        } catch (IllegalArgumentException e) {
+            e.printStackTrace();
+        } catch (IllegalAccessException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    private static Field bufferedImagePeer;
+
+    static {
+        try {
+            Class c = Class.forName("java.awt.image.BufferedImage");
+            bufferedImagePeer = c.getDeclaredField("peer");
+            bufferedImagePeer.setAccessible(true);
+        } catch (ClassNotFoundException e) {
+            throw new AWTError("java.awt.image.BufferedImage not found");
+        } catch (SecurityException e) {
+            throw new AWTError("java.awt.image.BufferedImage.peer not accessible");
+        } catch (NoSuchFieldException e) {
+            throw new AWTError("java.awt.image.BufferedImage.peer not found");
+        }
+    }
+
     private static final Logger logger = Logger.getLogger(BDGraphics.class.getName());
 }
diff --git a/src/libbluray/bdj/java-j2se/java/awt/BDImage.java b/src/libbluray/bdj/java-j2se/java/awt/BDImage.java
index e8e048b..4b79d32 100644
--- a/src/libbluray/bdj/java-j2se/java/awt/BDImage.java
+++ b/src/libbluray/bdj/java-j2se/java/awt/BDImage.java
@@ -19,7 +19,9 @@
 
 package java.awt;
 
-class BDImage extends BDImageBase {
+import sun.awt.image.BufferedImagePeer;
+
+class BDImage extends BDImageBase implements BufferedImagePeer {
     BDImage(Component component, int width, int height, GraphicsConfiguration gc) {
         super(component, width, height, gc);
     }
diff --git a/src/libbluray/bdj/java-j2se/java/awt/image/BufferedImage.java b/src/libbluray/bdj/java-j2se/java/awt/image/BufferedImage.java
new file mode 100644
index 0000000..afabe91
--- /dev/null
+++ b/src/libbluray/bdj/java-j2se/java/awt/image/BufferedImage.java
@@ -0,0 +1,110 @@
+/*
+ * This file is part of libbluray
+ * Copyright (C) 2012  libbluray
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+package java.awt.image;
+
+import sun.awt.image.BufferedImagePeer;
+import java.awt.Graphics2D;
+
+public class BufferedImage extends java.awt.Image
+{
+    private transient BufferedImagePeer peer;
+
+    public static final int TYPE_INT_ARGB = 2;
+
+    private BufferedImage (BufferedImagePeer peer) {
+        this.peer = peer;
+    }
+
+    public Graphics2D createGraphics() {
+        return (Graphics2D) peer.getGraphics();
+    }
+
+    public void flush() {
+        peer.flush();
+    }
+
+    public ColorModel getColorModel() {
+        return peer.getColorModel();
+    }
+
+    public java.awt.Graphics getGraphics() {
+        return peer.getGraphics();
+    }
+
+    public int getHeight() {
+        return peer.getHeight();
+    }
+
+    public int getHeight(ImageObserver observer) {
+        return peer.getHeight(observer);
+    }
+
+    public Object getProperty(String name) {
+        return peer.getProperty(name);
+    }
+
+    public Object getProperty(String name, ImageObserver observer) {
+        return peer.getProperty(name, observer);
+    }
+
+    public String[] getPropertyNames() {
+        return peer.getPropertyNames();
+    }
+
+    public int getRGB(int x, int y) {
+        return peer.getRGB(x, y);
+    }
+
+    public int[] getRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize) {
+        return peer.getRGB(startX, startY, w, h, rgbArray, offset, scansize);
+    }
+
+    public ImageProducer getSource() {
+        return peer.getSource();
+    }
+
+    public BufferedImage getSubimage(int x, int y, int w, int h) {
+        return peer.getSubimage(x, y, w, h);
+    }
+
+    public int getType() {
+        return peer.getType();
+    }
+
+    public int getWidth() {
+        return peer.getWidth();
+    }
+
+    public int getWidth(ImageObserver observer) {
+        return peer.getWidth(observer);
+    }
+
+    public synchronized void setRGB(int x, int y, int rgb) {
+        peer.setRGB(x, y, rgb);
+    }
+
+    public void setRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize) {
+        peer.setRGB(startX, startY, w, h, rgbArray, offset, scansize);
+    }
+
+    public String toString() {
+        return peer.toString();
+    }
+}
diff --git a/src/libbluray/bdj/java-j2se/sun/awt/image/BufferedImagePeer.java b/src/libbluray/bdj/java-j2se/sun/awt/image/BufferedImagePeer.java
new file mode 100644
index 0000000..815a093
--- /dev/null
+++ b/src/libbluray/bdj/java-j2se/sun/awt/image/BufferedImagePeer.java
@@ -0,0 +1,46 @@
+/*
+ * This file is part of libbluray
+ * Copyright (C) 2012  libbluray
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+package sun.awt.image;
+
+import java.awt.image.ColorModel;
+import java.awt.image.ImageObserver;
+import java.awt.image.ImageProducer;
+import java.awt.image.BufferedImage;
+import java.awt.Graphics;
+
+public interface BufferedImagePeer {
+    void          flush();
+    ColorModel    getColorModel();
+    Graphics      getGraphics();
+    int           getHeight();
+    int           getHeight(ImageObserver observer);
+    Object        getProperty(String name);
+    Object        getProperty(String name, ImageObserver observer);
+    String[]      getPropertyNames();
+    int           getRGB(int x, int y);
+    int[]         getRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize);
+    ImageProducer getSource();
+    BufferedImage getSubimage(int x, int y, int w, int h);
+    int           getType();
+    int           getWidth();
+    int           getWidth(ImageObserver observer);
+    void          setRGB(int x, int y, int rgb);
+    void          setRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize);
+}



More information about the libbluray-devel mailing list