I think the problem is poorly phrased. (In fact, it seems to me to be deliberately confusing.) The endianness bit is nonsense — you should not be treating any of this like anything but an array of bytes.
All you are being asked to do is take a byte array of the form:
r g b a r g b a r g b a
and eliminate every fourth byte:
r g b r g b r g b
(I have used “r” for what the problem labels as “11”, and “g” for “22”, etc.)
I need to convert RGBA pixel to RGB pixel, there by eliminating Alpha value. Exactly what you mentioned here is correct. How can I convert thirty two bit PIXEL to twenty four bit PIXEL?
Forget the PIXEL. The problem is asking you to dink with byte arrays.
[edit] Part of the problem is to recognize that the way that the information is presented to you is confusing. Focusing on the PIXEL and 32/24 bit values is a distraction.
@DizzyDon Here opaque means transparency(alpha). Typical alpha value is between 0.0(fully transparent) to 1.0(fully opaque). Ideally from RGBA pixel image, need to eliminate Alpha and finally RGB image is made. I was thinking about both image types to be uint8_t.
int main()
{
constint syze{3};
uint32_t rgba[syze]{0xf4cc2211,0x44331100,0x4422ff11};
uint8_t rgb[syze*3+1]; //cheating a little, 1 extra byte to make it simple
//the important part -------------------------
for(int i{0},j{0}; i < syze*3; i+=3)
{
uint32_t *p {(uint32_t*)(&rgb[i])};
*p = rgba[j++]; // >>8 if you want the first 3 bytes instead of last 3
//if wrong endian, swap rgb[i] and rgb[i+2] here:
//(if on a chip with endian reverse assembly command, use that on the int instead)
std::swap(rgb[i],rgb[i+2]);
}
//----------------------------------------
//uniportant print of output
for(int i{0}; i < syze*3; i+=3)
{
printf("%x %x %x\n", rgb[i], rgb[i+1], rgb[i+2]);
}
}
cc 22 11
33 11 0
22 ff 11
if you need performance tuning, the swap has to be avoided. Its still probably best to let the cpu do that if it can.
May I know how you arrive at these hard coded values? Are these assumptions here?
{0xf4cc2211}, {0x44331100}, {0x4422ff11} . I guess you assume little endian here, A:44,B:33,G:22,R:11 in memory and then read entire RGBA array and write it to RGB array, but after every 4bytes eliminate 255 for alpha? For RGBA image, the number is stored as a 32bit unsigned integer. So here the individual values will be like RRRRRRRR GGGGGGGG BBBBBBBB AAAAAAAA. Also there are 32 individual bits, 8 each of R, G, B, and A. But in my case here, ideally it must convert RGBA 32bit to RGB 24bit image.