byte* bgra = byte array of a BGRA formatted bitmap image;
byte* r = new byte[Height*Width];
for (int i = 0; i < Height; i++)
{
for (int j = 0; j < Width; j++)
{
int offset = i*Width + j;
r[offset] = bgra[offset*4 + 2];
}
}
delete[] r;
I'm using the above code to obtain red channel values from a byte array of a BGRA bitmap image. The image is formatted as:
B G R A B G R A... (Size of W*H*4)
I want to obtain a byte array of
R R R R... (Size of W*H)
Is there a more efficient way of doing this without using for loops?