PImage.alpha tweaks

This commit is contained in:
benfry
2004-09-02 21:25:40 +00:00
parent 84694d833f
commit 6fee49422d
3 changed files with 30 additions and 8 deletions

View File

@@ -172,13 +172,22 @@ 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 != pixels.length) {
if (alpha.length != image.pixels.length) {
System.err.println("alpha(): the mask image must be the same size");
return;
}
for (int i = 0; i < pixels.length; i++) {
pixels[i] = pixels[i] & 0xffffff | ((alpha[i] & 0xff) << 24);
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 (RGBA style)
@@ -191,7 +200,7 @@ public class PImage implements PConstants, Cloneable {
}
}
*/
format = RGBA;
image.format = RGBA;
}
@@ -202,6 +211,10 @@ public class PImage implements PConstants, Cloneable {
alpha(alpha.pixels);
}
static public void alpha(PImage image, PImage alpha) {
alpha(image, alpha.pixels);
}
/**