shithub: npe

Download patch

ref: 9c1c52a8cf07ab0c308c494e58ddf38988c98d13
parent: 8d94c00a31f8ec7621fae55d534a716b867c535a
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Fri Jan 7 11:18:15 EST 2022

sdl: add XRGB8888 (and RGB888 alias) pixel format

--- a/libnpe_sdl2/sdl2.c
+++ b/libnpe_sdl2/sdl2.c
@@ -24,6 +24,10 @@
 	.format = SDL_PIXELFORMAT_ARGB8888,
 };
 
+static SDL_PixelFormat xrgb8888 = {
+	.format = SDL_PIXELFORMAT_XRGB8888,
+};
+
 static SDL_Window onewin;
 static SDL_Renderer oneren;
 static Memimage *back;
@@ -180,13 +184,13 @@
 {
 	SDL_Texture *t;
 
-	if(format != SDL_PIXELFORMAT_ARGB8888){
-		werrstr("SDL_CreateTexture: only SDL_PIXELFORMAT_ARGB8888 is supported");
+	if(format != SDL_PIXELFORMAT_ARGB8888 && format != SDL_PIXELFORMAT_XRGB8888){
+		werrstr("SDL_CreateTexture: only SDL_PIXELFORMAT_*RGB8888 is supported");
 		goto err;
 	}
 	if((t = malloc(sizeof(*t))) == nil)
 		goto err;
-	if((t->m = allocmemimage(Rect(0, 0, w, h), ARGB32)) == nil){
+	if((t->m = allocmemimage(Rect(0, 0, w, h), format == SDL_PIXELFORMAT_ARGB8888 ? ARGB32 : XRGB32)) == nil){
 		free(t);
 		goto err;
 	}
@@ -346,6 +350,8 @@
 
 	if(fmt == SDL_PIXELFORMAT_ARGB8888)
 		f = &argb8888;
+	else if(fmt == SDL_PIXELFORMAT_XRGB8888)
+		f = &xrgb8888;
 	else{
 		werrstr("SDL_CreateRGBSurfaceWithFormat: FIXME format %8ux not implemented", fmt);
 		return nil;
@@ -692,8 +698,8 @@
 
 	USED(pitch); /* FIXME pitch & fmt */
 
-	if(fmt != SDL_PIXELFORMAT_ARGB8888){
-		werrstr("SDL_RenderReadPixels: FIXME non-argb8888");
+	if(fmt != SDL_PIXELFORMAT_ARGB8888 && fmt != SDL_PIXELFORMAT_XRGB8888){
+		werrstr("SDL_RenderReadPixels: FIXME non-*rgb8888");
 		return -1;
 	}