work on alpha() in PImage, also cleaned up proper bounding of color

commands
This commit is contained in:
benfry
2004-09-03 16:41:20 +00:00
parent 218dc2877f
commit 8790dad941
4 changed files with 55 additions and 18 deletions

View File

@@ -3333,7 +3333,7 @@ public class PApplet extends Applet
public final int color(int gray) {
if (g == null) {
gray &= 0xff; // cut the bounds on this feller
if (gray > 255) gray = 255; else if (gray < 0) gray = 0;
return 0xff000000 | (gray << 16) | (gray << 8) | gray;
}
return g.color(gray);
@@ -3342,7 +3342,8 @@ public class PApplet extends Applet
public final int color(float fgray) {
if (g == null) {
int gray = ((int) fgray) & 0xff;
int gray = (int) fgray;
if (gray > 255) gray = 255; else if (gray < 0) gray = 0;
return 0xff000000 | (gray << 16) | (gray << 8) | gray;
}
return g.color(fgray);
@@ -3351,8 +3352,8 @@ public class PApplet extends Applet
public final int color(int gray, int alpha) {
if (g == null) {
gray &= 0xff; // cut the bounds on this feller
alpha &= 0xff;
if (gray > 255) gray = 255; else if (gray < 0) gray = 0;
if (alpha > 255) alpha = 255; else if (alpha < 0) alpha = 0;
return (alpha << 24) | (gray << 16) | (gray << 8) | gray;
}
return g.color(gray, alpha);
@@ -3361,8 +3362,10 @@ public class PApplet extends Applet
public final int color(float fgray, float falpha) {
if (g == null) {
int gray = ((int) fgray) & 0xff;
int alpha = ((int) falpha) & 0xff;
int gray = (int) fgray;
int alpha = (int) falpha;
if (gray > 255) gray = 255; else if (gray < 0) gray = 0;
if (alpha > 255) alpha = 255; else if (alpha < 0) alpha = 0;
return 0xff000000 | (gray << 16) | (gray << 8) | gray;
}
return g.color(fgray, falpha);
@@ -3371,8 +3374,11 @@ public class PApplet extends Applet
public final int color(int x, int y, int z) {
if (g == null) {
return 0xff000000 |
((x & 0xff) << 16) | ((y & 0xff) << 8) | (z & 0xff);
if (x > 255) x = 255; else if (x < 0) x = 0;
if (y > 255) y = 255; else if (y < 0) y = 0;
if (z > 255) z = 255; else if (z < 0) z = 0;
return 0xff000000 | (x << 16) | (y << 8) | z;
}
return g.color(x, y, z);
}
@@ -3380,8 +3386,11 @@ public class PApplet extends Applet
public final int color(float x, float y, float z) {
if (g == null) {
return 0xff000000 |
(((int)x & 0xff) << 16) | (((int)y & 0xff) << 8) | ((int)z & 0xff);
if (x > 255) x = 255; else if (x < 0) x = 0;
if (y > 255) y = 255; else if (y < 0) y = 0;
if (z > 255) z = 255; else if (z < 0) z = 0;
return 0xff000000 | ((int)x << 16) | ((int)y << 8) | (int)z;
}
return g.color(x, y, z);
}
@@ -3389,8 +3398,12 @@ public class PApplet extends Applet
public final int color(int x, int y, int z, int a) {
if (g == null) {
return ((a & 0xff) << 24) |
((x & 0xff) << 16) | ((y & 0xff) << 8) | (z & 0xff);
if (a > 255) a = 255; else if (a < 0) a = 0;
if (x > 255) x = 255; else if (x < 0) x = 0;
if (y > 255) y = 255; else if (y < 0) y = 0;
if (z > 255) z = 255; else if (z < 0) z = 0;
return (a << 24) | (x << 16) | (y << 8) | z;
}
return g.color(x, y, z, a);
}
@@ -3398,8 +3411,12 @@ public class PApplet extends Applet
public final int color(float x, float y, float z, float a) {
if (g == null) {
return (((int)a & 0xff) << 24) |
(((int)x & 0xff) << 16) | (((int)y & 0xff) << 8) | ((int)z & 0xff);
if (a > 255) a = 255; else if (a < 0) a = 0;
if (x > 255) x = 255; else if (x < 0) x = 0;
if (y > 255) y = 255; else if (y < 0) y = 0;
if (z > 255) z = 255; else if (z < 0) z = 0;
return ((int)a << 24) | ((int)x << 16) | ((int)y << 8) | (int)z;
}
return g.color(x, y, z, a);
}

View File

@@ -5399,6 +5399,8 @@ public class PGraphics extends PImage
public final int color(int gray) { // ignore
if (color_rgb255) {
// bounds checking to make sure the numbers aren't to high or low
if (gray > 255) gray = 255; else if (gray < 0) gray = 0;
return 0xff000000 | (gray << 16) | (gray << 8) | gray;
}
calc_color(gray);
@@ -5413,7 +5415,11 @@ public class PGraphics extends PImage
public final int color(int gray, int alpha) { // ignore
if (color_rgb255) {
return (gray << 24) | (gray << 16) | (gray << 8) | gray;
// bounds checking to make sure the numbers aren't to high or low
if (gray > 255) gray = 255; else if (gray < 0) gray = 0;
if (alpha > 255) alpha = 255; else if (alpha < 0) alpha = 0;
return ((alpha & 0xff) << 24) | (gray << 16) | (gray << 8) | gray;
}
calc_color(gray, alpha);
return calci;
@@ -5427,6 +5433,11 @@ public class PGraphics extends PImage
public final int color(int x, int y, int z) { // ignore
if (color_rgb255) {
// bounds checking to make sure the numbers aren't to high or low
if (x > 255) x = 255; else if (x < 0) x = 0;
if (y > 255) y = 255; else if (y < 0) y = 0;
if (z > 255) z = 255; else if (z < 0) z = 0;
return 0xff000000 | (x << 16) | (y << 8) | z;
}
calc_color(x, y, z);
@@ -5441,6 +5452,12 @@ public class PGraphics extends PImage
public final int color(int x, int y, int z, int a) { // ignore
if (color_rgb255) {
// bounds checking to make sure the numbers aren't to high or low
if (a > 255) a = 255; else if (a < 0) a = 0;
if (x > 255) x = 255; else if (x < 0) x = 0;
if (y > 255) y = 255; else if (y < 0) y = 0;
if (z > 255) z = 255; else if (z < 0) z = 0;
return (a << 24) | (x << 16) | (y << 8) | z;
}
calc_color(x, y, z, a);

View File

@@ -285,7 +285,8 @@ public class PImage implements PConstants, Cloneable {
public int get(int x, int y) {
if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) return 0;
return (format == RGB) ?
(pixels[y*width + x] & 0xff000000) : pixels[y*width + x];
(pixels[y*width + x] & 0x00ffffff) : pixels[y*width + x];
//(pixels[y*width + x] & 0xff000000) : pixels[y*width + x];
}

View File

@@ -139,13 +139,13 @@ X casey: i wan't able to get binary() to work at all:
o Typography: Helix won't compile
o works fine, just needs BFont -> PFont
X standalone 'alpha' function for PImage (static methods for alpha fxns)
X Image: Edge, Image: Blur: Alpha not set? The error is easier to see on Blur
X turns out bounds checking wasn't working properly on colors
The biggest problem was the key and mouse functions not working. For example:
Input: Mouse_Functions
Input: Keyboard_Functions
Image: Edge, Image: Blur: Alpha not set? The error is easier to see on Blur
....
_ processing.net -> PClient, PServer
@@ -279,6 +279,8 @@ CORE / PGraphics
b _ lines become 2 pixels thick after a 3D transform
b _ better handling of single-pixel special case
b _ flat_line_retribution is a hack, can go away
b _ lines are conflicting with type in 2D
b _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1094174791;start=0
b _ mgorbet stroke transparency problem
b _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1076383048;start=0
b _ make sure line() commands don't try to have a fill