Convert color notation in an array

so, i want to take an inventory of a bunch of my pixels in an array, and loadPixels() seems to generate that array fine, but I can’t figure out how to read that data, much less use it with other code.

any idea how to convert it all into rgb values I (and other bits of code) can use? preferably en masse?

Color information is stored in what’s referred to as a packed 32-bit integer, representing alpha, red, green and blue. Processing provides convenience methods that allow you to extract both hsb and rgb color information:-

get(x, y); // returns a color value from pixel array at a coordinate
color c = get(x, y);
alpha(c);
red(c);
blue(c);
green(c)
hue(c);
saturation(c);
brightness(c);

Although if you want to do this efficiently you may need learn about bitwise operations.
You can use get to get the color at a particular x, y coordinates in the pixel array, the reference is your friend.

1 Like

so I need to make a second array copying data from the first with get (x y) for each pixel rather than operating on the data in the loadPixels array. okay!

sorry, that sounds even more confused?
possibly try again,

there are 2 ways to get to the color of a pixel or set it.
SLOW and EASY

color c = get(x, y);
set(x,y,c);

FAST and TRICKY

loadPixels();
int i = x + y * width;
color c = pixels[i];
pixels[i] = c;
updatePixels();

even check https://processing.org/reference/pixelDensity_.html


once you got the color here named ‘c’
you can read/change it

read works anyway, for understand / write must know the
https://processing.org/reference/colorMode_.html

also can use more faster bit operations on it.


so partial copy to array / smaller array or image is possible this way,
but depending on what you need
https://processing.org/reference/PImage.html
https://processing.org/reference/PImage_copy_.html the 9 parameter usage
might already do the job.

1 Like

If you told us what you wanted to do with the colors we could help you more, it is quite possible you don’t need to do individual pixel manipulation at all, when you can do things like apply a filter to graphics object or blend. For crazy weird stuff someone might have already created a glsl filter you could use that’s probably a bit advanced.

1 Like

reading the color data, modifying sounds with it. the sounds bit was pretty intuitive and the documentation got me where I was going up until the part where i might base something on the total amount of red in the left side of the image minus the amount of blue in the top right corner

There is an example sketch that should help you get started:-
Histogram Sketch