fixing up get and set with setImpl

This commit is contained in:
benfry
2005-04-07 06:33:13 +00:00
parent 9121904ff7
commit 2c411f5dcd
5 changed files with 108 additions and 308 deletions

View File

@@ -80,9 +80,14 @@ public class PApplet extends Applet
// figure out which operating system
// this has to be first, since editor needs to know
if (System.getProperty("mrj.version") != null) { // running on a mac
platform = (platformName.equals("Mac OS X")) ?
MACOSX : MACOS9;
if (platformName.toLowerCase().indexOf("mac") != -1) {
// can only check this property if running on a mac
// on a pc it throws a security exception and kills the applet
// (but on the mac it does just fine)
if (System.getProperty("mrj.version") != null) { // running on a mac
platform = (platformName.equals("Mac OS X")) ?
MACOSX : MACOS9;
}
} else {
String osname = System.getProperty("os.name");
@@ -4968,9 +4973,9 @@ v PApplet.this.stop();
}
public void set(int x1, int y1, PImage image) {
if (recorder != null) recorder.set(x1, y1, image);
g.set(x1, y1, image);
public void set(int dx, int dy, PImage src) {
if (recorder != null) recorder.set(dx, dy, src);
g.set(dx, dy, src);
}

View File

@@ -185,24 +185,6 @@ public class PGraphics2 extends PGraphics {
vertices[vertexCount - 1][MY],
vertices[vertexCount - 3][MX],
vertices[vertexCount - 3][MY]);
/*
if (vertexCount == 3) {
triangle(vertices[0][MX], vertices[0][MY],
vertices[1][MX], vertices[1][MY],
x, y);
} else if (vertexCount > 3) {
gpath = new GeneralPath();
// when vertexCount == 4, draw an un-closed triangle
// for indices 2, 3, 1
gpath.moveTo(vertices[vertexCount - 2][MX],
vertices[vertexCount - 2][MY]);
gpath.lineTo(vertices[vertexCount - 1][MX],
vertices[vertexCount - 1][MY]);
gpath.lineTo(vertices[vertexCount - 3][MX],
vertices[vertexCount - 3][MY]);
draw_shape(gpath);
}
*/
}
break;
@@ -216,7 +198,7 @@ public class PGraphics2 extends PGraphics {
// when vertexCount > 3, draw an un-closed triangle
// for indices 0 (center), previous, current
gpath.moveTo(vertices[0][MX],
vertices[0][MY]);
vertices[0][MY]);
gpath.lineTo(vertices[vertexCount - 2][MX],
vertices[vertexCount - 2][MY]);
gpath.lineTo(x, y);
@@ -241,12 +223,6 @@ public class PGraphics2 extends PGraphics {
// | | |
// 1---3---5
if ((vertexCount >= 4) && ((vertexCount % 2) == 0)) {
//if (vertexCount == 4) {//
// note difference in winding order:
//quad(vertices[0][MX], vertices[0][MY],
// vertices[2][MX], vertices[2][MY],
// x, y,
// vertices[1][MX], vertices[1][MY]);
quad(vertices[vertexCount - 4][MX],
vertices[vertexCount - 4][MY],
vertices[vertexCount - 2][MX],
@@ -254,34 +230,14 @@ public class PGraphics2 extends PGraphics {
x, y,
vertices[vertexCount - 3][MX],
vertices[vertexCount - 3][MY]);
/*
} else if ((vertexCount > 4) && ((vertexCount % 2) == 0)) {
gpath = new GeneralPath();
// when vertexCount == 6, draw an un-closed triangle
// for indices 2, 4, 5, 3
gpath.moveTo(vertices[vertexCount - 4][MX],
vertices[vertexCount - 4][MY]);
gpath.lineTo(vertices[vertexCount - 2][MX],
vertices[vertexCount - 2][MY]);
gpath.lineTo(x, y);
gpath.lineTo(vertices[vertexCount - 3][MX],
vertices[vertexCount - 3][MY]);
draw_shape(gpath);
*/
}
break;
case POLYGON:
//case CONCAVE_POLYGON:
//case CONVEX_POLYGON:
//if (vertexCount == 1) {
if (gpath == null) {
//System.out.println("starting poly path " + x + " " + y);
gpath = new GeneralPath();
gpath.moveTo(x, y);
} else {
//System.out.println("continuing poly path " + x + " " + y);
gpath.lineTo(x, y);
}
break;
@@ -292,7 +248,6 @@ public class PGraphics2 extends PGraphics {
public void bezierVertex(float x1, float y1,
float x2, float y2,
float x3, float y3) {
//if (vertexCount == 0) {
if (gpath == null) {
throw new RuntimeException("Must call vertex() at least once " +
"before using bezierVertex()");
@@ -385,9 +340,8 @@ public class PGraphics2 extends PGraphics {
gpath = null;
}
public void endShape() {
//System.out.println("endShape");
public void endShape() {
switch (shape) {
case LINE_STRIP:
stroke_shape(gpath);
@@ -399,14 +353,10 @@ public class PGraphics2 extends PGraphics {
break;
case POLYGON:
//case CONCAVE_POLYGON:
//case CONVEX_POLYGON:
//System.out.println("finishing polygon");
gpath.closePath();
draw_shape(gpath);
break;
}
shape = 0;
}
@@ -424,7 +374,6 @@ public class PGraphics2 extends PGraphics {
protected void stroke_shape(Shape s) {
if (stroke) {
//System.out.println("stroking shape");
g2.setColor(strokeColorObject);
g2.draw(s);
}
@@ -432,12 +381,10 @@ public class PGraphics2 extends PGraphics {
protected void draw_shape(Shape s) {
if (fill) {
//System.out.println("filling shape");
g2.setColor(fillColorObject);
g2.fill(s);
}
if (stroke) {
//System.out.println("stroking shape");
g2.setColor(strokeColorObject);
g2.draw(s);
}
@@ -489,54 +436,11 @@ public class PGraphics2 extends PGraphics {
protected void rectImpl(float x1, float y1, float x2, float y2) {
/*
switch (rectMode) {
case CORNERS:
rect.setFrameFromDiagonal(x1, y1, x2, y2);
break;
case CORNER:
rect.setFrame(x1, y1, x2, y2);
break;
case CENTER_RADIUS:
rect.setFrame(x1 - x2, y1 - y2, x1 + x2, y1 + y2);
break;
case CENTER:
rect.setFrame(x1 - x2/2.0f, y1 - y2/2.0f, x1 + x2/2.0f, y1 + y2/2.0f);
break;
}
*/
rect.setFrame(x1, y1, x2-x1, y2-y1);
draw_shape(rect);
}
/*
public void ellipse(float a, float b, float c, float d) {
float x = a;
float y = b;
float w = c;
float h = d;
if (ellipseMode == CORNERS) {
w = c - a;
h = d - b;
} else if (ellipseMode == CENTER_RADIUS) {
x = a - c;
y = b - d;
w = c * 2;
h = d * 2;
} else if (ellipseMode == CENTER) {
x = a - c/2f;
y = b - d/2f;
}
ellipse.setFrame(x, y, w, h);
draw_shape(ellipse);
}
*/
protected void ellipseImpl(float x, float y, float w, float h) {
ellipse.setFrame(x, y, w, h);
draw_shape(ellipse);
@@ -557,18 +461,10 @@ public class PGraphics2 extends PGraphics {
stop = -stop * RAD_TO_DEG;
// ok to do this because already checked for NaN
//while (start < 0) start += 360;
//while (stop < 0) stop += 360;
while (start < 0) {
start += 360;
stop += 360;
}
/*
while (stop < 0) {
start += 360;
stop += 360;
}
*/
if (start > stop) {
float temp = start;
start = stop;
@@ -577,22 +473,6 @@ public class PGraphics2 extends PGraphics {
}
float span = stop - start;
/*
float span = stop - start;
start -= span;
start *= RAD_TO_DEG;
span *= RAD_TO_DEG;
*/
//start %= 360;
//System.out.println(RAD_TO_DEG*start + " " + RAD_TO_DEG*span);
//System.out.println(start + " " + span);
// start is int proper place, but the stop is the wrong way
//float stop = start;
//float start =
// stroke as Arc2D.OPEN, fill as Arc2D.PIE
if (fill) {
//System.out.println("filla");
@@ -610,46 +490,16 @@ public class PGraphics2 extends PGraphics {
//////////////////////////////////////////////////////////////
/*
public void bezier(float x1, float y1,
float x2, float y2,
float x3, float y3,
float x4, float y4) {
GeneralPath gp = new GeneralPath();
gp.moveTo(x1, y1);
gp.curveTo(x2, y2, x3, y3, x4, y4);
gp.closePath();
draw_shape(gp);
}
*/
/** Ignored (not needed) in Java 2D. */
public void bezierDetail(int detail) {
// ignored in java2d
}
/** Ignored (not needed) in Java 2D. */
public void curveDetail(int detail) {
// ignored in java2d
}
/*
public void curveTightness(float tightness) {
// TODO
}
public void curve(float x1, float y1,
float x2, float y2,
float x3, float y3,
float x4, float y4) {
// TODO need inverse catmull rom to bezier matrix
}
*/
//////////////////////////////////////////////////////////////
@@ -659,9 +509,6 @@ public class PGraphics2 extends PGraphics {
int u1, int v1, int u2, int v2) {
if (who.cache == null) {
who.cache = new ImageCache(who);
//who.cache = new BufferedImage(who.width, who.height,
// BufferedImage.TYPE_INT_ARGB);
who.updatePixels(); // mark the whole thing for update
}
@@ -680,28 +527,6 @@ public class PGraphics2 extends PGraphics {
who.modified = false;
}
/*
if (who.modified) {
((ImageCache) who.cache).update();
// update the sub-portion of the image as necessary
BufferedImage bi = (BufferedImage) who.cache;
bi.setRGB(who.mx1,
who.my1,
who.mx2 - who.mx1,
who.my2 - who.my1,
who.pixels,
who.my1*who.width + who.mx1, // offset for copy
who.width); // scan size
//who.pixelsUpdated();
who.modified = false;
}
*/
//int x2 = (int) (x + w);
//int y2 = (int) (y + h);
g2.drawImage(((ImageCache) who.cache).image,
//(int) x, (int) y, x2, y2,
(int) x1, (int) y1, (int) x2, (int) y2,
@@ -818,21 +643,6 @@ public class PGraphics2 extends PGraphics {
// finally, do a setRGB based on tintedPixels
image.setRGB(0, 0, source.width, source.height,
tintedPixels, 0, source.width);
/*
int argb2 = tint ? tintColor : 0xFFFFFFFF;
int a2 = (tintColor >> 24) & 0xff;
int r2 = (tintColor >> 16) & 0xff;
int g2 = (tintColor >> 8) & 0xff;
int b2 = (tintColor) & 0xff;
// multiply each of the color components into tintedPixels
for (int i = 0; i < tintedPixels.length; i++) {
int argb1 = source.pixels[i];
int a1 = (argb1 >> 24) & 0xff;
int r1 = (argb1 >> 16) & 0xff;
int g1 = (argb1 >> 8) & 0xff;
int b1 = (argb1) & 0xff;
*/
}
}
}
@@ -993,17 +803,8 @@ public class PGraphics2 extends PGraphics {
if ((image.format != RGB) && (image.format != ARGB)) {
throw new RuntimeException("background images should be RGB or ARGB");
}
// make sure it's been properly updated
//check_image_cache(image);
// blit image to the screen
//g2.drawImage((BufferedImage) image.cache, 0, 0, null);
//graphics.drawImage((BufferedImage) image.cache, 0, 0, null);
// draw the image to screen without any transformations
set(0, 0, image);
//push();
//resetMatrix();
//imageImpl(image, 0, 0, width, height, 0, 0, width, height);
//pop();
}
@@ -1015,7 +816,6 @@ public class PGraphics2 extends PGraphics {
* even if noDepth() was called before draw() exited.
*/
public void clear() {
//System.out.println("clearing " + PApplet.hex(backgroundColor));
g2.setColor(new Color(backgroundColor));
g2.fillRect(0, 0, width, height);
}
@@ -1086,7 +886,6 @@ public class PGraphics2 extends PGraphics {
public PImage get(int x, int y, int w, int h) {
if (imageMode == CORNERS) { // if CORNER, do nothing
//x2 += x1; y2 += y1;
// w/h are x2/y2 in this case, bring em down to size
w = (w - x);
h = (h - x);
@@ -1112,22 +911,14 @@ public class PGraphics2 extends PGraphics {
/**
* This is used to both set the pixels[] array so that it can be
* manipulated, and it also returns a PImage object that can be
* messed with directly.
* Grab a copy of the current pixel buffer.
*/
/*
public PImage get() {
//PImage outgoing = new PImage(width, height);
// int[] getRGB(int startX, int startY, int w, int h,
// int[] rgbArray, int offset, int scansize)
if (pixels == null) {
pixels = new int[width * height];
}
((BufferedImage) image).getRGB(0, 0, width, height, pixels, 0, width);
return new PImage(pixels, width, height, RGB);
PImage outgoing = new PImage(width, height);
((BufferedImage) image).getRGB(0, 0, width, height,
outgoing.pixels, 0, width);
return outgoing;
}
*/
public void set(int x, int y, int argb) {
@@ -1136,14 +927,43 @@ public class PGraphics2 extends PGraphics {
}
// fully debugged
/*
public void set(int dx, int dy, PImage src) {
push();
imageImpl(src, 0, 0, width, height, 0, 0, width, height);
resetMatrix();
pop();
//loadPixels();
//super.set(dx, dy, src);
//updatePixels();
int sx = 0;
int sy = 0;
int sw = src.width;
int sh = src.height;
if (dx < 0) { // off left edge
sx -= dx;
sw += dx;
dx = 0;
}
if (dy < 0) { // off top edge
sy -= dy;
sh += dy;
dy = 0;
}
if (dx + sw > width) { // off right edge
sw = width - dx;
}
if (dy + sh > height) { // off bottom edge
sh = height - dy;
}
//System.out.println(dx + " " + dy + " " +
// sx + " " + sy + " " + sw + " " + sh + " " +
// src.pixels + " " + 0 + " " + src.width);
BufferedImage bi = (BufferedImage) image;
bi.setRGB(dx, dy, sw, sh, src.pixels, sy*src.width + sx, src.width);
}
*/
protected void setImpl(int dx, int dy, int sx, int sy, int sw, int sh,
PImage src) {
BufferedImage bi = (BufferedImage) image;
bi.setRGB(dx, dy, sw, sh, src.pixels, sy*src.width + sx, src.width);
}

View File

@@ -466,92 +466,49 @@ public class PImage implements PConstants, Cloneable {
}
/*
// properly debugged version from copy()
// in case the below one doesn't work
public void set(int dx, int dy, PImage src) {
// source
int sx = 0;
int sy = 0;
int sw = src.width;
int sh = src.height;
// target
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)
sw += tx; // source width -3
tw += tx; // target width -3
tx = 0; // target x is zero (upper corner)
if (dx < 0) { // off left edge
sx -= dx;
sw += dx;
dx = 0;
}
if (ty < 0) {
sy -= ty;
sh += ty;
th += ty;
ty = 0;
if (dy < 0) { // off top edge
sy -= dy;
sh += dy;
dy = 0;
}
if (tx + tw > width) {
int extra = (tx + tw) - width;
sw -= extra;
tw -= extra;
if (dx + sw > width) { // off right edge
sw = width - dx;
}
if (ty + th > height) {
int extra = (ty + th) - height;
sh -= extra;
sw -= extra;
if (dy + sh > height) { // off bottom edge
sh = height - dy;
}
for (int row = sy; row < sy + sh; row++) {
System.arraycopy(src.pixels, row*src.width + sx,
pixels, (dy+row)*width + tx, sw);
}
// this could be nonexistant
if ((sw <= 0) || (sh <= 0)) return;
setImpl(dx, dy, sx, sy, sw, sh, src);
}
*/
public void set(int x1, int y1, PImage image) {
int x2 = x1 + image.width;
int y2 = y1 + image.height;
/**
* Internal function to actually handle setting a block of pixels that
* has already been properly cropped from the image to a valid region.
*/
protected void setImpl(int dx, int dy, int sx, int sy, int sw, int sh,
PImage src) {
int srcOffset = sy * src.width + sx;
int dstOffset = dy * width + dx;
// off to the top and/or left
if ((x2 < 0) || (y2 < 0)) return;
int ix1 = 0;
int iy1 = 0;
int ix2 = image.width;
int iy2 = image.height;
if (x1 < 0) { // off left edge
ix1 += -x1;
x1 = 0;
}
if (y1 < 0) { // off top edge
iy1 += - y1;
y1 = 0;
}
if (x2 >= width) { // off right edge
ix2 -= x2 - width;
x2 = width;
}
if (y2 >= height) { // off bottom edge
iy2 -= y2 - height;
y2 = height;
}
int src = iy1*image.width + ix1;
int dest = y1*width + x1;
int len = x2 - x1;
for (int y = y1; y < y2; y++) {
//for (int x = x1; x < x2; x++) {
System.arraycopy(image.pixels, src, pixels, dest, len);
src += len;
dest += len;
for (int y = sy; y < sy + sh; y++) {
System.arraycopy(src.pixels, srcOffset, pixels, dstOffset, sw);
srcOffset += src.width;
dstOffset += width;
}
}

View File

@@ -1,5 +1,20 @@
0083 core
X fix double key events
X fix mrj.version security error on the pc
X set() fixes for PGraphics2 and setImpl inside PGraphics
_ make get/getImpl for PGraphics/PGraphics2
_ make sure there's a loadPixels/updatePixels in PGraphics2
_ rewrite getImpl/setImpl inside opengl
_ make screen space fonts use get/set as well?
_ too much to debug on their own
_ get/set doesn't use tint at all
_ apply tint() to textures as well
_ otherwise no good way to color textures
_ textMode(SCREEN) having issues
_ fix bezierVertex() for newer api
@@ -34,9 +49,6 @@ X is it because the lock was taken off (g) in PApplet?
_ don't let users on < 1.3 load JAVA2D, or < 1.4 load OPENGL
_ apply tint() to textures as well
_ otherwise no good way to color textures
_ cellular automata examples broken
_ gl smoothing.. how to disable polygon but keep line enabled
@@ -206,6 +218,9 @@ _ although the images aren't populated
_ until a P2D/P3D/OPENGL tries to draw them, which triggers it
_ but if PGraphics2, just uses the built-in font
_ how does ftgl handle tesselation? will our tesselator just work?
_ main code is in FTVectoriser
_ uses gluTessBeginContour and gluTessEndContour
_ and then does 5 step sizes for each curveto
_ createFont() also works for font names and just creating them
_ if font name doesn't end with otf or ttf, then tries to create it
_ illustrator api can get the ps name from the java font name

View File

@@ -1,5 +1,8 @@
0083 pde
_ why is gl being added on export, no matter what? or is it?
_ get both versions of size() properly detected on export
_ external apps don't stop at all when 'stop' is hit
_ worker thread is halting the app ala code folder bug
_ could this be dealt with by using nio?
@@ -14,7 +17,7 @@ _ external apps also seem to not do newlines properly on exceptions
_ appendText launches a new thread for every blip of text
_ this is totally wrong and really horks things
_ fishwick library export stuff
_ fishwick library export duplication stuff
_ make a linux version
_ need to fix up the make/dist scripts for linux