I'm trying to create a pixel buffer for a render bucket but I can't get my head around the pointers. Or the declaration.
Can anyone help me sort this out?
// I need to allocate this:
Code:
struct pixel { unsigned char R;
unsigned char G;
unsigned char B; };
in this
Code:
struct bucket { long double max;
long double min;
long double factor;
int max_it;
int size;
int xStart;
int yStart;
struct pixel *buffer;
char started;
char done; };
Access it in another function
Code:
bucket->buffer[xl+(yl*bucket->size)].R = map(brightness*brightness, 0, 1000, 0, 155);
bucket->buffer[xl+(yl*bucket->size)].G = map(brightness, 0, 255, 0, 155);
bucket->buffer[xl+(yl*bucket->size)].B = map(brightness, 0, 255, 0, 255);
So how do I declare and allocate it?
Code:
int main(int argc, char *argv[])
{
struct bucket bucketlist[buckets_per_frame];
struct pixel* buffer[pixels_per_bucket];
for ( i=0 ; i<buckets_per_frame ; i++ )
{
for ( j=0 ; j<pixels_per_bucket ; j++ )
{
bucketlist[i].buffer[j] = (struct pixel *) malloc(sizeof(struct pixel));
}
}
}