Мне нужно преобразовать rgba8 в rgba5551 вручную. Я нашел полезный код из другого сообщения и хочу его модифицировать для преобразования из rgba8 в rgba5551. У меня нет опыта работы с bitewise, и мне не повезло с кодом.Вручную Преобразование rgba8 в rgba5551
void* rgba8888_to_rgba4444(void* src, int src_bytes)
{
// compute the actual number of pixel elements in the buffer.
int num_pixels = src_bytes/4;
unsigned long* psrc = (unsigned long*)src;
unsigned short* pdst = (unsigned short*)src;
// convert every pixel
for(int i = 0; i < num_pixels; i++){
// read a source pixel
unsigned px = psrc[i];
// unpack the source data as 8 bit values
unsigned r = (px << 8) & 0xf000;
unsigned g = (px >> 4) & 0x0f00;
unsigned b = (px >> 16) & 0x00f0;
unsigned a = (px >> 28) & 0x000f;
// and store
pdst[i] = r | g | b | a;
}
return pdst;
}