shithub: npe

Download patch

ref: 13c0e712ae7d999f8df7f335cb6eaf7e48a3feb9
parent: 130289e73d40b0769065b2ecffd2e635125c7783
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Tue Jun 15 11:30:11 EDT 2021

sdl2: add SDL_CreateRGBSurfaceWithFormat; use pitch in SDL_CreateRGBSurfaceFrom

--- a/include/npe/SDL2/SDL.h
+++ b/include/npe/SDL2/SDL.h
@@ -71,6 +71,7 @@
 SDL_Cursor *SDL_GetDefaultCursor(void);
 void SDL_SetCursor(SDL_Cursor *cursor);
 void SDL_FreeCursor(SDL_Cursor *cursor);
+SDL_Surface *SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int w, int h, int bpp, Uint32 fmt);
 SDL_Surface *SDL_CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 rm, Uint32 gm, Uint32 bm, Uint32 am);
 SDL_Surface *SDL_CreateRGBSurfaceFrom(Uint32 *pixels, int w, int h, int bpp, int pitch, Uint32 rm, Uint32 gm, Uint32 bm, Uint32 am);
 Uint32 SDL_MapRGB(SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b);
--- a/libnpe_sdl2/sdl2.c
+++ b/libnpe_sdl2/sdl2.c
@@ -300,12 +300,12 @@
 }
 
 SDL_Surface *
-SDL_CreateRGBSurface(Uint32, int w, int h, int bpp, Uint32 rm, Uint32 gm, Uint32 bm, Uint32 am)
+SDL_CreateRGBSurface(Uint32 flags, int w, int h, int bpp, Uint32 rm, Uint32 gm, Uint32 bm, Uint32 am)
 {
 	SDL_Surface *s;
 	int n;
 
-	USED(rm, gm, bm, am); /* FIXME masks */
+	USED(flags, rm, gm, bm, am); /* FIXME flags & masks */
 
 	n = w*h*bpp/8;
 	if((s = calloc(1, sizeof(*s)+n)) == nil){
@@ -328,17 +328,29 @@
 SDL_CreateRGBSurfaceFrom(Uint32 *pixels, int w, int h, int bpp, int pitch, Uint32 rm, Uint32 gm, Uint32 bm, Uint32 am)
 {
 	SDL_Surface *s;
-	int n;
+	int n, y;
 
-	USED(pitch); /* FIXME pitch */
-
 	if((s = SDL_CreateRGBSurface(0, w, h, bpp, rm, gm, bm, am)) == nil)
 		return nil;
 
-	n = w*h*bpp/8;
-	memmove(s->pixels, pixels, n);
+	n = w*bpp/8;
+	for(y = 0; y < h; y++){
+		memmove(s->pixels + y*n, pixels, n);
+		pixels += pitch / sizeof(Uint32);
+	}
 
 	return s;
+}
+
+SDL_Surface *
+SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int w, int h, int bpp, Uint32 fmt)
+{
+	if(fmt != SDL_PIXELFORMAT_ARGB8888){
+		werrstr("SDL_CreateRGBSurfaceWithFormat: FIXME non-argb8888");
+		return nil;
+	}
+
+	return SDL_CreateRGBSurface(flags, w, h, bpp, 0, 0, 0, 0);
 }
 
 void