What is the best way to handle an image in memory for image processing (filters, effects, drawing)?
Storing the image just in 1D array or would it be better to store it in a 2D array? However, is it
better to read each color R,G,B,A as byte for a 32bit image or to read it just as long and using shifts
to manipulate each color?
At the moment i am working on a test project, where the image is stored in a 1D buffer.
void DrawGreyscale()
{
temp = bitsDib / 8;
int i;
BYTE r, g, b, y;
for (i = 0; i < cxDib * cyDib * temp; i+=temp) {
b = bitmap2[i ]; // Blue
g = bitmap2[i + 1]; // Green
r = bitmap2[i + 2]; // Red
y = (r + g + b) / 3;
bitmap[i] = y;
bitmap[i + 1] = y;
bitmap[i + 2] = y;
}
}
Any improvment ideas for easy and fast image processing (clean code/handling)?
An 1D array gives nice speed improvments for using filters/effects on the complete image, because only
one loop is required. But when wanting to manipulate a special x,y position in the 1D array, a lot of
extra muls, divs, mods are required and may slow down operations a lot.
How does Photoshop stores imagedatas internally? 1D, 2D? Thanks for feeedback.