Pixel matrix

Hello, when i have this:
typedef unsigned char pixel[3];

and then pixel** fillArea (const pixel *const *const picture,size_t width, size_t height)

then i have a matrix of rgb pixels, but how to fill it? I mean with the standart method to fill the matrix like:

1
2
3
4
5
6
7
  for(int i=0; i<rows; i++)
{
for(int j=0; j<cols; j++)
{
cin>>matrix[i][j];
}
}


how to allocate such a matrix?
then i just get only one of the values of the rgb cell, like an rgb is a number for the red a number for the green and a number for the blue. how to fill this matrix so i can get the average of the three rgb numbers?

Last edited on
pseudocode

pixel ** pic;
pic = new pixel*[rows];
for all the rows
pic[row] = new pixel[cols];

now pic[row][col][green] for example

this is woefully inefficient (not a solid block of memory, page faults, cant do .write() or .read() on it, cant memcpy, and more). I strongly advise you instead work in either raw bytes:
pic = new unsigned char[rows*cols*3];
or if you must:
pic = new pixel[rows*cols];

if you want a greyscale image, you have 2 choices
fill in the pic where red=green=blue = average of original rgb
or
make pic = new unsigned char[rows*cols] and put the average in each spot.

see if your library supports single dimensional allocated images instead...
Topic archived. No new replies allowed.