I am trying to figure out what the CheckAlpha argument to Pgraphics does - and how and why - and have chased my confusion down to line 281 of LINK UPDATED the core docs
if ((pixels[i] & 0xff000000) != 0xff000000)
It’s checking for transparency, and setting the mode to ARGB if it finds it. But:
why is it checking for transparency?
how does this conditional work?
It’s ANDing the value of the pixel with a hex value, and checking that the result isn’t that value. Somehow, this tells you about whether there is transparency.
/**
* Check the alpha on an image, using a really primitive loop.
*/
private void checkAlpha() {
if (pixels == null) {
return;
}
for (int i = 0; i < pixels.length; i++) {
// since transparency is often at corners, hopefully this
// will find a non-transparent pixel quickly and exit
if ((pixels[i] & 0xff000000) != 0xff000000) {
format = ARGB;
break;
}
}
}
The PImage constructor initializes the format attribute to RGB and this method changes the format attribute to ARGB if it finds a pixel with transparency i.e. 0xAA != 0xFF
Obviously some other methods in this class need to be aware of format for their implementation
It is also a private function so we can’t use it directly.