I ave a more or an efficiency question, I have an array of pixels now the array is built up like this
unsignedchar* blue = newunsignedchar[W*H*3];
each pixel consists out of 3 chars B,G,R so pixel one is
1 2 3
blue[i] = 255;
blue[i + 1] = 0;
blue[i + 2] = 0;
now I can loop though the whole array and clear the array one pixel at a time to the color i want, but what i really want to do is just set the whole array to a color.
I could do something like this
memset(blue, 255, W*H*3);
but then i set all the color values to 255 and then i get white.
so my question is is there a fast way to fill an array with lets say a smaller array?
unsignedchar *** img = newunsignedchar[3][width][height]; Illegal C++. All array dimensions aside from first should be compile time constants.
Even if it was legal, return type will be unsigned char (*)[width][height] and not triple pointer.
Again, lines 13-19 can be replaced by std::vector<std::vector<std::vector<unsignedchar> > > img{3, {3, {3}}};
Also OP want fast method (he uses 1D representation of 3D array, and it seems like it is a screen buffer which is probably has some requirements on memory layout).
OP, It seems like your first approach would be best and it is probably will be neatly optimised. You can try to create a struct for pixel, check if no padding bytes were added and either create an array of structs or cast your buffer pointer to struct pointer and use it. It might make your code clearer, but I doubt that will make significant improvements.