Turns out that the mandrill image file loads as format RGB, even though you do have to use a full four-byte int for each pixel, and the javadoc advises keeping 0xFF in the high byte. I don’t know if this is safe, but setting the format to ARGB after loading the image makes the problem go away. A safer play would probably be to create an ARGB format image of the same dimensions and copy its pixel data from the RGB image to the new image.
Here’s my code with one line added to set the format. Anyone know whether or not this is safe?
PImage imgFace;
PImage imgMandrill;
void setup()
{
size(480, 480);
imgFace = loadImage("Face.png");
imgMandrill = loadImage("Mandrill.png");
imgMandrill.format = ARGB;
imgMandrill.loadPixels();
for(int p = 0; p < imgMandrill.pixels.length; ++p)
{
imgMandrill.pixels[p] = (imgMandrill.pixels[p] & 0xFFFFFF) | 0x40000000;
}
imgMandrill.pixels[0] = imgMandrill.pixels[0] & 0xFFFFFF;
imgMandrill.updatePixels();
}
void draw()
{
background(imgFace);
image(imgMandrill, 0, 0);
}