Hi,
I’ve got a juce Image that I’m stroking into, and would like to be able to iterate over the entire set of pixels in this image periodically to do some calculations based on the image data. Currently, I can accomplish this task by iterating over the entire set of pixels and grabbing each individual pixel by using getPixelAt(), and everything works fine. Of course, I’d rather not do it this way, and would prefer to take the more appropriate approach of accessing the pointer to the pixel data directly via lockPixelDataReadOnly, and not having to call getPixelAt() for each pixel.
The problem is that whenever I do this, all of the pixels I get out the image this way are zero. Here’s the approach I’m taking (recently updated with a chunk of code taken directly from the getPixelAt() implementation…
unsigned char *pixels = image->lockPixelDataReadOnly(0, 0, width, height, lineStride, pixelStride);
for(size_t y=0; y<height; ++y) {
for(size_t x=0; x<width; ++x) {
int index = y*lineStride + x * pixelStride;
Colour c;
if (image->isARGB())
{
PixelARGB p (pixels[index]);
p.unpremultiply();
c = Colour (p.getARGB());
}
else if (sketchedImage->isRGB())
c = Colour (((const PixelRGB*) pixels)->getARGB());
else
c = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *pixels);
a = c.getAlpha();
b = c.getBlue();
g = c.getGreen();
r = c.getRed();
}
}
As mentioned, the a, r, g, b values are all zero when I do it this way. Can someone see where I’m going wrong?
thanks