From ba0fc444b9d55e210facdbfc0032ba8fb76a490a Mon Sep 17 00:00:00 2001 From: benfry Date: Tue, 21 Sep 2004 01:28:12 +0000 Subject: [PATCH] fixup PImage defaults for subclasses (set to RGB). --- core/PApplet.java | 21 ++++++++++----------- core/PGraphics.java | 5 ++++- core/PImage.java | 25 ++++++++++++++++--------- core/todo.txt | 21 +++++++++++++++------ 4 files changed, 45 insertions(+), 27 deletions(-) diff --git a/core/PApplet.java b/core/PApplet.java index 0ab411fa5..1ccb3e6d9 100644 --- a/core/PApplet.java +++ b/core/PApplet.java @@ -1018,17 +1018,6 @@ public class PApplet extends Applet // ------------------------------------------------------------ - /** - * Explicitly exit the applet. Inserted as a call for static - * mode apps, but is generally necessary because apps no longer - * have draw/loop separation. - */ - public void exit() { - stop(); - // TODO if not running as an applet, do a System.exit() here - } - - /** * Function for an applet/application to kill itself and * display an error. Mostly this is here to be improved later. @@ -1055,6 +1044,16 @@ public class PApplet extends Applet } + /** + * Explicitly exit the applet. Inserted as a call for static + * mode apps, but is generally necessary because apps no longer + * have draw/loop separation. + */ + public void exit() { + stop(); + // TODO if not running as an applet, do a System.exit() here + } + // ------------------------------------------------------------ diff --git a/core/PGraphics.java b/core/PGraphics.java index 74bd90f0c..663f9ba58 100644 --- a/core/PGraphics.java +++ b/core/PGraphics.java @@ -321,7 +321,10 @@ public class PGraphics extends PImage /** - * Constructor for the PGraphics object + * Constructor for the PGraphics object. Use this to ensure that + * the defaults get set properly. In a subclass, use this(w, h) + * as the first line of a subclass' constructor to properly set + * the internal fields and defaults. * * @param iwidth viewport width * @param iheight viewport height diff --git a/core/PImage.java b/core/PImage.java index 7465718e0..c7dcf713d 100644 --- a/core/PImage.java +++ b/core/PImage.java @@ -69,8 +69,11 @@ import java.io.*; */ public class PImage implements PConstants, Cloneable { - // note that RGB images still require 0xff in the high byte - // because of how they'll be manipulated by other functions + /** + * Format for this image, one of RGB, RGBA or ALPHA. + * note that RGB images still require 0xff in the high byte + * because of how they'll be manipulated by other functions + */ public int format; public int pixels[]; @@ -81,7 +84,7 @@ public class PImage implements PConstants, Cloneable { int image_mode = CORNER; boolean smooth = false; - // for gl subclass / hardware accel + /** for gl subclass / hardware accel */ public int cacheIndex; // private fields @@ -97,21 +100,25 @@ public class PImage implements PConstants, Cloneable { static final int PREC_MAXVAL = PRECISIONF-1; static final int PREC_ALPHA_SHIFT = 24-PRECISIONB; static final int PREC_RED_SHIFT = 16-PRECISIONB; - - + + /** - * Constructor required by java compiler for subclasses. + * Create an empty image object, set its format to RGB. + * The pixel array is not allocated. */ - public PImage() { } + public PImage() { + format = RGB; // makes sure that this guy is useful + cacheIndex = -1; + } /** - * Create a new (transparent) image of a specific size. + * Create a new RGB (alpha ignored) image of a specific size. * All pixels are set to zero, meaning black, but since the * alpha is zero, it will be transparent. */ public PImage(int width, int height) { - setup(width, height, RGBA); + setup(width, height, RGB); //this(new int[width * height], width, height, RGBA); // toxi: is it maybe better to init the image with max alpha enabled? //for(int i=0; i