mirror of
https://github.com/processing/processing4.git
synced 2026-06-08 16:40:46 +02:00
fixing the f-ers
This commit is contained in:
+7
-3
@@ -937,6 +937,7 @@ public class PGraphics extends PImage implements PConstants {
|
||||
float r1, float g1, float b1, float a1,
|
||||
float ox2, float oy2,
|
||||
float r2, float g2, float b2, float a2) {
|
||||
/*
|
||||
spolygon.interpARGB = (r1 != r2) || (g1 != g2) || (b1 != b2) || (a1 != a2);
|
||||
spolygon.interpZ = false;
|
||||
|
||||
@@ -987,6 +988,7 @@ public class PGraphics extends PImage implements PConstants {
|
||||
svertex[A] = a2;
|
||||
|
||||
spolygon.render();
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@@ -996,6 +998,7 @@ public class PGraphics extends PImage implements PConstants {
|
||||
float r1, float g1, float b1,
|
||||
float x2, float y2, float z2,
|
||||
float r2, float g2, float b2) {
|
||||
/*
|
||||
spolygon.interpARGB = (r1 != r2) || (g1 != g2) || (b1 != b2);
|
||||
spolygon.interpZ = true;
|
||||
|
||||
@@ -1048,6 +1051,7 @@ public class PGraphics extends PImage implements PConstants {
|
||||
svertex[B] = b2;
|
||||
|
||||
spolygon.render();
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@@ -3274,11 +3278,11 @@ public class PGraphics extends PImage implements PConstants {
|
||||
*/
|
||||
public void background(PImage image) {
|
||||
if ((image.width != width) || (image.height != height)) {
|
||||
die("background image must be the same size " +
|
||||
"as your application");
|
||||
throw new RuntimeException("background image must be " +
|
||||
"the same size as your application");
|
||||
}
|
||||
if ((image.format != RGB) && (image.format != ARGB)) {
|
||||
die("background images should be RGB or ARGB");
|
||||
throw new RuntimeException("background images should be RGB or ARGB");
|
||||
}
|
||||
|
||||
// blit image to the screen
|
||||
|
||||
+25
-24
@@ -531,7 +531,7 @@ public class PGraphics2 extends PGraphics {
|
||||
x1 -= image.width /2f;
|
||||
y1 -= image.height / 2f;
|
||||
}
|
||||
check_image_cache();
|
||||
check_image_cache(image);
|
||||
graphics.drawImage((Image) image.cache,
|
||||
(int)x1, (int)y1, (int)x2, (int)y2,
|
||||
(int)u1, (int)v1, (int)u2, (int)v2,
|
||||
@@ -539,24 +539,24 @@ public class PGraphics2 extends PGraphics {
|
||||
}
|
||||
|
||||
|
||||
protected void check_image_cache(PImage what) {
|
||||
if (image.cache == null) {
|
||||
cache = new BufferedImage(image.width, image.height,
|
||||
protected void check_image_cache(PImage who) {
|
||||
if (who.cache == null) {
|
||||
cache = new BufferedImage(who.width, who.height,
|
||||
BufferedImage.TYPE_INT_ARGB);
|
||||
image.modified(); // mark the whole thing for update
|
||||
who.modified(); // mark the whole thing for update
|
||||
}
|
||||
|
||||
if (image.modified) {
|
||||
if (who.modified) {
|
||||
// update the sub-portion of the image as necessary
|
||||
BufferedImage bi = (BufferedImage) image.cache;
|
||||
BufferedImage bi = (BufferedImage) who.cache;
|
||||
|
||||
bi.setRGB(image.mx1, image.my1,
|
||||
image.mx2 - image.mx1 + 1,
|
||||
image.my2 - image.my1 + 1,
|
||||
image.pixels,
|
||||
image.my1*image.width + image.mx1, // offset for copy
|
||||
image.width); // scan size
|
||||
image.resetModified();
|
||||
bi.setRGB(who.mx1, who.my1,
|
||||
who.mx2 - who.mx1 + 1,
|
||||
who.my2 - who.my1 + 1,
|
||||
who.pixels,
|
||||
who.my1*who.width + who.mx1, // offset for copy
|
||||
who.width); // scan size
|
||||
who.resetModified();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -626,8 +626,8 @@ public class PGraphics2 extends PGraphics {
|
||||
|
||||
public void push() {
|
||||
if (transformCount == transformStack.length) {
|
||||
die("push() cannot use push more than " +
|
||||
transformStack.length + " times");
|
||||
throw new RuntimeException("push() cannot use push more than " +
|
||||
transformStack.length + " times");
|
||||
}
|
||||
transformStack[transformCount] = graphics.getTransform();
|
||||
transformCount++;
|
||||
@@ -636,7 +636,7 @@ public class PGraphics2 extends PGraphics {
|
||||
|
||||
public void pop() {
|
||||
if (transformCount == 0) {
|
||||
die("missing a pop() to go with that push()");
|
||||
throw new RuntimeException("missing a pop() to go with that push()");
|
||||
}
|
||||
transformCount--;
|
||||
graphics.setTransform(transformStack[transformCount]);
|
||||
@@ -650,7 +650,7 @@ public class PGraphics2 extends PGraphics {
|
||||
|
||||
public void applyMatrix(float n00, float n01, float n02,
|
||||
float n10, float n11, float n12) {
|
||||
graphics.transform(new AffineTransform(n00, n10, n01, n11, n02, n22));
|
||||
graphics.transform(new AffineTransform(n00, n10, n01, n11, n02, n12));
|
||||
}
|
||||
|
||||
|
||||
@@ -759,18 +759,18 @@ public class PGraphics2 extends PGraphics {
|
||||
|
||||
public void background(PImage image) {
|
||||
if ((image.width != width) || (image.height != height)) {
|
||||
die("background image must be the same size " +
|
||||
"as your application");
|
||||
throw new RuntimeException("background image must be " +
|
||||
"the same size as your application");
|
||||
}
|
||||
if ((image.format != RGB) && (image.format != ARGB)) {
|
||||
die("background images should be RGB or 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
|
||||
graphics.drawImage((BufferedImage) image.cache, 0, 0);
|
||||
graphics.drawImage((BufferedImage) image.cache, 0, 0, null);
|
||||
}
|
||||
|
||||
|
||||
@@ -811,13 +811,14 @@ public class PGraphics2 extends PGraphics {
|
||||
|
||||
|
||||
public int get(int x, int y) {
|
||||
((BufferedImage) image).getRGB(x, y);
|
||||
return ((BufferedImage) image).getRGB(x, y);
|
||||
}
|
||||
|
||||
|
||||
public PImage get(int x, int y, int w, int h) {
|
||||
PImage output = new PImage(w, h);
|
||||
((BufferedImage) image).getRGB(x, y, w, h, output.pixels, 0, width);
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
@@ -881,7 +882,7 @@ public class PGraphics2 extends PGraphics {
|
||||
if (pixels == null) {
|
||||
pixels = new int[width * height];
|
||||
}
|
||||
image.getRGB(0, 0, width, height, pixels, 0, width);
|
||||
((BufferedImage) image).getRGB(0, 0, width, height, pixels, 0, width);
|
||||
return new PImage(pixels, width, height, RGB);
|
||||
}
|
||||
|
||||
|
||||
+128
-118
@@ -26,9 +26,9 @@
|
||||
package processing.core;
|
||||
|
||||
//import java.applet.*;
|
||||
//import java.awt.*;
|
||||
import java.awt.*;
|
||||
//import java.awt.event.*;
|
||||
//import java.awt.image.*;
|
||||
import java.awt.image.*;
|
||||
//import java.io.*;
|
||||
|
||||
public class PGraphics3 extends PGraphics {
|
||||
@@ -94,7 +94,7 @@ public class PGraphics3 extends PGraphics {
|
||||
protected int vertex_start;
|
||||
|
||||
// i think vertex_end is actually the last vertex in the current shape
|
||||
// and is separate from vertex_count for occasions where drawing happens
|
||||
// and is separate from vertexCount for occasions where drawing happens
|
||||
// on endFrame with all the triangles being depth sorted
|
||||
protected int vertex_end;
|
||||
|
||||
@@ -124,6 +124,9 @@ public class PGraphics3 extends PGraphics {
|
||||
public int triangles[][] = new int[DEFAULT_TRIANGLES][TRIANGLE_FIELD_COUNT];
|
||||
public int triangleCount; // total number of triangles
|
||||
|
||||
// cheap picking someday
|
||||
int shape_index;
|
||||
|
||||
// ........................................................
|
||||
|
||||
/**
|
||||
@@ -174,6 +177,20 @@ public class PGraphics3 extends PGraphics {
|
||||
public PGraphics3() { }
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for the PGraphics3 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
|
||||
*/
|
||||
public PGraphics3(int iwidth, int iheight) {
|
||||
resize(iwidth, iheight);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called in repsonse to a resize event, handles setting the
|
||||
* new width and height internally, as well as re-allocating
|
||||
@@ -307,16 +324,21 @@ public class PGraphics3 extends PGraphics {
|
||||
public void beginShape(int kind) {
|
||||
shape = kind;
|
||||
|
||||
shape_index = shape_index + 1;
|
||||
if (shape_index == -1) {
|
||||
shape_index = 0;
|
||||
}
|
||||
|
||||
if (hints[DEPTH_SORT]) {
|
||||
// continue with previous vertex, line and triangle count
|
||||
// all shapes are rendered at endFrame();
|
||||
vertex_start = vertex_count;
|
||||
vertex_start = vertexCount;
|
||||
vertex_end = 0;
|
||||
|
||||
} else {
|
||||
// reset vertex, line and triangle information
|
||||
// every shape is rendered at endShape();
|
||||
vertex_count = 0;
|
||||
vertexCount = 0;
|
||||
if (line != null) line.reset(); // necessary?
|
||||
lineCount = 0;
|
||||
pathCount = 0;
|
||||
@@ -325,12 +347,7 @@ public class PGraphics3 extends PGraphics {
|
||||
}
|
||||
textureImage = null;
|
||||
|
||||
spline_vertex_index = 0;
|
||||
spline_vertices_flat = true;
|
||||
|
||||
//strokeChanged = false;
|
||||
//fillChanged = false;
|
||||
//normalChanged = false;
|
||||
splineVertexCount = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -358,20 +375,20 @@ public class PGraphics3 extends PGraphics {
|
||||
|
||||
|
||||
protected void setup_vertex(float x, float y, float z) {
|
||||
if (vertex_count == vertices.length) {
|
||||
float temp[][] = new float[vertex_count<<1][VERTEX_FIELD_COUNT];
|
||||
System.arraycopy(vertices, 0, temp, 0, vertex_count);
|
||||
if (vertexCount == vertices.length) {
|
||||
float temp[][] = new float[vertexCount<<1][VERTEX_FIELD_COUNT];
|
||||
System.arraycopy(vertices, 0, temp, 0, vertexCount);
|
||||
vertices = temp;
|
||||
message(CHATTER, "allocating more vertices " + vertices.length);
|
||||
}
|
||||
float vertex[] = vertices[vertex_count++];
|
||||
float vertex[] = vertices[vertexCount++];
|
||||
|
||||
//if (polygon.redundantVertex(x, y, z)) return;
|
||||
|
||||
// user called vertex(), so that invalidates anything queued
|
||||
// up for curve vertices. if this is internally called by
|
||||
// spline_segment, then spline_vertex_index will be saved and restored.
|
||||
spline_vertex_index = 0;
|
||||
// spline_segment, then splineVertexCount will be saved and restored.
|
||||
splineVertexCount = 0;
|
||||
|
||||
vertex[MX] = x;
|
||||
vertex[MY] = y;
|
||||
@@ -439,19 +456,19 @@ public class PGraphics3 extends PGraphics {
|
||||
protected void spline_vertex(float x, float y, float z, boolean bezier) {
|
||||
// allocate space for the spline vertices
|
||||
// to improve processing applet load times, don't allocate until actual use
|
||||
if (spline_vertex == null) {
|
||||
spline_vertex = new float[SPLINE_VERTEX_ALLOC][VERTEX_FIELD_COUNT];
|
||||
if (splineVertices == null) {
|
||||
splineVertices = new float[DEFAULT_SPLINE_VERTICES][VERTEX_FIELD_COUNT];
|
||||
}
|
||||
|
||||
// if more than 128 points, shift everything back to the beginning
|
||||
if (spline_vertex_index == SPLINE_VERTEX_ALLOC) {
|
||||
System.arraycopy(spline_vertex[SPLINE_VERTEX_ALLOC-3], 0,
|
||||
spline_vertex[0], 0, VERTEX_FIELD_COUNT);
|
||||
System.arraycopy(spline_vertex[SPLINE_VERTEX_ALLOC-2], 0,
|
||||
spline_vertex[1], 0, VERTEX_FIELD_COUNT);
|
||||
System.arraycopy(spline_vertex[SPLINE_VERTEX_ALLOC-1], 0,
|
||||
spline_vertex[2], 0, VERTEX_FIELD_COUNT);
|
||||
spline_vertex_index = 3;
|
||||
if (splineVertexCount == DEFAULT_SPLINE_VERTICES) {
|
||||
System.arraycopy(splineVertices[DEFAULT_SPLINE_VERTICES-3], 0,
|
||||
splineVertices[0], 0, VERTEX_FIELD_COUNT);
|
||||
System.arraycopy(splineVertices[DEFAULT_SPLINE_VERTICES-2], 0,
|
||||
splineVertices[1], 0, VERTEX_FIELD_COUNT);
|
||||
System.arraycopy(splineVertices[DEFAULT_SPLINE_VERTICES-1], 0,
|
||||
splineVertices[2], 0, VERTEX_FIELD_COUNT);
|
||||
splineVertexCount = 3;
|
||||
}
|
||||
|
||||
// 'flat' may be a misnomer here because it's actually just
|
||||
@@ -461,7 +478,7 @@ public class PGraphics3 extends PGraphics {
|
||||
//if (spline_vertices_flat) {
|
||||
//if (z != 0) spline_vertices_flat = false;
|
||||
//}
|
||||
float vertex[] = spline_vertex[spline_vertex_index];
|
||||
float vertex[] = splineVertices[splineVertexCount];
|
||||
|
||||
vertex[MX] = x;
|
||||
vertex[MY] = y;
|
||||
@@ -494,22 +511,22 @@ public class PGraphics3 extends PGraphics {
|
||||
vertex[NZ] = normalZ;
|
||||
//}
|
||||
|
||||
spline_vertex_index++;
|
||||
splineVertexCount++;
|
||||
|
||||
// draw a segment if there are enough points
|
||||
if (spline_vertex_index > 3) {
|
||||
if (splineVertexCount > 3) {
|
||||
if (bezier) {
|
||||
if ((spline_vertex_index % 4) == 0) {
|
||||
if ((splineVertexCount % 4) == 0) {
|
||||
if (!bezier_inited) bezier_init();
|
||||
spline3_segment(spline_vertex_index-4,
|
||||
spline_vertex_index-4,
|
||||
spline3_segment(splineVertexCount-4,
|
||||
splineVertexCount-4,
|
||||
bezier_draw,
|
||||
bezier_detail);
|
||||
}
|
||||
} else { // catmull-rom curve (!bezier)
|
||||
if (!curve_inited) curve_init();
|
||||
spline3_segment(spline_vertex_index-4,
|
||||
spline_vertex_index-3,
|
||||
spline3_segment(splineVertexCount-4,
|
||||
splineVertexCount-3,
|
||||
curve_draw,
|
||||
curve_detail);
|
||||
}
|
||||
@@ -603,11 +620,11 @@ public class PGraphics3 extends PGraphics {
|
||||
|
||||
|
||||
public void endShape() {
|
||||
vertex_end = vertex_count;
|
||||
vertex_end = vertexCount;
|
||||
|
||||
// don't try to draw if there are no vertices
|
||||
// (fixes a bug in LINE_LOOP that re-adds a nonexistent vertex)
|
||||
if (vertex_count == 0) {
|
||||
if (vertexCount == 0) {
|
||||
shape = 0;
|
||||
return;
|
||||
}
|
||||
@@ -783,7 +800,7 @@ public class PGraphics3 extends PGraphics {
|
||||
case QUADS:
|
||||
case QUAD_STRIP:
|
||||
{
|
||||
stop = vertex_count-3;
|
||||
stop = vertexCount-3;
|
||||
increment = (shape == QUADS) ? 4 : 2;
|
||||
|
||||
for (int i = vertex_start; i < stop; i += increment) {
|
||||
@@ -809,21 +826,13 @@ public class PGraphics3 extends PGraphics {
|
||||
// ------------------------------------------------------------------
|
||||
// 2D or 3D POINTS FROM MODEL (MX, MY, MZ) TO VIEW SPACE (X, Y, Z)
|
||||
|
||||
if (depth) {
|
||||
for (int i = vertex_start; i < vertex_end; i++) {
|
||||
float vertex[] = vertices[i];
|
||||
for (int i = vertex_start; i < vertex_end; i++) {
|
||||
float vertex[] = vertices[i];
|
||||
|
||||
vertex[VX] = m00*vertex[MX] + m01*vertex[MY] + m02*vertex[MZ] + m03;
|
||||
vertex[VY] = m10*vertex[MX] + m11*vertex[MY] + m12*vertex[MZ] + m13;
|
||||
vertex[VZ] = m20*vertex[MX] + m21*vertex[MY] + m22*vertex[MZ] + m23;
|
||||
vertex[VW] = m30*vertex[MX] + m31*vertex[MY] + m32*vertex[MZ] + m33;
|
||||
}
|
||||
} else {
|
||||
// if no depth in use, then the points can be transformed simpler
|
||||
for (int i = vertex_start; i < vertex_end; i++) {
|
||||
vertices[i][X] = m00*vertices[i][MX] + m01*vertices[i][MY] + m03;
|
||||
vertices[i][Y] = m10*vertices[i][MX] + m11*vertices[i][MY] + m13;
|
||||
}
|
||||
vertex[VX] = m00*vertex[MX] + m01*vertex[MY] + m02*vertex[MZ] + m03;
|
||||
vertex[VY] = m10*vertex[MX] + m11*vertex[MY] + m12*vertex[MZ] + m13;
|
||||
vertex[VZ] = m20*vertex[MX] + m21*vertex[MY] + m22*vertex[MZ] + m23;
|
||||
vertex[VW] = m30*vertex[MX] + m31*vertex[MY] + m32*vertex[MZ] + m33;
|
||||
}
|
||||
|
||||
|
||||
@@ -1184,24 +1193,21 @@ public class PGraphics3 extends PGraphics {
|
||||
// ------------------------------------------------------------------
|
||||
// POINTS FROM VIEW SPACE (VX, VY, VZ) TO SCREEN SPACE (X, Y, Z)
|
||||
|
||||
//if ((cameraMode == PERSPECTIVE) && (dimensions == 3)) {
|
||||
if (depth) {
|
||||
for (int i = vertex_start; i < vertex_end; i++) {
|
||||
float vx[] = vertices[i];
|
||||
for (int i = vertex_start; i < vertex_end; i++) {
|
||||
float vx[] = vertices[i];
|
||||
|
||||
float ox = p00*vx[VX] + p01*vx[VY] + p02*vx[VZ] + p03*vx[VW];
|
||||
float oy = p10*vx[VX] + p11*vx[VY] + p12*vx[VZ] + p13*vx[VW];
|
||||
float oz = p20*vx[VX] + p21*vx[VY] + p22*vx[VZ] + p23*vx[VW];
|
||||
float ow = p30*vx[VX] + p31*vx[VY] + p32*vx[VZ] + p33*vx[VW];
|
||||
float ox = p00*vx[VX] + p01*vx[VY] + p02*vx[VZ] + p03*vx[VW];
|
||||
float oy = p10*vx[VX] + p11*vx[VY] + p12*vx[VZ] + p13*vx[VW];
|
||||
float oz = p20*vx[VX] + p21*vx[VY] + p22*vx[VZ] + p23*vx[VW];
|
||||
float ow = p30*vx[VX] + p31*vx[VY] + p32*vx[VZ] + p33*vx[VW];
|
||||
|
||||
if (ow != 0) {
|
||||
ox /= ow; oy /= ow; oz /= ow;
|
||||
}
|
||||
|
||||
vx[X] = width * (ONE + ox) / 2.0f;
|
||||
vx[Y] = height * (ONE + oy) / 2.0f;
|
||||
vx[Z] = (oz + ONE) / 2.0f;
|
||||
if (ow != 0) {
|
||||
ox /= ow; oy /= ow; oz /= ow;
|
||||
}
|
||||
|
||||
vx[X] = width * (ONE + ox) / 2.0f;
|
||||
vx[Y] = height * (ONE + oy) / 2.0f;
|
||||
vx[Z] = (oz + ONE) / 2.0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1397,7 +1403,7 @@ public class PGraphics3 extends PGraphics {
|
||||
if (weight < 1.5f) {
|
||||
int xx = (int) ((x1 + x2) / 2f);
|
||||
int yy = (int) ((y1 + y2) / 2f);
|
||||
point0(xx, yy, z, color);
|
||||
//point0(xx, yy, z, color);
|
||||
zbuffer[yy*width + xx] = screenZ(x, y, z);
|
||||
//stencil?
|
||||
|
||||
@@ -1633,21 +1639,11 @@ public class PGraphics3 extends PGraphics {
|
||||
|
||||
|
||||
public void translate(float tx, float ty) {
|
||||
if (!depth) {
|
||||
m03 += tx*m00 + ty*m01 + m02;
|
||||
m13 += tx*m10 + ty*m11 + m12;
|
||||
m23 += tx*m20 + ty*m21 + m22;
|
||||
m33 += tx*m30 + ty*m31 + m32;
|
||||
|
||||
} else {
|
||||
translate(tx, ty, 0);
|
||||
}
|
||||
translate(tx, ty, 0);
|
||||
}
|
||||
|
||||
|
||||
public void translate(float tx, float ty, float tz) {
|
||||
//dimensions = 3;
|
||||
|
||||
m03 += tx*m00 + ty*m01 + tz*m02;
|
||||
m13 += tx*m10 + ty*m11 + tz*m12;
|
||||
m23 += tx*m20 + ty*m21 + tz*m22;
|
||||
@@ -1731,45 +1727,20 @@ public class PGraphics3 extends PGraphics {
|
||||
* dimensions higher than two, in case this is still 2D mode.
|
||||
*/
|
||||
public void scale(float s) {
|
||||
//if (dimensions == 3) {
|
||||
applyMatrix(s, 0, 0, 0, 0, s, 0, 0, 0, 0, s, 0, 0, 0, 0, 1);
|
||||
//if (dimensions < 2) dimensions = 2;
|
||||
|
||||
//} else {
|
||||
//dimensions = 2;
|
||||
//applyMatrix(s, 0, 0, 0, 0, s, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
||||
//}
|
||||
|
||||
// figure out whether 2D or 3D matrix
|
||||
//scale(xyz, xyz, xyz);
|
||||
}
|
||||
|
||||
|
||||
public void scale(float sx, float sy) {
|
||||
//if (dimensions == 0) dimensions = 2;
|
||||
applyMatrix(sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
// OPTIMIZE: same as above
|
||||
public void scale(float x, float y, float z) {
|
||||
//modelMatrixIsIdentity = false;
|
||||
//dimensions = 3;
|
||||
applyMatrix(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public void transform(float n00, float n01, float n02, float n03,
|
||||
float n10, float n11, float n12, float n13,
|
||||
float n20, float n21, float n22, float n23,
|
||||
float n30, float n31, float n32, float n33) {
|
||||
//dimensions = 3;
|
||||
applyMatrix(n00, n01, n02, n03, n10, n11, n12, n13,
|
||||
n20, n21, n22, n23, n30, n31, n32, n33);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -2103,18 +2074,16 @@ public class PGraphics3 extends PGraphics {
|
||||
|
||||
|
||||
public float screenX(float x, float y) {
|
||||
return m00*x + m01*y + m02;
|
||||
return screenX(x, y, 0);
|
||||
}
|
||||
|
||||
|
||||
public float screenY(float x, float y) {
|
||||
return m10*x + m11*y + m12;
|
||||
return screenY(x, y, 0);
|
||||
}
|
||||
|
||||
|
||||
public float screenX(float x, float y, float z) {
|
||||
if (!depth) return screenX(x, y);
|
||||
|
||||
float ax = m00*x + m01*y + m02*z + m03;
|
||||
float ay = m10*x + m11*y + m12*z + m13;
|
||||
float az = m20*x + m21*y + m22*z + m23;
|
||||
@@ -2129,8 +2098,6 @@ public class PGraphics3 extends PGraphics {
|
||||
|
||||
|
||||
public float screenY(float x, float y, float z) {
|
||||
if (!depth) return screenY(x, y);
|
||||
|
||||
float ax = m00*x + m01*y + m02*z + m03;
|
||||
float ay = m10*x + m11*y + m12*z + m13;
|
||||
float az = m20*x + m21*y + m22*z + m23;
|
||||
@@ -2145,8 +2112,6 @@ public class PGraphics3 extends PGraphics {
|
||||
|
||||
|
||||
public float screenZ(float x, float y, float z) {
|
||||
if (!depth) return 0;
|
||||
|
||||
float ax = m00*x + m01*y + m02*z + m03;
|
||||
float ay = m10*x + m11*y + m12*z + m13;
|
||||
float az = m20*x + m21*y + m22*z + m23;
|
||||
@@ -2161,8 +2126,6 @@ public class PGraphics3 extends PGraphics {
|
||||
|
||||
|
||||
public float objectX(float x, float y, float z) {
|
||||
if (!depth) return screenX(x, y);
|
||||
|
||||
float ax = m00*x + m01*y + m02*z + m03;
|
||||
float aw = m30*x + m31*y + m32*z + m33;
|
||||
return (aw != 0) ? ax / aw : ax;
|
||||
@@ -2170,8 +2133,6 @@ public class PGraphics3 extends PGraphics {
|
||||
|
||||
|
||||
public float objectY(float x, float y, float z) {
|
||||
if (!depth) return screenY(x, y);
|
||||
|
||||
float ay = m10*x + m11*y + m12*z + m13;
|
||||
float aw = m30*x + m31*y + m32*z + m33;
|
||||
return (aw != 0) ? ay / aw : ay;
|
||||
@@ -2179,8 +2140,6 @@ public class PGraphics3 extends PGraphics {
|
||||
|
||||
|
||||
public float objectZ(float x, float y, float z) {
|
||||
if (!depth) return 0;
|
||||
|
||||
float az = m20*x + m21*y + m22*z + m23;
|
||||
float aw = m30*x + m31*y + m32*z + m33;
|
||||
return (aw != 0) ? az / aw : az;
|
||||
@@ -2297,4 +2256,55 @@ public class PGraphics3 extends PGraphics {
|
||||
lightSpecularG[num] = calcG;
|
||||
lightSpecularB[num] = calcB;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// MATH
|
||||
|
||||
|
||||
private final float mag(float a, float b) {
|
||||
return (float)Math.sqrt(a*a + b*b);
|
||||
}
|
||||
|
||||
private final float mag(float a, float b, float c) {
|
||||
return (float)Math.sqrt(a*a + b*b + c*c);
|
||||
}
|
||||
|
||||
private final float max(float a, float b) {
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
|
||||
private final float max(float a, float b, float c) {
|
||||
return Math.max(a, Math.max(b, c));
|
||||
}
|
||||
|
||||
private final float sq(float a) {
|
||||
return a*a;
|
||||
}
|
||||
|
||||
private final float sqrt(float a) {
|
||||
return (float)Math.sqrt(a);
|
||||
}
|
||||
|
||||
private final float abs(float a) {
|
||||
return (a < 0) ? -a : a;
|
||||
}
|
||||
|
||||
private final float sin(float angle) {
|
||||
if (angleMode == DEGREES) angle *= DEG_TO_RAD;
|
||||
return (float)Math.sin(angle);
|
||||
}
|
||||
|
||||
private final float cos(float angle) {
|
||||
if (angleMode == DEGREES) angle *= DEG_TO_RAD;
|
||||
return (float)Math.cos(angle);
|
||||
}
|
||||
|
||||
private final float tan(float angle) {
|
||||
if (angleMode == DEGREES) angle *= DEG_TO_RAD;
|
||||
return (float)Math.tan(angle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+263
-261
@@ -106,6 +106,9 @@ public class PImage implements PConstants, Cloneable {
|
||||
static final int PREC_RED_SHIFT = 16-PRECISIONB;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* Create an empty image object, set its format to RGB.
|
||||
* The pixel array is not allocated.
|
||||
@@ -179,6 +182,40 @@ public class PImage implements PConstants, Cloneable {
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* mode is one of CORNERS, CORNER, CENTER
|
||||
*/
|
||||
public void imageMode(int mode) {
|
||||
imageMode = mode;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* If true in PImage, use bilinear interpolation for copy()
|
||||
* operations. When inherited by PGraphics, also controls shapes.
|
||||
*/
|
||||
public void smooth() {
|
||||
smooth = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Disable smoothing. See smooth().
|
||||
*/
|
||||
public void noSmooth() {
|
||||
smooth = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// MARKING IMAGE AS MODIFIED / FOR USE w/ GET/SET
|
||||
|
||||
|
||||
public void modified() {
|
||||
mx1 = 0;
|
||||
my1 = 0;
|
||||
@@ -217,109 +254,6 @@ public class PImage implements PConstants, Cloneable {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set alpha channel for an image.
|
||||
*/
|
||||
public void alpha(int alpha[]) {
|
||||
alpha(this, alpha);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set alpha channel for an image.
|
||||
*/
|
||||
static public void alpha(PImage image, int alpha[]) {
|
||||
// don't execute if mask image is different size
|
||||
if (alpha.length != image.pixels.length) {
|
||||
System.err.println("alpha(): the mask image must be the same size");
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < image.pixels.length; i++) {
|
||||
image.pixels[i] =
|
||||
((alpha[i] & 0xff) << 24) |
|
||||
(image.pixels[i] & 0xffffff);
|
||||
}
|
||||
/*
|
||||
if (highbits) { // grab alpha from the high 8 bits (ARGB style)
|
||||
for (int i = 0; i < pixels.length; i++) {
|
||||
pixels[i] = pixels[i] & 0xffffff | (alpha[i] & 0xff000000);
|
||||
}
|
||||
} else { // alpha is in the low bits (ALPHA style)
|
||||
for (int i = 0; i < pixels.length; i++) {
|
||||
pixels[i] = pixels[i] & 0xffffff | ((alpha[i] & 0xff) << 24);
|
||||
}
|
||||
}
|
||||
*/
|
||||
image.format = ARGB;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set alpha channel for an image using another image as the source.
|
||||
*/
|
||||
public void alpha(PImage alpha) {
|
||||
alpha(alpha.pixels);
|
||||
}
|
||||
|
||||
static public void alpha(PImage image, PImage alpha) {
|
||||
alpha(image, alpha.pixels);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
// FIND_EDGES (no params) .. high pass filter
|
||||
// BLUR (no params)
|
||||
// GAUSSIAN_BLUR (one param)
|
||||
// BLACK_WHITE? (param for midpoint)
|
||||
// GRAYSCALE
|
||||
// POSTERIZE (int num of levels)
|
||||
public void filter(int kind) {
|
||||
switch (kind) {
|
||||
|
||||
case BLACK_WHITE:
|
||||
filter(BLACK_WHITE, 0.5f);
|
||||
break;
|
||||
|
||||
case GRAYSCALE:
|
||||
// Converts RGB image data into grayscale using
|
||||
// weighted RGB components, and keeps alpha channel intact.
|
||||
// [toxi 040115]
|
||||
for (int i = 0; i < pixels.length; i++) {
|
||||
int col = pixels[i];
|
||||
// luminance = 0.3*red + 0.59*green + 0.11*blue
|
||||
// 0.30 * 256 = 77
|
||||
// 0.59 * 256 = 151
|
||||
// 0.11 * 256 = 28
|
||||
int lum = (77*(col>>16&0xff) + 151*(col>>8&0xff) + 28*(col&0xff))>>8;
|
||||
pixels[i] = (col & ALPHA_MASK) | lum<<16 | lum<<8 | lum;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void filter(int kind, float param) {
|
||||
switch (kind) {
|
||||
|
||||
case BLACK_WHITE: // greater than or equal to the threshold
|
||||
int thresh = (int) (param * 255);
|
||||
for (int i = 0; i < pixels.length; i++) {
|
||||
int max = Math.max((pixels[i] & RED_MASK) >> 16,
|
||||
Math.max((pixels[i] & GREEN_MASK) >> 8,
|
||||
(pixels[i] & BLUE_MASK)));
|
||||
pixels[i] = (pixels[i] & ALPHA_MASK) |
|
||||
((max < thresh) ? 0x000000 : 0xffffff);
|
||||
}
|
||||
break;
|
||||
|
||||
case GRAYSCALE:
|
||||
filter(GRAYSCALE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// GET/SET PIXELS
|
||||
@@ -375,6 +309,19 @@ public class PImage implements PConstants, Cloneable {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convenience method to avoid an extra cast,
|
||||
* and the exception handling.
|
||||
*/
|
||||
public PImage get() {
|
||||
try {
|
||||
return (PImage) clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void set(int x, int y, int c) {
|
||||
if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) return;
|
||||
pixels[y*width + x] = c;
|
||||
@@ -382,42 +329,120 @@ public class PImage implements PConstants, Cloneable {
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// ALPHA CHANNEL
|
||||
|
||||
|
||||
/**
|
||||
* Set alpha channel for an image.
|
||||
*/
|
||||
public void alpha(int alpha[]) {
|
||||
alpha(this, alpha);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set alpha channel for an image.
|
||||
*/
|
||||
static public void alpha(PImage image, int alpha[]) {
|
||||
// don't execute if mask image is different size
|
||||
if (alpha.length != image.pixels.length) {
|
||||
System.err.println("alpha(): the mask image must be the same size");
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < image.pixels.length; i++) {
|
||||
image.pixels[i] =
|
||||
((alpha[i] & 0xff) << 24) |
|
||||
(image.pixels[i] & 0xffffff);
|
||||
}
|
||||
/*
|
||||
if (highbits) { // grab alpha from the high 8 bits (ARGB style)
|
||||
for (int i = 0; i < pixels.length; i++) {
|
||||
pixels[i] = pixels[i] & 0xffffff | (alpha[i] & 0xff000000);
|
||||
}
|
||||
} else { // alpha is in the low bits (ALPHA style)
|
||||
for (int i = 0; i < pixels.length; i++) {
|
||||
pixels[i] = pixels[i] & 0xffffff | ((alpha[i] & 0xff) << 24);
|
||||
}
|
||||
}
|
||||
*/
|
||||
image.format = ARGB;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set alpha channel for an image using another image as the source.
|
||||
*/
|
||||
public void alpha(PImage alpha) {
|
||||
alpha(alpha.pixels);
|
||||
}
|
||||
|
||||
static public void alpha(PImage image, PImage alpha) {
|
||||
alpha(image, alpha.pixels);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Options to filter an image in place.
|
||||
*/
|
||||
// FIND_EDGES (no params) .. high pass filter
|
||||
// BLUR (no params)
|
||||
// GAUSSIAN_BLUR (one param)
|
||||
// BLACK_WHITE? (param for midpoint)
|
||||
// GRAYSCALE
|
||||
// POSTERIZE (int num of levels)
|
||||
public void filter(int kind) {
|
||||
switch (kind) {
|
||||
|
||||
case BLACK_WHITE:
|
||||
filter(BLACK_WHITE, 0.5f);
|
||||
break;
|
||||
|
||||
case GRAYSCALE:
|
||||
// Converts RGB image data into grayscale using
|
||||
// weighted RGB components, and keeps alpha channel intact.
|
||||
// [toxi 040115]
|
||||
for (int i = 0; i < pixels.length; i++) {
|
||||
int col = pixels[i];
|
||||
// luminance = 0.3*red + 0.59*green + 0.11*blue
|
||||
// 0.30 * 256 = 77
|
||||
// 0.59 * 256 = 151
|
||||
// 0.11 * 256 = 28
|
||||
int lum = (77*(col>>16&0xff) + 151*(col>>8&0xff) + 28*(col&0xff))>>8;
|
||||
pixels[i] = (col & ALPHA_MASK) | lum<<16 | lum<<8 | lum;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void filter(int kind, float param) {
|
||||
switch (kind) {
|
||||
|
||||
case BLACK_WHITE: // greater than or equal to the threshold
|
||||
int thresh = (int) (param * 255);
|
||||
for (int i = 0; i < pixels.length; i++) {
|
||||
int max = Math.max((pixels[i] & RED_MASK) >> 16,
|
||||
Math.max((pixels[i] & GREEN_MASK) >> 8,
|
||||
(pixels[i] & BLUE_MASK)));
|
||||
pixels[i] = (pixels[i] & ALPHA_MASK) |
|
||||
((max < thresh) ? 0x000000 : 0xffffff);
|
||||
}
|
||||
break;
|
||||
|
||||
case GRAYSCALE:
|
||||
filter(GRAYSCALE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// 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;
|
||||
@@ -474,7 +499,8 @@ public class PImage implements PConstants, Cloneable {
|
||||
/**
|
||||
* Copies area of one image into another PImage object.
|
||||
*/
|
||||
public void copy(PImage src, int sx1, int sy1, int sx2, int sy2,
|
||||
public void copy(PImage src,
|
||||
int sx1, int sy1, int sx2, int sy2,
|
||||
int dx1, int dy1, int dx2, int dy2) {
|
||||
if (imageMode == CORNER) { // if CORNERS, do nothing
|
||||
sx2 += sx1; sy2 += sy1;
|
||||
@@ -515,17 +541,8 @@ public class PImage implements PConstants, Cloneable {
|
||||
|
||||
|
||||
/**
|
||||
* Copies and blends 1 pixel with MODE to pixel in another image
|
||||
* Copies and blends 1 pixel with MODE to pixel in this image.
|
||||
*/
|
||||
public void blend(PImage src, int sx, int sy, int dx, int dy, int mode) {
|
||||
if ((dx >= 0) && (dx < width) && (sx >= 0) && (sx < src.width) &&
|
||||
(dy >= 0) && (dy < height) && (sy >= 0) && (sy < src.height)) {
|
||||
pixels[dy * width + dx] =
|
||||
blend(pixels[dy * width + dx],
|
||||
src.pixels[sy * src.width + sx], mode);
|
||||
}
|
||||
}
|
||||
|
||||
public void blend(int sx, int sy, int dx, int dy, int mode) {
|
||||
if ((dx >= 0) && (dx < width) && (sx >= 0) && (sx < width) &&
|
||||
(dy >= 0) && (dy < height) && (sy >= 0) && (sy < height)) {
|
||||
@@ -535,6 +552,20 @@ public class PImage implements PConstants, Cloneable {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copies and blends 1 pixel with MODE to pixel in another image
|
||||
*/
|
||||
public void blend(PImage src,
|
||||
int sx, int sy, int dx, int dy, int mode) {
|
||||
if ((dx >= 0) && (dx < width) && (sx >= 0) && (sx < src.width) &&
|
||||
(dy >= 0) && (dy < height) && (sy >= 0) && (sy < src.height)) {
|
||||
pixels[dy * width + dx] =
|
||||
blend(pixels[dy * width + dx],
|
||||
src.pixels[sy * src.width + sx], mode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Blends one area of this image to another area
|
||||
*/
|
||||
@@ -547,7 +578,8 @@ public class PImage implements PConstants, Cloneable {
|
||||
/**
|
||||
* Copies area of one image into another PImage object
|
||||
*/
|
||||
public void blend(PImage src, int sx1, int sy1, int sx2, int sy2,
|
||||
public void blend(PImage src,
|
||||
int sx1, int sy1, int sx2, int sy2,
|
||||
int dx1, int dy1, int dx2, int dy2, int mode) {
|
||||
if (imageMode == CORNER) { // if CORNERS, do nothing
|
||||
sx2 += sx1; sy2 += sy1;
|
||||
@@ -612,19 +644,6 @@ public class PImage implements PConstants, Cloneable {
|
||||
// COPYING IMAGE DATA
|
||||
|
||||
|
||||
/**
|
||||
* Convenience method to avoid an extra cast,
|
||||
* and the exception handling.
|
||||
*/
|
||||
public PImage get() {
|
||||
try {
|
||||
return (PImage) clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Duplicate an image, returns new PImage object.
|
||||
* The pixels[] array for the new object will be unique
|
||||
@@ -643,32 +662,6 @@ public class PImage implements PConstants, Cloneable {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Duplicate an image, returns new object
|
||||
*/
|
||||
/*
|
||||
public PImage duplicate() {
|
||||
PImage c = new PImage(new int[pixels.length], width, height, format);
|
||||
System.arraycopy(pixels, 0, c.pixels, 0, pixels.length);
|
||||
return c;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Duplicate and resize image
|
||||
*/
|
||||
/*
|
||||
public PImage duplicate(int newWidth, int newHeight) {
|
||||
PImage dupe = new PImage(new int[newWidth * newHeight],
|
||||
newWidth, newHeight, format);
|
||||
|
||||
dupe.copy(this, 0, 0, width - 1, height - 1,
|
||||
0, 0, newWidth - 1, newHeight - 1);
|
||||
|
||||
return dupe;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -678,10 +671,10 @@ public class PImage implements PConstants, Cloneable {
|
||||
* 'mode' determines the blending mode used in the process.
|
||||
*/
|
||||
private void blit_resize(PImage img,
|
||||
int srcX1, int srcY1, int srcX2, int srcY2,
|
||||
int[] destPixels, int screenW, int screenH,
|
||||
int destX1, int destY1, int destX2, int destY2,
|
||||
int mode) {
|
||||
int srcX1, int srcY1, int srcX2, int srcY2,
|
||||
int[] destPixels, int screenW, int screenH,
|
||||
int destX1, int destY1, int destX2, int destY2,
|
||||
int mode) {
|
||||
if (srcX1 < 0) srcX1 = 0;
|
||||
if (srcY1 < 0) srcY1 = 0;
|
||||
if (srcX2 >= img.width) srcX2 = img.width - 1;
|
||||
@@ -1073,35 +1066,52 @@ public class PImage implements PConstants, Cloneable {
|
||||
1, 23, 0, 4, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 8, 0, 8
|
||||
};
|
||||
|
||||
static public void saveHeaderTIF(OutputStream output,
|
||||
int width, int height) throws IOException {
|
||||
byte tiff[] = new byte[768];
|
||||
System.arraycopy(tiff_header, 0, tiff, 0, tiff_header.length);
|
||||
|
||||
tiff[30] = (byte) ((width >> 8) & 0xff);
|
||||
tiff[31] = (byte) ((width) & 0xff);
|
||||
tiff[42] = tiff[102] = (byte) ((height >> 8) & 0xff);
|
||||
tiff[43] = tiff[103] = (byte) ((height) & 0xff);
|
||||
static public boolean saveHeaderTIF(OutputStream output,
|
||||
int width, int height) {
|
||||
try {
|
||||
byte tiff[] = new byte[768];
|
||||
System.arraycopy(tiff_header, 0, tiff, 0, tiff_header.length);
|
||||
|
||||
int count = width*height*3;
|
||||
tiff[114] = (byte) ((count >> 24) & 0xff);
|
||||
tiff[115] = (byte) ((count >> 16) & 0xff);
|
||||
tiff[116] = (byte) ((count >> 8) & 0xff);
|
||||
tiff[117] = (byte) ((count) & 0xff);
|
||||
tiff[30] = (byte) ((width >> 8) & 0xff);
|
||||
tiff[31] = (byte) ((width) & 0xff);
|
||||
tiff[42] = tiff[102] = (byte) ((height >> 8) & 0xff);
|
||||
tiff[43] = tiff[103] = (byte) ((height) & 0xff);
|
||||
|
||||
output.write(tiff);
|
||||
int count = width*height*3;
|
||||
tiff[114] = (byte) ((count >> 24) & 0xff);
|
||||
tiff[115] = (byte) ((count >> 16) & 0xff);
|
||||
tiff[116] = (byte) ((count >> 8) & 0xff);
|
||||
tiff[117] = (byte) ((count) & 0xff);
|
||||
|
||||
output.write(tiff);
|
||||
return true;
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static public void saveTIF(OutputStream output, int pixels[],
|
||||
int width, int height) throws IOException {
|
||||
saveHeaderTIF(output, width, height);
|
||||
for (int i = 0; i < pixels.length; i++) {
|
||||
output.write((pixels[i] >> 16) & 0xff);
|
||||
output.write((pixels[i] >> 8) & 0xff);
|
||||
output.write(pixels[i] & 0xff);
|
||||
static public boolean saveTIF(OutputStream output, int pixels[],
|
||||
int width, int height) {
|
||||
try {
|
||||
if (!saveHeaderTIF(output, width, height)) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < pixels.length; i++) {
|
||||
output.write((pixels[i] >> 16) & 0xff);
|
||||
output.write((pixels[i] >> 8) & 0xff);
|
||||
output.write(pixels[i] & 0xff);
|
||||
}
|
||||
output.flush();
|
||||
return true;
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
output.flush();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1115,40 +1125,55 @@ public class PImage implements PConstants, Cloneable {
|
||||
*
|
||||
* tga spec: http://organicbit.com/closecombat/formats/tga.html
|
||||
*/
|
||||
static void saveHeaderTGA(OutputStream output,
|
||||
int width, int height) throws IOException {
|
||||
byte header[] = new byte[18];
|
||||
static public boolean saveHeaderTGA(OutputStream output,
|
||||
int width, int height) {
|
||||
try {
|
||||
byte header[] = new byte[18];
|
||||
|
||||
// set header info
|
||||
header[2] = 0x02;
|
||||
header[12] = (byte) (width & 0xff);
|
||||
header[13] = (byte) (width >> 8);
|
||||
header[14] = (byte) (height & 0xff);
|
||||
header[15] = (byte) (height >> 8);
|
||||
header[16] = 32; // bits per pixel
|
||||
header[17] = 8; // bits per colour component
|
||||
// set header info
|
||||
header[2] = 0x02;
|
||||
header[12] = (byte) (width & 0xff);
|
||||
header[13] = (byte) (width >> 8);
|
||||
header[14] = (byte) (height & 0xff);
|
||||
header[15] = (byte) (height >> 8);
|
||||
header[16] = 32; // bits per pixel
|
||||
header[17] = 8; // bits per colour component
|
||||
|
||||
output.write(header);
|
||||
output.write(header);
|
||||
return true;
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static public void saveTGA(OutputStream output, int pixels[],
|
||||
int width, int height) throws IOException {
|
||||
saveHeaderTGA(output, width, height);
|
||||
|
||||
int index = (height-1) * width;
|
||||
|
||||
for (int y = height-1; y >= 0; y--) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
int col = pixels[index + x];
|
||||
output.write(col & 0xff);
|
||||
output.write(col >> 8 & 0xff);
|
||||
output.write(col >> 16 & 0xff);
|
||||
output.write(col >>> 24 & 0xff);
|
||||
static public boolean saveTGA(OutputStream output, int pixels[],
|
||||
int width, int height) {
|
||||
try {
|
||||
if (!saveHeaderTGA(output, width, height)) {
|
||||
return false;
|
||||
}
|
||||
index -= width;
|
||||
|
||||
int index = (height-1) * width;
|
||||
|
||||
for (int y = height-1; y >= 0; y--) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
int col = pixels[index + x];
|
||||
output.write(col & 0xff);
|
||||
output.write(col >> 8 & 0xff);
|
||||
output.write(col >> 16 & 0xff);
|
||||
output.write(col >>> 24 & 0xff);
|
||||
}
|
||||
index -= width;
|
||||
}
|
||||
output.flush();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
output.flush();
|
||||
}
|
||||
|
||||
|
||||
@@ -1176,28 +1201,5 @@ public class PImage implements PConstants, Cloneable {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// INHERITED BY PGRAPHICS
|
||||
|
||||
|
||||
public void smooth() {
|
||||
smooth = true;
|
||||
}
|
||||
|
||||
public void noSmooth() {
|
||||
smooth = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* mode is one of CORNERS, CORNER, CENTER
|
||||
*/
|
||||
public void imageMode(int mode) {
|
||||
imageMode = mode;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -94,10 +94,10 @@ public class PLine implements PConstants
|
||||
private float db;
|
||||
private float da;
|
||||
|
||||
private PGraphics parent;
|
||||
private PGraphics3 parent;
|
||||
|
||||
|
||||
public PLine(PGraphics g) {
|
||||
public PLine(PGraphics3 g) {
|
||||
INTERPOLATE_Z = false;
|
||||
|
||||
x_array = new float[2];
|
||||
|
||||
+121
-70
@@ -6,8 +6,34 @@ package processing.core;
|
||||
|
||||
public interface PMethods {
|
||||
|
||||
public void imageMode(int mode);
|
||||
|
||||
public void smooth();
|
||||
|
||||
public void noSmooth();
|
||||
|
||||
//
|
||||
|
||||
public void modified();
|
||||
|
||||
public void modified(int x, int y);
|
||||
|
||||
public void modified(int x1, int y1, int x2, int y2);
|
||||
|
||||
public void resetModified(); // <<<<< MORE CONSISTENT NAME NEEDED
|
||||
|
||||
//
|
||||
|
||||
public int get(int x, int y);
|
||||
|
||||
public PImage get(int x, int y, int w, int h);
|
||||
|
||||
public PImage get();
|
||||
|
||||
public void set(int x, int y, int c);
|
||||
|
||||
//
|
||||
|
||||
public void alpha(int alpha[]);
|
||||
|
||||
public void alpha(PImage alpha);
|
||||
@@ -16,46 +42,59 @@ public interface PMethods {
|
||||
|
||||
public void filter(int kind, float param);
|
||||
|
||||
public int get(int x, int y);
|
||||
|
||||
public PImage get(int x, int y, int w, int h);
|
||||
|
||||
public void set(int x, int y, int c);
|
||||
|
||||
public void copy(PImage src, int dx, int dy);
|
||||
|
||||
public void copy(int sx1, int sy1, int sx2, int sy2,
|
||||
int dx1, int dy1, int dx2, int dy2);
|
||||
|
||||
public void copy(PImage src, int sx1, int sy1, int sx2, int sy2,
|
||||
public void copy(PImage src,
|
||||
int sx1, int sy1, int sx2, int sy2,
|
||||
int dx1, int dy1, int dx2, int dy2);
|
||||
|
||||
public void blend(PImage src, int sx, int sy, int dx, int dy, int mode);
|
||||
|
||||
public void blend(int sx, int sy, int dx, int dy, int mode);
|
||||
|
||||
public void blend(PImage src,
|
||||
int sx, int sy, int dx, int dy, int mode);
|
||||
|
||||
public void blend(int sx1, int sy1, int sx2, int sy2,
|
||||
int dx1, int dy1, int dx2, int dy2, int mode);
|
||||
|
||||
public void blend(PImage src, int sx1, int sy1, int sx2, int sy2,
|
||||
public void blend(PImage src,
|
||||
int sx1, int sy1, int sx2, int sy2,
|
||||
int dx1, int dy1, int dx2, int dy2, int mode);
|
||||
|
||||
public PImage get();
|
||||
//
|
||||
|
||||
// WOULD LIKE A NICER NAME
|
||||
static public boolean saveHeaderTIF(OutputStream output,
|
||||
int width, int height);
|
||||
|
||||
static public boolean saveTIF(OutputStream output, int pixels[],
|
||||
int width, int height);
|
||||
|
||||
// WOULD LIKE A NICER NAME
|
||||
static public boolean saveHeaderTGA(OutputStream output,
|
||||
int width, int height);
|
||||
|
||||
static public boolean saveTGA(OutputStream output, int pixels[],
|
||||
int width, int height);
|
||||
|
||||
public void save(String filename);
|
||||
|
||||
public void smooth();
|
||||
|
||||
public void noSmooth();
|
||||
|
||||
public void imageMode(int mode);
|
||||
|
||||
public void defaults();
|
||||
//
|
||||
|
||||
public void beginFrame();
|
||||
|
||||
public void endFrame();
|
||||
|
||||
public void defaults();
|
||||
|
||||
public void hint(int which);
|
||||
|
||||
public void unhint(int which);
|
||||
|
||||
//
|
||||
|
||||
public void beginShape();
|
||||
|
||||
public void beginShape(int kind);
|
||||
@@ -85,6 +124,8 @@ public interface PMethods {
|
||||
|
||||
public void endShape();
|
||||
|
||||
//
|
||||
|
||||
public void point(float x, float y);
|
||||
|
||||
public void point(float x, float y, float z);
|
||||
@@ -104,18 +145,11 @@ public interface PMethods {
|
||||
public void quad(float x1, float y1, float x2, float y2,
|
||||
float x3, float y3, float x4, float y4);
|
||||
|
||||
public void image(PImage image, float x1, float y1);
|
||||
public void circle(float x, float y, float radius);
|
||||
|
||||
public void image(PImage image,
|
||||
float x1, float y1, float x2, float y2);
|
||||
public void ellipseMode(int mode);
|
||||
|
||||
public void image(PImage image,
|
||||
float x1, float y1, float x2, float y2,
|
||||
float u1, float v1, float u2, float v2);
|
||||
|
||||
public void cache(PImage image);
|
||||
|
||||
public void cache(PImage images[]);
|
||||
public void ellipse(float x, float y, float hradius, float vradius);
|
||||
|
||||
public void arcMode(int mode);
|
||||
|
||||
@@ -125,11 +159,34 @@ public interface PMethods {
|
||||
public void arc(float start, float stop,
|
||||
float x, float y, float hr, float vr);
|
||||
|
||||
public void ellipseMode(int mode);
|
||||
//
|
||||
|
||||
public void ellipse(float x, float y, float hradius, float vradius);
|
||||
public void box(float size);
|
||||
|
||||
public void circle(float x, float y, float radius);
|
||||
public void box(float w, float h, float d);
|
||||
|
||||
public void sphereDetail(int res);
|
||||
|
||||
public void sphere(float r);
|
||||
|
||||
public void sphere(float x, float y, float z, float r);
|
||||
|
||||
//
|
||||
|
||||
public void image(PImage image, float x1, float y1);
|
||||
|
||||
public void image(PImage image,
|
||||
float x1, float y1, float x2, float y2);
|
||||
|
||||
public void image(PImage image,
|
||||
float x1, float y1, float x2, float y2,
|
||||
float u1, float v1, float u2, float v2);
|
||||
|
||||
//public void cache(PImage image);
|
||||
|
||||
//public void cache(PImage images[]);
|
||||
|
||||
//
|
||||
|
||||
public float bezierPoint(float a, float b, float c, float d,
|
||||
float t);
|
||||
@@ -169,15 +226,7 @@ public interface PMethods {
|
||||
float x3, float y3, float z3,
|
||||
float x4, float y4, float z4);
|
||||
|
||||
public void box(float size);
|
||||
|
||||
public void box(float w, float h, float d);
|
||||
|
||||
public void sphereDetail(int res);
|
||||
|
||||
public void sphere(float r);
|
||||
|
||||
public void sphere(float x, float y, float z, float r);
|
||||
//
|
||||
|
||||
public void textFont(PFont which);
|
||||
|
||||
@@ -211,6 +260,8 @@ public interface PMethods {
|
||||
|
||||
public void text(float num, float x, float y, float z);
|
||||
|
||||
//
|
||||
|
||||
public void angleMode(int mode);
|
||||
|
||||
public void translate(float tx, float ty);
|
||||
@@ -244,16 +295,18 @@ public interface PMethods {
|
||||
|
||||
public void resetMatrix();
|
||||
|
||||
public void applyMatrix(float n00, float n01, float n02,
|
||||
float n10, float n11, float n12);
|
||||
|
||||
public void applyMatrix(float n00, float n01, float n02, float n03,
|
||||
float n10, float n11, float n12, float n13,
|
||||
float n20, float n21, float n22, float n23,
|
||||
float n30, float n31, float n32, float n33);
|
||||
|
||||
public void applyMatrix(float n00, float n01, float n02,
|
||||
float n10, float n11, float n12);
|
||||
|
||||
public void printMatrix();
|
||||
|
||||
//
|
||||
|
||||
public void cameraMode(int mode);
|
||||
|
||||
public void beginCamera();
|
||||
@@ -275,6 +328,8 @@ public interface PMethods {
|
||||
|
||||
public void printCamera();
|
||||
|
||||
//
|
||||
|
||||
public float screenX(float x, float y);
|
||||
|
||||
public float screenY(float x, float y);
|
||||
@@ -291,6 +346,29 @@ public interface PMethods {
|
||||
|
||||
public float objectZ(float x, float y, float z);
|
||||
|
||||
//
|
||||
|
||||
public void lights();
|
||||
|
||||
public void noLights();
|
||||
|
||||
public void light(int num, float x, float y, float z,
|
||||
float red, float green, float blue);
|
||||
|
||||
public void lightEnable(int num);
|
||||
|
||||
public void lightDisable(int num);
|
||||
|
||||
public void lightPosition(int num, float x, float y, float z);
|
||||
|
||||
public void lightAmbient(int num, float x, float y, float z);
|
||||
|
||||
public void lightDiffuse(int num, float x, float y, float z);
|
||||
|
||||
public void lightSpecular(int num, float x, float y, float z);
|
||||
|
||||
//
|
||||
|
||||
public void colorMode(int mode);
|
||||
|
||||
public void colorMode(int mode, float max);
|
||||
@@ -352,31 +430,4 @@ public interface PMethods {
|
||||
public void background(PImage image);
|
||||
|
||||
public void clear();
|
||||
|
||||
public void depth();
|
||||
|
||||
public void noDepth();
|
||||
|
||||
public void lights();
|
||||
|
||||
public void noLights();
|
||||
|
||||
public void light(int num, float x, float y, float z,
|
||||
float red, float green, float blue);
|
||||
|
||||
public void lightEnable(int num);
|
||||
|
||||
public void lightDisable(int num);
|
||||
|
||||
public void lightPosition(int num, float x, float y, float z);
|
||||
|
||||
public void lightAmbient(int num, float x, float y, float z);
|
||||
|
||||
public void lightDiffuse(int num, float x, float y, float z);
|
||||
|
||||
public void lightSpecular(int num, float x, float y, float z);
|
||||
|
||||
public void hint(int which);
|
||||
|
||||
public void unhint(int which);
|
||||
}
|
||||
|
||||
+9
-8
@@ -36,7 +36,7 @@ public class PPolygon implements PConstants {
|
||||
static final boolean FRY = false;
|
||||
|
||||
// after some fiddling, this seems to produce the best results
|
||||
static final int ZBUFFER_MIN_COVERAGE = 204;
|
||||
//static final int ZBUFFER_MIN_COVERAGE = 204;
|
||||
|
||||
float r[] = new float[DEFAULT_SIZE]; // storage used by incrementalize
|
||||
float dr[] = new float[DEFAULT_SIZE];
|
||||
@@ -54,7 +54,7 @@ public class PPolygon implements PConstants {
|
||||
int rgba;
|
||||
int r2, g2, b2, a2, a2orig;
|
||||
|
||||
float zbuffer[];
|
||||
//float zbuffer[];
|
||||
boolean noDepthTest;
|
||||
|
||||
PGraphics parent;
|
||||
@@ -173,7 +173,7 @@ public class PPolygon implements PConstants {
|
||||
// these may have changed due to a resize()
|
||||
// so they should be refreshed here
|
||||
pixels = parent.pixels;
|
||||
zbuffer = parent.zbuffer;
|
||||
//zbuffer = parent.zbuffer;
|
||||
|
||||
noDepthTest = parent.hints[NO_DEPTH_TEST]; //!parent.depthTest;
|
||||
smoothing = parent.smooth;
|
||||
@@ -391,7 +391,8 @@ public class PPolygon implements PConstants {
|
||||
for (int x = lx; x <= rx; x++) {
|
||||
// added == because things on same plane weren't replacing each other
|
||||
// makes for strangeness in 3D, but totally necessary for 2D
|
||||
if (noDepthTest || (sp[Z] <= zbuffer[offset+x])) {
|
||||
//if (noDepthTest || (sp[Z] <= zbuffer[offset+x])) {
|
||||
if (true) {
|
||||
|
||||
// map texture based on U, V coords in sp[U] and sp[V]
|
||||
if (interpUV) {
|
||||
@@ -547,7 +548,7 @@ public class PPolygon implements PConstants {
|
||||
if ((ta == 254) || (ta == 255)) { // if (ta & 0xf8) would be good
|
||||
// no need to blend
|
||||
pixels[offset+x] = 0xff000000 | (tr << 16) | (tg << 8) | tb;
|
||||
zbuffer[offset+x] = sp[Z];
|
||||
//zbuffer[offset+x] = sp[Z];
|
||||
|
||||
} else {
|
||||
// blend with pixel on screen
|
||||
@@ -560,7 +561,7 @@ public class PPolygon implements PConstants {
|
||||
(((tr*ta + r1*a1) >> 8) << 16) |
|
||||
((tg*ta + g1*a1) & 0xff00) |
|
||||
((tb*ta + b1*a1) >> 8);
|
||||
if (ta > ZBUFFER_MIN_COVERAGE) zbuffer[offset+x] = sp[Z];
|
||||
//if (ta > ZBUFFER_MIN_COVERAGE) zbuffer[offset+x] = sp[Z];
|
||||
}
|
||||
|
||||
} else { // no image applied
|
||||
@@ -581,7 +582,7 @@ public class PPolygon implements PConstants {
|
||||
if (weight == 255) {
|
||||
// no blend, no aa, just the rgba
|
||||
pixels[offset+x] = rgba;
|
||||
zbuffer[offset+x] = sp[Z];
|
||||
//zbuffer[offset+x] = sp[Z];
|
||||
|
||||
} else {
|
||||
int r1 = (pixels[offset+x] >> 16) & 0xff;
|
||||
@@ -596,7 +597,7 @@ public class PPolygon implements PConstants {
|
||||
((g1*a1 + g2*a2) >> 8) << 8 |
|
||||
((b1*a1 + b2*a2) >> 8));
|
||||
|
||||
if (a2 > ZBUFFER_MIN_COVERAGE) zbuffer[offset+x] = sp[Z];
|
||||
//if (a2 > ZBUFFER_MIN_COVERAGE) zbuffer[offset+x] = sp[Z];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -182,7 +182,7 @@ public class PTriangle implements PConstants
|
||||
private int m_index;
|
||||
|
||||
/** */
|
||||
private PGraphics parent;
|
||||
private PGraphics3 parent;
|
||||
|
||||
/** */
|
||||
private boolean m_culling;
|
||||
@@ -193,7 +193,7 @@ public class PTriangle implements PConstants
|
||||
/** */
|
||||
private boolean m_bilinear;
|
||||
|
||||
public PTriangle(PGraphics g) {
|
||||
public PTriangle(PGraphics3 g) {
|
||||
//SCREEN_WIDTH = g.width;
|
||||
//SCREEN_HEIGHT = g.height;
|
||||
//SCREEN_WIDTH1 = SCREEN_WIDTH-1;
|
||||
|
||||
Reference in New Issue
Block a user