2003/07/09 10:59:17
[org.ibex.core.git] / src / org / xwt / plat / GCJ.java
1 // Copyright 2002 Adam Megacz, see the COPYING file for licensing [GPL]
2 package org.xwt.plat;
3
4 import org.xwt.*;
5 import org.xwt.util.*;
6 import java.io.*;
7
8 /** common superclass for all platforms that use GCJ to compile a native binary */
9 public abstract class GCJ extends Platform {
10
11     // static references to these classes ensure that the linker will include them
12     private static Class c1 = gnu.java.locale.Calendar.class;
13     private static Class c2 = java.util.GregorianCalendar.class;
14     private static Class c3 = gnu.gcj.convert.Input_ASCII.class;
15     private static Class c4 = gnu.gcj.convert.Input_UTF8.class;
16     private static Class c5 = gnu.gcj.convert.Input_8859_1.class;
17     private static Class c6 = gnu.java.locale.LocaleInformation.class;
18     private static Class c7 = gnu.gcj.convert.Output_ASCII.class;
19     private static Class c8 = gnu.java.locale.Calendar_en.class;
20     private static Class c9 = gnu.java.locale.Calendar_en_US.class;
21
22     protected org.xwt.Weak _getWeak(Object o) { return new Java2Weak(o); }
23     protected native InputStream _getBuiltinInputStream(); 
24
25     private static class Java2Weak extends java.lang.ref.WeakReference implements org.xwt.Weak {
26         public Java2Weak(Object o) { super(o); }
27     }
28         
29     // FIXME
30     protected ImageDecoder _decodeJPEG(InputStream is, String name) {
31         try {
32             return new JPEG(is);
33         } catch (Exception e) {
34             Log.log(this, "Exception while decoding JPEG image " + name);
35             Log.log(this, e);
36             return null;
37         }
38     }
39
40     /** Converts an InputStream carrying a JPEG image into an ARGB int[] */
41     private static class JPEG implements ImageDecoder {
42         int[] data;
43         byte[] buffer;
44         int width, height;
45         InputStream is;
46         
47         public final int[] getData() { return data; }
48         public final int getWidth() { return width; }
49         public final int getHeight() { return height; }
50         private JPEG(InputStream is) { this.is = is; nativeDecompress(); buffer = null; }
51         private native void nativeDecompress();
52     }
53
54 }
55