protected String getDescriptiveName() { return "Generic JDK 1.1+ with AWT"; }
protected PixelBuffer _createPixelBuffer(int w, int h, Surface owner) { return new AWTPixelBuffer(w, h); }
- protected Picture _createPicture(int[] b, int w, int h) { return new AWTPicture(b, w, h); }
+ protected Picture _createPicture() { return new AWTPicture(); }
protected int _getScreenWidth() { return Toolkit.getDefaultToolkit().getScreenSize().width; }
protected int _getScreenHeight() { return Toolkit.getDefaultToolkit().getScreenSize().height; }
protected Surface _createSurface(Box b, boolean framed) { return new AWTSurface(b, framed); }
// Inner Classes /////////////////////////////////////////////////////////////////////////////////////
- protected static class AWTPicture extends Picture {
- public int getHeight() { return i.getHeight(null); }
- public int getWidth() { return i.getWidth(null); }
- public int[] getData() { return data; }
+ protected org.xwt.Font.Glyph _createGlyph(org.xwt.Font f, char c) { return new AWTGlyph(f, c); }
+ protected static class AWTGlyph extends org.xwt.Font.Glyph {
+ private Image i = null;
+ static ColorModel cmodel = new DirectColorModel(8, 0x00000000, 0x00000000, 0x00000000, 0xFF);
+ public AWTGlyph(org.xwt.Font f, char c) { super(f, c); }
+ Image getImage() {
+ if (i == null && isLoaded) {
+ i = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(width, height, cmodel, data, 0, width));
+ MediaTracker mediatracker = new MediaTracker(new Canvas());
+ mediatracker.addImage(i, 1);
+ try { mediatracker.waitForAll(); } catch (InterruptedException e) { }
+ mediatracker.removeImage(i);
+ synchronized(AWTPixelBuffer.class) {
+ if (AWTPixelBuffer.component == null) {
+ AWTPixelBuffer.component = new Frame();
+ AWTPixelBuffer.component.setVisible(false);
+ AWTPixelBuffer.component.addNotify();
+ }
+ }
+ data = null;
+ }
+ return i;
+ }
+ }
+ protected static class AWTPicture extends Picture {
int[] data = null;
public Image i = null;
private static ColorModel cmodel = new DirectColorModel(32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
- public AWTPicture(int[] b, int w, int h) {
- data = b;
- i = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(w, h, cmodel, b, 0, w));
+ boolean initialized = false;
+ public void init() {
+ if (initialized) return;
+ initialized = true;
+ i = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(width, height, cmodel, data, 0, width));
MediaTracker mediatracker = new MediaTracker(new Canvas());
mediatracker.addImage(i, 1);
try { mediatracker.waitForAll(); } catch (InterruptedException e) { }
public int getWidth() { return i == null ? 0 : i.getWidth(null); }
public void drawPicture(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2) {
+ ((AWTPicture)source).init();
g.setClip(cx1, cy1, cx2 - cx1, cy2 - cy1);
g.drawImage(((AWTPicture)source).i, dx, dy, null);
g.setClip(0, 0, i.getWidth(null), i.getHeight(null));
}
/** implemented with java.awt 1.1's setXORMode() */
- public void drawPictureAlphaOnly(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int rgb) {
+ public void drawGlyph(org.xwt.Font.Glyph source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int rgb) {
// XOR the target region
g.setXORMode(new Color((rgb & 0x00ff0000) >> 16, (rgb & 0x0000ff00) >> 8, rgb & 0x000000ff));
// blacken the area we want the glyph to cover
g.setPaintMode();
- drawPicture(source, dx, dy, cx1, cy1, cx2, cy2);
+ g.setClip(cx1, cy1, cx2 - cx1, cy2 - cy1);
+ g.drawImage(((AWTGlyph)source).getImage(), dx, dy, null);
+ g.setClip(0, 0, i.getWidth(null), i.getHeight(null));
// XOR back, turning black into the chosen rgb color
g.setXORMode(new Color((rgb & 0x00ff0000) >> 16, (rgb & 0x0000ff00) >> 8, rgb & 0x000000ff));
}
}
- protected Picture _decodeJPEG(InputStream is, String name) {
+ protected void _decodeJPEG(InputStream is, Picture p) {
try {
Image i = Toolkit.getDefaultToolkit().createImage(InputStreamToByteArray.convert(is));
MediaTracker mediatracker = new MediaTracker(new Canvas());
final int[] data = new int[width * height];
PixelGrabber pg = new PixelGrabber(i, 0, 0, width, height, data, 0, width);
pg.grabPixels();
- if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
- Log.log(this, "PixelGrabber reported an error while decoding JPEG image " + name);
- return null;
- }
- return Platform.createPicture(data, width, height);
+ if ((pg.getStatus() & ImageObserver.ABORT) != 0)
+ Log.log(this, "PixelGrabber reported an error while decoding JPEG image");
+ p.width = width;
+ p.height = height;
+ p.data = data;
} catch (Exception e) {
- Log.log(this, "Exception caught while decoding JPEG image " + name);
+ Log.log(this, "Exception caught while decoding JPEG image");
Log.log(this, e);
- return null;
}
}
}
private static native final boolean isJaguar();
- // Called by main thread after initialization, this is the event handler
- protected native void runApplicationEventLoop();
-
- public void init() {
- super.init();
+ public void postInit() {
jaguar = isJaguar();
try {
openGL = new CarbonOpenGL();
natInit();
}
- public void _running() { runApplicationEventLoop(); }
+ protected native void runApplicationEventLoop();
+ private class DarwinScheduler extends org.xwt.Scheduler {
+ public void run() {
+ new Thread() { public void run() { defaultRun(); } }.start();
+ runApplicationEventLoop();
+ }
+ }
private final class CarbonOpenGL extends OpenGL {
public RawData rawPixelFormat;
else
return /*new QZCarbonSufrace(b,framed)*/ null;
}
- protected Picture _createPicture(int[] data, int w, int h) {
+ protected Picture _createPicture() {
if(openGL != null)
- return openGL.createPicture(data,w,h);
+ return openGL._createPicture(true);
else
return /*new QZCarbonPicture(data,w,h);*/ null;
}
- protected Picture _createAlphaOnlyPicture(byte[] data, int w, int h) {
+ protected org.xwt.Font.Glyph _createGlyph(org.xwt.Font f, char c) {
if(openGL != null)
- return openGL.createAlphaOnlyPicture(data,w,h);
+ return openGL._createGlyph(f, c);
else
- return super.createAlphaOnlyPicture(data,w,h);
+ return super.createGlyph(f, c);
}
/* A message that is sent through the carbon event queue */
src->pub.bytes_in_buffer -= num_bytes;
}
-org::xwt::Picture* org::xwt::plat::GCJ::_decodeJPEG(java::io::InputStream* is, jstring name) {
+void org::xwt::plat::GCJ::_decodeJPEG(java::io::InputStream* is, org::xwt::Picture* p) {
struct jpeg_decompress_struct cinfo;
my_error_mgr_t jerr;
my_source_mgr_t src;
- jintArray data;
- jint width;
- jint height;
src.is = is;
src.buf = JvNewByteArray(16384);
(jerr.pub.format_message)((j_common_ptr)&cinfo, msgbuf);
Log::log(&GCJ::class$,JvNewStringLatin1(msgbuf));
jpeg_destroy_decompress(&cinfo);
- return 0;
+ return;
}
jpeg_create_decompress(&cinfo);
jpeg_read_header(&cinfo,TRUE);
jpeg_start_decompress(&cinfo);
- width = cinfo.output_width;
- height = cinfo.output_height;
- data = JvNewIntArray(width * height);
+ p->width = cinfo.output_width;
+ p->height = cinfo.output_height;
+ p->data = JvNewIntArray(width * height);
while (cinfo.output_scanline < cinfo.output_height) {
JSAMPLE *dest = (JSAMPLE*) (elements(data) + cinfo.output_scanline * width);
for(int i=0;i<data->length;i++)
elements(data)[i] |= 0xff000000; // alpha channel
-
- return org::xwt::Platform::createPicture(data, width, height);
}
// C++ new/delete operators (JvMalloc never fails)
protected native InputStream _getBuiltinInputStream();
- protected native Picture _decodeJPEG(InputStream is, String name);
+ protected native void _decodeJPEG(InputStream is, Picture p);
// FEATURE: This could be optimized (a lot) by using a custom hashtable
public final static class Retainer {
public class Java2 extends AWT {
private boolean isJava14 = false;
- protected boolean _supressDirtyOnResize() {
- return false;
- //return (isJava14 && !System.getProperty("os.name", "").equals("Mac OS X"))? false : true;
- }
public Java2() {
// disable the focus manager so we can intercept the tab key
String versionString = System.getProperty("java.version", "");
int secondDecimal = versionString.substring(versionString.indexOf('.') + 1).indexOf('.');
if (secondDecimal != -1) versionString = versionString.substring(0, secondDecimal);
- /*
double version = Double.parseDouble(versionString);
if (version >= 1.4) {
isJava14 = true;
Log.log(this, e);
}
}
- */
javax.swing.FocusManager.setCurrentManager(new javax.swing.FocusManager() {
public void processKeyEvent(Component focusedComponent, KeyEvent anEvent) { }
public void focusPreviousComponent(Component aComponent) { }
private SampleModel sm = null;
private DataBuffer buf = null;
- public void drawPictureAlphaOnly(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int rgb) {
+ public void drawGlyph(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int rgb) {
AWTPicture src = (AWTPicture)source;
+ src.init();
Graphics2D g2 = (Graphics2D)i.getGraphics();
g2.setComposite(AlphaComposite.DstOut);
g2.setClip(cx1, cy1, cx2 - cx1, cy2 - cy1);
//System.out.println("drawString(): " + text);
}
- public void drawPictureAlphaOnly(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int rgb) {
- drawPicture_(source, dx, dy, cx1, cy1, cx2, cy2, rgb);
+ public void drawGlyph(org.xwt.Font.Glyph source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int rgb) {
+ drawPicture_(((org.xwt.Platform.DefaultGlyph)source).getPicture(), dx, dy, cx1, cy1, cx2, cy2, rgb);
}
public void drawPicture(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2) {
drawPicture_(source, dx, dy, cx1, cy1, cx2, cy2, 0xffffffff);
private void drawPicture_(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int color) {
activateInterpreter();
setColor(color);
- GLPicture p = (GLPicture) source;
+ GLPicture p = getInnerPicture(source, gl);
p.draw(dx,dy,cx1,cy1,cx2,cy2);
}
}
+
+ // FIXME ugly
+ public static OpenGL gl = null;
+ public OpenGL() { gl = this; }
public final static int roundToPowerOf2(int n) {
if(((n-1)&n)==0) return n;
for(int x=2;x!=0;x<<=1) if(n < x) return x;
return 0;
}
-
- private Picture _createPicture(Object data, int w, int h, boolean alphaOnly) {
- if(rectangularTextures && w <= maxRectTexSize && h <= maxRectTexSize) new RectGLPicture(data,w,h,alphaOnly,this);
- if(w <= maxTexSize && h <= maxTexSize) return new SquareGLPicture(data,w,h,alphaOnly,this);
- return new MosaicGLPicture(data,w,h,alphaOnly,this);
- }
- public Picture createPicture(int[] data, int w, int h) {
- if(w*h > data.length) throw new Error("should never happen");
- return _createPicture(data,w,h,false);
+ private static GLPicture getInnerPicture(Picture p, OpenGL gl) {
+ OpenGLPicture oglp = (OpenGLPicture)p;
+ if (!oglp.isLoaded || oglp.realPicture != null) return oglp.realPicture;
+ if (gl.rectangularTextures && p.width <= gl.maxRectTexSize && p.height <= gl.maxRectTexSize)
+ oglp.realPicture = new RectGLPicture(p.data,p.width,p.height,oglp.alphaOnly,gl);
+ else if (p.width <= gl.maxTexSize && p.height <= gl.maxTexSize)
+ oglp.realPicture = new SquareGLPicture(p.data,p.width,p.height,oglp.alphaOnly,gl);
+ else
+ oglp.realPicture = new MosaicGLPicture(p.data,p.width,p.height,oglp.alphaOnly,gl);
+ p.data = null;
+ return oglp.realPicture;
}
- public Picture createAlphaOnlyPicture(byte[] data, int w, int h) {
- if(w*h > data.length) throw new Error("should never happen");
- return _createPicture(data,w,h,true);
+
+ public Picture _createPicture(boolean alphaOnly) { return new OpenGLPicture(alphaOnly); }
+
+ public static class OpenGLPicture extends Picture {
+ public OpenGLPicture(boolean a) { alphaOnly = a; }
+ boolean alphaOnly;
+ GLPicture realPicture = null;
}
+
+ public Font.Glyph _createGlyph(org.xwt.Font f, char c) { return new OpenGLGlyph(f, c); }
+ public static class OpenGLGlyph extends Font.Glyph {
+ private Picture p = null;
+ public OpenGLGlyph(org.xwt.Font f, char c) { super(f, c); }
+ Picture getPicture() {
+ if (p == null && isLoaded) {
+ p = new OpenGLPicture(true);
+ p.data = new int[data.length];
+ for(int i=0; i<data.length; i++) p.data[i] = (data[i] & 0xff) << 24;
+ data = null;
+ p.width = this.width;
+ p.height = this.height;
+ }
+ return p;
+ }
+ }
+
private native void natDeleteTexture(int tex);
public void deleteTexture(final int tex) {
// CHECKME: Is this safe to do from finalize()?
Scheduler.add(new Scheduler.Task() { public void perform() { natDeleteTexture(tex); }});
}
- private static abstract class GLPicture extends Picture {
+ private static abstract class GLPicture {
protected int width;
protected int height;
// Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL]
package org.xwt.plat;
import org.xwt.*;
+import java.io.*;
/** Platform class for PalmOS devices */
public class PalmOS extends Platform {
return 0;
}
+ protected void _decodeJPEG(InputStream is, Picture p) {
+ throw new Error("unimplemented");
+ }
+
}
protected String getDescriptiveName() { return "GCJ Win32 Binary"; }
protected Surface _createSurface(Box b, boolean framed) { return new Win32Surface(b, framed); }
protected PixelBuffer _createPixelBuffer(int w, int h, Surface owner) { return new Win32PixelBuffer(w, h, (Win32Surface)owner); }
- protected Picture _createPicture(int[] b, int w, int h) { return new Win32Picture(b, w, h); }
+ protected Picture _createPicture() { return new Win32Picture(); }
protected native int _getScreenWidth();
protected native int _getScreenHeight();
protected boolean _supressDirtyOnResize() { return false; }
public int getWidth() { return w; };
public int getHeight() { return h; };
public int[] getData() { return data; }
+ boolean initialized = false;
+ public void init() { if (!initialized && isLoaded) natInit(); initialized = true; }
public native void natInit();
- public Win32Picture(int[] data, int w, int h) { this.w = w; this.h = h; this.data = data; natInit(); }
}
public native void fillRect(int x, int y, int x2, int y2, int color);
public void drawPicture(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2) {
+ ((Win32Picture)source).init();
drawPicture(source, dx, dy, cx1, cy1, cx2, cy2, 0, false);
}
- public void drawPictureAlphaOnly(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int rgb) {
- drawPicture(source, dx, dy, cx1, cy1, cx2, cy2, rgb, true);
+ public void drawGlyph(org.xwt.Font.Glyph source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int rgb) {
+ Win32Picture p = ((Win32Picture)((DefaultGlyph)source).getPicture());
+ p.init();
+ drawPicture(p, dx, dy, cx1, cy1, cx2, cy2, rgb, true);
}
public native void drawPicture(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2,
int rgb, boolean alphaOnly);
protected String _getAltKeyName() { return System.getProperty("os.name", "").indexOf("SunOS") != -1 ? "Meta" : "Alt"; }
- protected Picture _createPicture(int[] data, int w, int h) { return new X11Picture(data, w, h); }
+ protected Picture _createPicture() { return new X11Picture(); }
protected PixelBuffer _createPixelBuffer(int w, int h, Surface owner) { return new X11PixelBuffer(w, h); }
protected Surface _createSurface(Box b, boolean framed) { return new X11Surface(b, framed); }
protected boolean _needsAutoClick() { return true; }
public int getWidth() { return width; }
public int getHeight() { return height; }
- public X11Picture(int[] data, int w, int h) {
- this.data = data;
- this.width = w;
- this.height = h;
+ boolean initialized = false;
+ public void init() {
+ if (initialized) return;
+ initialized = true;
boolean needsStipple = false;
// if we have any non-0x00, non-0xFF alphas, we can't double buffer ourselves
- for(int i=0; i<w*h; i++)
+ for(int i=0; i<width*height; i++)
if ((data[i] & 0xFF000000) == 0xFF000000)
needsStipple = true;
else if ((data[i] & 0xFF000000) != 0x00)
natInit();
}
- public void drawPictureAlphaOnly(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int rgb) {
+ public void drawGlyph(Font.Glyph source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int rgb) {
cx1 = Math.max(dx, cx1);
cy1 = Math.max(dy, cy1);
- cx2 = Math.min(dx + source.getWidth(), cx2);
- cy2 = Math.min(dy + source.getHeight(), cy2);
+ cx2 = Math.min(dx + source.width, cx2);
+ cy2 = Math.min(dy + source.height, cy2);
if (cx1 >= cx2 || cy1 >= cy2) return;
- slowDrawPicture(source, dx, dy, cx1, cy1, cx2, cy2, rgb, true);
+ slowDrawPicture(((DefaultGlyph)source).getPicture(), dx, dy, cx1, cy1, cx2, cy2, rgb, true);
}
public void drawPicture(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2) {
cx1 = Math.max(dx, cx1);
cy1 = Math.max(dy, cy1);
- cx2 = Math.min(dx + source.getWidth(), cx2);
- cy2 = Math.min(dy + source.getHeight(), cy2);
+ cx2 = Math.min(dx + source.width, cx2);
+ cy2 = Math.min(dy + source.height, cy2);
if (cx1 >= cx2 || cy1 >= cy2) return;
+ ((X11Picture)source).init();
if (((X11Picture)source).doublebuf != null)
fastDrawPicture(source, dx, dy, cx1, cy1, cx2, cy2);
else
}
public synchronized void renderGlyph(Font.Glyph glyph) throws IOException {
- int width = 0;
- int height = 0;
- byte[] data = null;
-
try {
if (loadedStream != glyph.font.res) loadFontByteStream(glyph.font.res);
vm.setUserInfo(2, (int)glyph.c);
glyph.baseline = vm.getUserInfo(10);
glyph.advance = vm.getUserInfo(11);
- width = vm.getUserInfo(6);
- height = vm.getUserInfo(7);
+ glyph.width = vm.getUserInfo(6);
+ glyph.height = vm.getUserInfo(7);
- data = new byte[width * height];
+ glyph.data = new byte[glyph.width * glyph.height];
int addr = vm.getUserInfo(5);
- vm.copyin(addr,data,width*height);
+ vm.copyin(addr, glyph.data, glyph.width * glyph.height);
- if (width == 0 || height == 0) Log.log(Freetype.class, "warning glyph has zero width/height");
- glyph.p = Platform.createAlphaOnlyPicture(data, width, height);
} catch (Exception e) {
Log.log(this, e);
}
// Public Methods /////////////////////////////////////////////////////////
- public GIF() { }
+ private GIF() { }
- public int[] getData() { return data; }
- public int getWidth() { return width; }
- public int getHeight() { return height; }
+ private static Queue instances = new Queue(10);
- /** Processes an image from InputStream is; returns null if there is an error
- @param name A string describing the image; used for error reporting.
- */
- public Picture fromInputStream(InputStream is, String name) {
+ public static void load(InputStream is, Picture p) {
+ GIF g = (GIF)instances.remove();
+ if (g == null) g = new GIF();
try {
- if (is instanceof BufferedInputStream) _in = (BufferedInputStream)is;
- else _in = new BufferedInputStream(is);
- decodeAsBufferedImage(0);
- return Platform.createPicture(data, width, height);
+ g._load(is, p);
} catch (Exception e) {
if (Log.on) Log.log(GIF.class, e);
- return null;
+ return;
}
+ // FIXME: must reset fields
+ // if (instances.size() < 10) instances.append(g);
}
+ private void _load(InputStream is, Picture p) throws IOException {
+ this.p = p;
+ if (is instanceof BufferedInputStream) _in = (BufferedInputStream)is;
+ else _in = new BufferedInputStream(is);
+ decodeAsBufferedImage(0);
+ p.isLoaded = true;
+ p = null;
+ _in = null;
+ }
- // Private Methods /////////////////////////////////////////////////////////
-
- private int[] data = null;
/** Decode a particular frame from the GIF file. Frames must be decoded in order, starting with 0. */
private void decodeAsBufferedImage(int page) throws IOException, IOException {
if (block_identifier != ',') continue;
if (!readLocalImageDescriptor()) throw new IOException("Unexpected EOF(3)");
- data = new int[width * height];
+ p.data = new int[p.width * p.height];
readImage();
// If we did not decode the requested index, need to go on
/** Actually read the image data */
private void readImage()
throws IOException, IOException {
- int len = width;
- int rows = height;
+ int len = p.width;
+ int rows = p.height;
int initialCodeSize;
int v;
int xpos = 0, ypos = 0, pass = 0, i;
if (v < 0) return;
// Finally, we can set a pixel! Joy!
- data[xpos + ypos * width] = cmap[v];
+ p.data[xpos + ypos * p.width] = cmap[v];
xpos++;
}
left = _buf[0] | (_buf[1] << 8);
top = _buf[2] | (_buf[3] << 8);
- width = _buf[4] | (_buf[5] << 8);
- height = _buf[6] | (_buf[7] << 8);
+ p.width = _buf[4] | (_buf[5] << 8);
+ p.height = _buf[6] | (_buf[7] << 8);
packed = _buf[8];
hascmap = (packed & LOCALCOLORMAP) == LOCALCOLORMAP;
cmapsize = 2 << (packed & 0x07);
// Private Data //////////////////////////////////////////////////////////
+ private Picture p;
+
// State management stuff
private int index = -1;
private BufferedInputStream _in = null;
// Local image descriptor contents
private int left = 0;
private int top = 0;
- private int width = 0;
- private int height = 0;
private int cmapsize = 0;
private boolean hascmap = false;
private boolean interlaced = false;
public PNG() { }
+ private static Queue instances = new Queue(10);
+
+ public static void load(InputStream is, Picture p) {
+ PNG g = (PNG)instances.remove();
+ if (g == null) g = new PNG();
+ try {
+ g._load(is, p);
+ } catch (Exception e) {
+ if (Log.on) Log.log(PNG.class, e);
+ return;
+ }
+ // FIXME: must reset fields
+ // if (instances.size() < 10) instances.append(g);
+ }
+
// Public Methods ///////////////////////////////////////////////////////////////////////////////
+ private Picture p;
+
/** process a PNG as an inputstream; returns null if there is an error
@param name A string describing the image, to be used when logging errors
*/
- public Picture fromInputStream(InputStream is, String name) throws IOException {
- underlyingStream = is;
+ private void _load(InputStream is, Picture p) throws IOException {
+ this.p = p;
+ if (is instanceof BufferedInputStream) underlyingStream = (BufferedInputStream)is;
+ else underlyingStream = new BufferedInputStream(is);
target_offset = 0;
inputStream = new DataInputStream(underlyingStream);
// consume the header
if ((inputStream.read() != 137) || (inputStream.read() != 80) || (inputStream.read() != 78) || (inputStream.read() != 71) ||
(inputStream.read() != 13) || (inputStream.read() != 10) || (inputStream.read() != 26) || (inputStream.read() != 10)) {
- Log.log(this, "PNG: error: input file " + name + " is not a PNG file");
+ Log.log(this, "PNG: error: input file is not a PNG file");
data = new int[] { };
- width = height = 0;
- return null;
+ p.width = p.height = 0;
+ return;
}
DONE: while (!error) {
int crc = inputStream.readInt();
needChunkInfo = true;
}
-
- return Platform.createPicture(data, width, height);
+ p.isLoaded = true;
}
// Chunk Handlers ///////////////////////////////////////////////////////////////////////
/** handle data chunk */
private void handleIDAT() throws IOException {
- if (width == -1 || height == -1) throw new IOException("never got image width/height");
+ if (p.width == -1 || p.height == -1) throw new IOException("never got image width/height");
switch (depth) {
case 1: mask = 0x1; break;
case 2: mask = 0x3; break;
if (depth < 8) smask = mask << depth;
else smask = mask << 8;
- int count = width * height;
+ int count = p.width * p.height;
switch (colorType) {
case 0:
private void handleIHDR() throws IOException {
if (headerFound) throw new IOException("Extraneous IHDR chunk encountered.");
if (chunkLength != 13) throw new IOException("IHDR chunk length wrong: " + chunkLength);
- width = inputStream.readInt();
- height = inputStream.readInt();
+ p.width = inputStream.readInt();
+ p.height = inputStream.readInt();
depth = inputStream.read();
colorType = inputStream.read();
compressionMethod = inputStream.read();
int rInc = rowInc[pass];
int cInc = colInc[pass];
int sCol = startingCol[pass];
- int val = (width - sCol + cInc - 1) / cInc;
+ int val = (p.width - sCol + cInc - 1) / cInc;
int samples = val * filterOffset;
int rowSize = (val * bps)>>3;
int sRow = startingRow[pass];
- if (height <= sRow || rowSize == 0) continue;
- int sInc = rInc * width;
+ if (p.height <= sRow || rowSize == 0) continue;
+ int sInc = rInc * p.width;
byte inbuf[] = new byte[rowSize];
int pix[] = new int[rowSize];
int upix[] = null;
int temp[] = new int[rowSize];
int nextY = sRow; // next Y value and number of rows to report to sendPixels
int rows = 0;
- int rowStart = sRow * width;
+ int rowStart = sRow * p.width;
- for (int y = sRow; y < height; y += rInc, rowStart += sInc) {
+ for (int y = sRow; y < p.height; y += rInc, rowStart += sInc) {
rows += rInc;
int rowFilter = dis.read();
dis.readFully(inbuf);
private void blockFill(int rowStart) {
int counter;
- int dw = width;
+ int dw = p.width;
int pass = this.pass;
int w = blockWidth[pass];
int sCol = startingCol[pass];
// Private Data ///////////////////////////////////////////////////////////////////////////////////////
private int target_offset = 0;
- private int width = -1;
- private int height = -1;
private int sigmask = 0xffff;
private Object pixels = null;
private int ipixels[] = null;
import java.util.*;
+// FIXME needs to be a weak hash
+
/**
* A Hash table with a fixed size; drops extraneous elements. Uses
* LRU strategy.
-// Copyright (C) 2002 Adam Megacz <adam@xwt.org> all rights reserved.
+// Copyright (C) 2003 Adam Megacz <adam@xwt.org> all rights reserved.
//
// You may modify, copy, and redistribute this code under the terms of
// the GNU Library Public License version 2.1, with the exception of
* beginning of this character segment, which can be processed in a
* line-by-line fashion due to the above newline restriction.</p>
*/
- public abstract void characters(char[] ch, int start, int length) throws SchemaException;
+ public abstract void characters(char[] ch, int start, int length) throws SchemaException, IOException;
/** Represents a line of ignorable whitespace. */
- public abstract void whitespace(char[] ch, int start, int length) throws SchemaException;
+ public abstract void whitespace(char[] ch, int start, int length) throws SchemaException, IOException;
/** Represents the end of an Element. */
- public abstract void endElement(Element e) throws SchemaException;
+ public abstract void endElement(Element e) throws SchemaException, IOException;
/////////////////////////////////////////////////////////////////////////////////////////////