We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Getting started with image creation and manipulation. Ran example "LinearImage" trying to figure out pixel color "set" and "get". But, whoa, loadPixels() is used both as a method applied to the already-created instance "img" and all by itself. Note this snippet with my added comments:
void setup() {
size(640, 360);
stroke(255);
img = loadImage("sea.jpg"); // define previously declared PImage instance
img.loadPixels(); // fill pixel array field of "img" using PImage class method
loadPixels(); // Yipes! Create another pixels[] not attached to any PImage
}
Evidently the stand-alone call to loadPixels() creates an independent array of pixels[] since there is such a reference below in this line in the draw() block:
for (int y = 0; y < img.height; y++) {
arrayCopy(img.pixels, signalOffset, pixels, y*width, img.width);
If so, can one do a stand-alone "loadPixels()" more than once and have access to additional pixel arrays (of uncertain size and unknown name/label/address)? By the way, although this example confused me, I DO appreciate all the well-organized examples downloaded with Processing.
Answers
loadPixels() alone is loading the array containing display window pixels.
Processing's canvas is itself a PGraphics object. Its reference is stored in variable g! @-)
And PGraphics is a sub-class of PImage. That's why it got pixels[] as well. >-)
When we issue a loadPixels(), pixels[] is merely filled up w/ current image representation as an array of pixel colors.
It's not created, 'cause pixels[] is a field of class PImage. And it's always there! 8-X
In the same vein, updatePixels() re-copies pixels[]'s content back to its PImage's internal format.
A simple example demonstrating that drawing w/ or w/o specifying variable g is the same thing: O:-)
Thanks _vk and GoToLoop. The situation may be clearing up. Let me review in simple terms (the kind I best understand):
I'll keep exploring the examples and documentation. The examples are a real treasure 'cause one can hack up the code to explore various effects.
My next challenge is how to enforce something like CR/LF in this editor! :-/
A single empty line before your list made it a real list. I edited your message to add it. B-)
And basically, your analysis / summary is right.
Just one remark: loadPixels() isn't necessary, actually, for a PImage (but it is mandatory for a PGraphics) in default (JAVA2D) mode in Java mode.
It is good practice to always use it, because it can fail in Android mode and perhaps in other modes (OpenGL? JavaScript?).