I am developing an emulator that simulates different machines. There are 3 types of pixel formats used by these machines:
- 32-bit 8bpp big endian BGRA
- 16-bit 4bpp big endian RGBX
- 2-bit packed gray scale (white, light grey, dark grey, black), 4 pixels per byte
I am blitting the VRAM contents of the 32-bit capable machines using this function (SDL2):
void Screen_Blit32(uint8_t* vram, SDL_Texture* tex) {
void* src;
void* dst;
int src_pitch, dst_pitch;
uint32_t src_format, dst_format;
src = &vram[0];
src_pitch = (SCREEN_WIDTH + 32) * 4;
src_format = SDL_PIXELFORMAT_BGRA32;
SDL_QueryTexture(tex, &dst_format, NULL, NULL, NULL);
SDL_LockTexture(tex, NULL, &dst, &dst_pitch);
SDL_ConvertPixels(SCREEN_WIDTH, SCREEN_HEIGHT, src_format, src, src_pitch, dst_format, dst, dst_pitch);
SDL_UnlockTexture(tex);
}
or this function (SDL3):
void Screen_Blit32(uint8_t* vram, SDL_Texture* tex) {
void* src;
void* dst;
int src_pitch, dst_pitch;
SDL_PixelFormat src_format, dst_format;
src = &vram[0];
src_pitch = (SCREEN_WIDTH + 32) * 4;
src_format = SDL_PIXELFORMAT_BGRA32;
dst_format = tex->format;
SDL_LockTexture(tex, NULL, &dst, &dst_pitch);
SDL_ConvertPixels(SCREEN_WIDTH, SCREEN_HEIGHT, src_format, src, src_pitch, dst_format, dst, dst_pitch);
SDL_UnlockTexture(tex);
}
Can anyone help with adapting this function for the 16-bit and 2-bit pixel data?