1 // Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL]
8 /** common superclass for all platforms that use GCJ to compile a native binary */
9 public abstract class GCJ extends Platform {
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;
22 protected native InputStream _getBuiltinInputStream();
25 protected ImageDecoder _decodeJPEG(InputStream is, String name) {
28 } catch (Exception e) {
29 Log.log(this, "Exception while decoding JPEG image " + name);
35 /** Converts an InputStream carrying a JPEG image into an ARGB int[] */
36 private static class JPEG extends ImageDecoder {
42 public final int[] getData() { return data; }
43 public final int getWidth() { return width; }
44 public final int getHeight() { return height; }
45 private JPEG(InputStream is) { this.is = is; nativeDecompress(); buffer = null; }
46 private native void nativeDecompress();
49 // FIXME: This could be optimized (a lot) by using a custom hashtable
50 public final static class Retainer {
51 private static Hash table = new Hash();
52 private final static class Key {
54 public Key(Object o) { this.o = o; }
55 public int hashCode() { return o == null ? 0 : o.hashCode(); }
56 public boolean equals(Object o2) { return (o2 instanceof Key) && ((Key)o2).o == o; }
58 private final static class Entry {
60 public Entry() { inc(); }
61 public void inc() { refCount++; }
62 public boolean dec() { return --refCount == 0; }
64 public static synchronized void retain(Object o) {
66 Entry r = (Entry) table.get(k);
67 if(r == null) table.put(k,new Entry());
70 public static synchronized void release(Object o) {
72 Entry e = (Entry) table.get(k);
73 if(e == null) throw new Error("Retainer::Release on unknown object");
74 if(e.dec()) { table.remove(k); }