color4_image and color3_image

Hi,

imgdata.rawdata has ushort (*color4_image)[4] and ushort (*color3_image)[3]. For images where these are actually used (Foveon etc.) I want to access the data but am a bit unsure how. I'm not a C or C++ expert, so maybe this is a silly question. Does (*color3_image)[3] mean that color3_image is an array of 3 pointers where each points to a separate array for a single color? So the arrays are not together one contiguous chunk of memory but separate? The reason why I'm a bit confused is because of code like &c3image[(row+S.top_margin)*S.raw_pitch] where it seems that it's actually a 2D array (of the image size) of pointers each pointing to a separate array of size 3. But that doesn't sound right, so I guess I don't understand it yet.

Thanks already,
Maik

Forums: 

ushort (*color3_image)[3]

ushort (*color3_image)[3] means 'array, contains 3-element items of ushort).
Also:
S.raw_pitch is row pitch in bytes, not array elements. So, the code:

unsigned char *bufferptr = (unsigned char*)imgdata.rawdata.color3_image; // unsigned char to easy address calculations
// In byte ariphmetics;
unsigned char *rowptr = bufferptr + row*S.raw_pitch; // => will point to row beginning
unsigned char *pixelptr = bufferptr + row*S.raw_pitch + col*(3*sizeof(ushort)); // each pixel is 3-ushort, so 3*sizeof
 
ushort *pixel  = (ushort*) pixelptr; // same address, but converted to ushort
  red = pixel[0];// .... 
 
// in ushort (*)[3] units
 
ushort (*rowptr)[3] =  (ushort (*)[3]) &bufferptr[row * S.raw_pitch]; // We use the trick that bufferptr is unsigned char*, so sizeof == 1, so index does not multiplied by item size
 
red =  rowptr[col][0]; // red at row, col

-- Alex Tutubalin