diff --git a/processing/core/PApplet.java b/processing/core/PApplet.java index 43c0b413a..c94bd5c41 100644 --- a/processing/core/PApplet.java +++ b/processing/core/PApplet.java @@ -2019,7 +2019,7 @@ public class PApplet extends Applet // ------------------------------------------------------------ - // public functions from bagel + // public functions for processing.core public void alpha(int alpha[]) { @@ -2037,7 +2037,7 @@ public class PApplet extends Applet } - public void toGrayscale() { + public void toGrayscale() { g.toGrayscale(); } @@ -2057,29 +2057,19 @@ public class PApplet extends Applet } - public void set(int x, int y, PImage image) { - g.set(x, y, image); - } - - - public void copy(int sx, int sy, int dx, int dy) { - g.copy(sx, sy, dx, dy); - } - - - public void copy(PImage src, int sx, int sy, int dx, int dy) { - g.copy(src, sx, sy, dx, dy); + public void copy(PImage src, int dx, int dy) { + g.copy(src, dx, dy); } public void copy(int sx1, int sy1, int sx2, int sy2, - int dx1, int dy1, int dx2, int dy2) { + int dx1, int dy1, int dx2, int dy2) { g.copy(sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2); } public void copy(PImage src, int sx1, int sy1, int sx2, int sy2, - int dx1, int dy1, int dx2, int dy2) { + int dx1, int dy1, int dx2, int dy2) { g.copy(src, sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2); } @@ -2116,6 +2106,21 @@ public class PApplet extends Applet } + public void smooth() { + g.smooth(); + } + + + public void noSmooth() { + g.noSmooth(); + } + + + public void imageMode(int mode) { + g.imageMode(mode); + } + + public void defaults() { g.defaults(); } @@ -2391,11 +2396,6 @@ public class PApplet extends Applet } - public void imageMode(int mode) { - g.imageMode(mode); - } - - public void image(PImage image, float x1, float y1) { g.image(image, x1, y1); } @@ -2822,16 +2822,6 @@ public class PApplet extends Applet } - public void smooth() { - g.smooth(); - } - - - public void noSmooth() { - g.noSmooth(); - } - - public void hint(int which) { g.hint(which); } diff --git a/processing/core/PConstants.java b/processing/core/PConstants.java index 73672b41e..5b4ae8c7b 100644 --- a/processing/core/PConstants.java +++ b/processing/core/PConstants.java @@ -136,29 +136,29 @@ public interface PConstants { // shape modes - static final int CORNER = 0; - static final int CORNERS = 1; - static final int CENTER_RADIUS = 2; - static final int CENTER_DIAMETER = 3; + static final int CORNER = 0; + static final int CORNERS = 1; + static final int CENTER_RADIUS = 2; + static final int CENTER = 3; // former CENTER_DIAMETER // uv texture orientation modes - static final int NORMAL_SPACE = 0; // 0..1 - static final int IMAGE_SPACE = 1; + static final int NORMAL_SPACE = 0; // 0..1 + static final int IMAGE_SPACE = 1; // text placement modes - static final int SCREEN_SPACE = 2; - static final int OBJECT_SPACE = 3; + static final int SCREEN_SPACE = 2; + static final int OBJECT_SPACE = 3; // text alignment modes - static final int ALIGN_LEFT = 0; - static final int ALIGN_CENTER = 1; - static final int ALIGN_RIGHT = 2; + static final int ALIGN_LEFT = 0; + static final int ALIGN_CENTER = 1; + static final int ALIGN_RIGHT = 2; // stroke modes diff --git a/processing/core/PGraphics.java b/processing/core/PGraphics.java index 5d0372568..01672d5de 100644 --- a/processing/core/PGraphics.java +++ b/processing/core/PGraphics.java @@ -296,7 +296,6 @@ public class PGraphics extends PImage implements PConstants { // ........................................................ - int image_mode = CORNER; int rect_mode = CORNER; int ellipse_mode = CORNER; @@ -3195,7 +3194,7 @@ public class PGraphics extends PImage implements PConstants { int ix2 = image.width; int iy2 = image.height; - if (image_mode == CENTER_DIAMETER) { + if (image_mode == CENTER) { sx1 -= image.width / 2; sy1 -= image.height / 2; } @@ -3355,7 +3354,7 @@ public class PGraphics extends PImage implements PConstants { x1 -= hradius; y1 -= vradius; break; - case CENTER_DIAMETER: + case CENTER: hradius = x2 / 2.0f; vradius = y2 / 2.0f; x2 = x1 + hradius; @@ -3390,7 +3389,7 @@ public class PGraphics extends PImage implements PConstants { switch (ellipse_mode) { case CENTER_RADIUS: break; - case CENTER_DIAMETER: + case CENTER: hradius /= 2f; vradius /= 2f; break; case CORNER: @@ -4273,10 +4272,6 @@ public class PGraphics extends PImage implements PConstants { } - public void imageMode(int mode) { - image_mode = mode; - } - public void image(PImage image, float x1, float y1) { if ((dimensions == 0) && !lighting && !_tint && (image_mode != CENTER_RADIUS)) { @@ -4306,7 +4301,7 @@ public class PGraphics extends PImage implements PConstants { case CORNER: x2 += x1; y2 += y1; break; - case CENTER_DIAMETER: + case CENTER: x2 /= 2f; y2 /= 2f; case CENTER_RADIUS: @@ -5445,20 +5440,6 @@ public class PGraphics extends PImage implements PConstants { } - ////////////////////////////////////////////////////////////// - - // SMOOTHING (ANTIALIASING) - - - public void smooth() { - smooth = true; - } - - public void noSmooth() { - smooth = false; - } - - ////////////////////////////////////////////////////////////// // HINTS diff --git a/processing/core/PImage.java b/processing/core/PImage.java index d914a0bf9..3faa0879a 100644 --- a/processing/core/PImage.java +++ b/processing/core/PImage.java @@ -71,7 +71,8 @@ public class PImage implements PConstants, Cloneable { // would scan line be useful? maybe for pow of 2 gl textures // note! inherited by PGraphics - boolean smooth = false; //true; // for now.. how to fix? + int image_mode = CORNER; + boolean smooth = false; // for gl subclass / hardware accel int cacheIndex; @@ -215,7 +216,7 @@ public class PImage implements PConstants, Cloneable { ////////////////////////////////////////////////////////////// - // GETTING PIXELS + // GET/SET PIXELS public int get(int x, int y) { @@ -245,32 +246,61 @@ public class PImage implements PConstants, Cloneable { } - - ////////////////////////////////////////////////////////////// - - // SETTING PIXELS - - public void set(int x, int y, int c) { if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) return; pixels[y*width + x] = c; } - // not all variables here are needed.. fix it up later - public void set(int x, int y, PImage image) { + ////////////////////////////////////////////////////////////// + + // REPLICATING & BLENDING (AREAS) OF PIXELS + + + /** + * Copies a pixel from place to another (in the same image) + * this function is excluded from using any blend modes because + * it always replaces/overwrites the target pixel value. + */ + /* + public void copy(int sx, int sy, int dx, int dy) { + // In PGraphics, should this copy the zbuffer and stencil too? + if ((sx >= 0) && (sx < width) && (dx >= 0) && (dx < width) && + (sy >= 0) && (sy < height) && (dy >= 0) && (dy < height)) { + pixels[dy * width + dx] = pixels[sy * width + sx]; + } + } + */ + + + /** + * Copies a pixel from place to another (in different images) + * this function is excluded from using any blend modes + * it always replaces/overwrites the target pixel value + */ + /* + public void copy(PImage src, int sx, int sy, int dx, int dy) { + if ((dx >= 0) && (dx < width) && (sx >= 0) && (sx < src.width) && + (dy >= 0) && (dy < height) && (sy >= 0) && (sy < src.height)) { + pixels[dy * width + dx] = src.pixels[sy * src.width + sx]; + } + } + */ + + + public void copy(PImage src, int dx, int dy) { // source int sx = 0; int sy = 0; - int sw = image.width; - int sh = image.height; + int sw = src.width; + int sh = src.height; // target - int tx = x; // < 0 ? 0 : x; - int ty = y; // < 0 ? 0 : y; - int tw = image.width; - int th = image.height; + int tx = dx; // < 0 ? 0 : x; + int ty = dy; // < 0 ? 0 : y; + int tw = width; + int th = height; if (tx < 0) { // say if target x were -3 sx -= tx; // source x -(-3) (or add 3) @@ -296,49 +326,38 @@ public class PImage implements PConstants, Cloneable { } for (int row = sy; row < sy + sh; row++) { - System.arraycopy(image.pixels, row*image.width + sx, - pixels, (y+row)*width + tx, sw); - } - } - - - - ////////////////////////////////////////////////////////////// - - // REPLICATING & BLENDING (AREAS) OF PIXELS - - - // copies a pixel from place to another (in the same image) - // this function is excluded from using any blend modes - // it always replaces/overwrites the target pixel value - - // should this copy the zbuffer and stencil for this pixel? - - public void copy(int sx, int sy, int dx, int dy) { - if ((sx >= 0) && (sx < width) && (dx >= 0) && (dx < width) && - (sy >= 0) && (sy < height) && (dy >= 0) && (dy < height)) { - pixels[dy * width + dx] = pixels[sy * width + sx]; - } - } - - - // copies a pixel from place to another (in different images) - // this function is excluded from using any blend modes - // it always replaces/overwrites the target pixel value - - public void copy(PImage src, int sx, int sy, int dx, int dy) { - if ((dx >= 0) && (dx < width) && (sx >= 0) && (sx < src.width) && - (dy >= 0) && (dy < height) && (sy >= 0) && (sy < src.height)) { - pixels[dy * width + dx] = src.pixels[sy * src.width + sx]; + System.arraycopy(src.pixels, row*src.width + sx, + pixels, (dy+row)*width + tx, sw); } } /** - * Copy things from one area of this image to another area in the same image + * Copy things from one area of this image + * to another area in the same image. */ public void copy(int sx1, int sy1, int sx2, int sy2, - int dx1, int dy1, int dx2, int dy2) { + int dx1, int dy1, int dx2, int dy2) { + switch (image_mode) { + //case CORNERS: + //break; + case CORNER: + sx2 += sx1; sy2 += sy1; + dx2 += dx1; dy2 += dy1; + break; + case CENTER: + sx2 /= 2f; sy2 /= 2f; + dx2 /= 2f; dy2 /= 2f; + break; + case CENTER_RADIUS: + int hr, vr; + hr = sx2; sx2 = sx1 + hr; sx1 -= hr; + vr = sy2; sy2 = sy1 + vr; sy1 -= vr; + hr = dx2; dx2 = dx1 + hr; dx1 -= hr; + vr = dy2; dy2 = dy1 + vr; dy1 -= vr; + break; + } + if (intersect(sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2)) { blit_resize(this.get(sx1, sy1, sx2 - sx1, sy2 - sy1), 0, 0, sx2 - sx1 - 1, sy2 - sy1 - 1, @@ -351,12 +370,32 @@ public class PImage implements PConstants, Cloneable { /** - * Copies area of one image into another PImage object + * Copies area of one image into another PImage object. */ public void copy(PImage src, int sx1, int sy1, int sx2, int sy2, - int dx1, int dy1, int dx2, int dy2) { + int dx1, int dy1, int dx2, int dy2) { + switch (image_mode) { + //case CORNERS: + //break; + case CORNER: + sx2 += sx1; sy2 += sy1; + dx2 += dx1; dy2 += dy1; + break; + case CENTER: + sx2 /= 2f; sy2 /= 2f; + dx2 /= 2f; dy2 /= 2f; + break; + case CENTER_RADIUS: + int hr, vr; + hr = sx2; sx2 = sx1 + hr; sx1 -= hr; + vr = sy2; sy2 = sy1 + vr; sy1 -= vr; + hr = dx2; dx2 = dx1 + hr; dx1 -= hr; + vr = dy2; dy2 = dy1 + vr; dy1 -= vr; + break; + } + blit_resize(src, sx1, sy1, sx2, sy2, - pixels, width, height, dx1, dy1, dx2, dy2, REPLACE); + pixels, width, height, dx1, dy1, dx2, dy2, REPLACE); } @@ -367,7 +406,8 @@ public class PImage implements PConstants, Cloneable { if ((dx >= 0) && (dx < width) && (sx >= 0) && (sx < src.width) && (dy >= 0) && (dy < height) && (sy >= 0) && (sy < src.height)) { pixels[dy * width + dx] = - blendColor(pixels[dy * width + dx], src.pixels[sy * src.width + sx], mode); + blendColor(pixels[dy * width + dx], + src.pixels[sy * src.width + sx], mode); } } @@ -378,12 +418,32 @@ public class PImage implements PConstants, Cloneable { blendColor(pixels[dy * width + dx], pixels[sy * width + sx], mode); } } - + /** * Copy things from one area of this image to another area */ public void blend(int sx1, int sy1, int sx2, int sy2, int dx1, int dy1, int dx2, int dy2, int mode) { + switch (image_mode) { + //case CORNERS: + //break; + case CORNER: + sx2 += sx1; sy2 += sy1; + dx2 += dx1; dy2 += dy1; + break; + case CENTER: + sx2 /= 2f; sy2 /= 2f; + dx2 /= 2f; dy2 /= 2f; + break; + case CENTER_RADIUS: + int hr, vr; + hr = sx2; sx2 = sx1 + hr; sx1 -= hr; + vr = sy2; sy2 = sy1 + vr; sy1 -= vr; + hr = dx2; dx2 = dx1 + hr; dx1 -= hr; + vr = dy2; dy2 = dy1 + vr; dy1 -= vr; + break; + } + if (intersect(sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2)) { blit_resize(this.get(sx1, sy1, sx2 - sx1, sy2 - sy1), 0, 0, sx2 - sx1 - 1, sy2 - sy1 - 1, @@ -400,6 +460,26 @@ public class PImage implements PConstants, Cloneable { */ public void blend(PImage src, int sx1, int sy1, int sx2, int sy2, int dx1, int dy1, int dx2, int dy2, int mode) { + switch (image_mode) { + //case CORNERS: + //break; + case CORNER: + sx2 += sx1; sy2 += sy1; + dx2 += dx1; dy2 += dy1; + break; + case CENTER: + sx2 /= 2f; sy2 /= 2f; + dx2 /= 2f; dy2 /= 2f; + break; + case CENTER_RADIUS: + int hr, vr; + hr = sx2; sx2 = sx1 + hr; sx1 -= hr; + vr = sy2; sy2 = sy1 + vr; sy1 -= vr; + hr = dx2; dx2 = dx1 + hr; dx1 -= hr; + vr = dy2; dy2 = dy1 + vr; dy1 -= vr; + break; + } + blit_resize(src, sx1, sy1, sx2, sy2, pixels, width, height, dx1, dy1, dx2, dy2, mode); } @@ -410,6 +490,11 @@ public class PImage implements PConstants, Cloneable { // COPYING IMAGE DATA + /** + * Duplicate an image, returns new PImage object. + * The pixels[] array for the new object will be unique + * and recopied from the source image. + */ public Object clone() throws CloneNotSupportedException { PImage c = (PImage) super.clone(); @@ -997,5 +1082,20 @@ public class PImage implements PConstants, Cloneable { } } */ + + + public void smooth() { + smooth = true; + } + + public void noSmooth() { + smooth = false; + } + + + public void imageMode(int mode) { + image_mode = mode; + } + } diff --git a/processing/core/preproc.pl b/processing/core/preproc.pl new file mode 100755 index 000000000..2b967f1c4 --- /dev/null +++ b/processing/core/preproc.pl @@ -0,0 +1,125 @@ +#!/usr/bin/perl + +# PGraphics subclasses PImage.. so first get methods from bimage +open(F, "PImage.java") || die $!; +@contents = ; +close(F); + +# next slurp methods from PGraphics +open(F, "PGraphics.java") || die $!; +#@contents = ; +foreach $line () { + # can't remember perl right now.. there must be a better way + @contents[$#contents++] = $line; +} +close(F); + + +open(APPLET, "PApplet.java") || die $!; +@applet = ; +close(APPLET); + + +$insert = 'public functions for processing.core'; + +# an improved version of this would only rewrite if changes made +open(OUT, ">PApplet.new") || die $!; +foreach $line (@applet) { + print OUT $line; + last if ($line =~ /$insert/); +} + + +$comments = 0; + +while ($line = shift(@contents)) { + $decl = ""; + + if ($line =~ /\/\*/) { + $comments++; + } + if ($line =~ /\*\//) { + $comments--; + } + next if ($comments > 0); + + $got_something = 0; # so it's ugly, back off + $got_static = 0; + if ($line =~ /^\s*public ([\w\[\]]+) [a-zA-z_]+\(.*$/) { + $got_something = 1; + } elsif ($line =~ /^\s*public final ([\w\[\]]+) [a-zA-z_]+\(.*$/) { + $got_something = 1; + } elsif ($line =~ /^\s*static public ([\w\[\]]+) [a-zA-z_]+\(.*$/) { + $got_something = 1; + $got_static = 1; + } + # if function is marked "// ignore" then, uh, ignore it. + if (($got_something == 1) && ($line =~ /\/\/ ignore/)) { + $got_something = 0; + } + #if ($line =~ /^\s*public (\w+) [a-zA-z_]+\(.*$/) { + if ($got_something == 1) { + if ($1 ne 'void') { + $returns = 'return'; + } else { + $returns = ''; + } + print OUT "\n\n$line"; + $decl .= $line; + while (!($line =~ /\)/)) { + $line = shift (@contents); + $decl .= $line; + print OUT $line; + } + + $decl =~ /\s(\S+)\(/; + $decl_name = $1; + if ($got_static == 1) { + print OUT " $returns PGraphics.${decl_name}("; + } else { + print OUT " $returns g.${decl_name}("; + } + + $decl =~ s/\s+/ /g; # smush onto a single line + $decl =~ s/^.*\(//; + $decl =~ s/\).*$//; + + $prev = 0; + @parts = split(', ', $decl); + foreach $part (@parts) { + ($the_type, $the_arg) = split(' ', $part); + $the_arg =~ s/[\[\]]//g; + if ($prev != 0) { + print OUT ", "; + } + print OUT "${the_arg}"; + $prev = 1; + } + print OUT ");\n"; + + print OUT " }\n"; #\n"; + } +} +print OUT "}\n"; + +close(OUT); + +$oldguy = join(' ', @applet); + +open(NEWGUY, "PApplet.new") || die $!; +@newbie = ; +$newguy = join(' ', @newbie); +close(NEWGUY); + +if ($oldguy ne $newguy) { + # replace him + print "updating PApplet with PGraphics api changes\n"; + `mv PApplet.new PApplet.java`; +} else { + # just kill the new guy + #print "no changes to applet\n"; + `rm PApplet.new`; +} + +# then do the actual building +#print `perl buzz.pl '${JIKES} -target 1.1 -bootclasspath $extra_classes +D -d classes' $video_flag $sonic_flag $serial_flag $opengl_flag $illustrator_flag $jdk13_flag *.java`;