From ae44478b30d890fe0fb04022f44d474dcdcc3f9d Mon Sep 17 00:00:00 2001 From: Lassi Pulkkinen Date: Thu, 31 Oct 2024 03:11:21 +0200 Subject: Initial commit (import old repo) --- sdl2/image/image.ha | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 sdl2/image/image.ha (limited to 'sdl2/image/image.ha') diff --git a/sdl2/image/image.ha b/sdl2/image/image.ha new file mode 100644 index 0000000..32f8f3d --- /dev/null +++ b/sdl2/image/image.ha @@ -0,0 +1,46 @@ +// TODO: Flesh me out +// TODO: SDL_RWops +use sdl2; +use types::c; + +// Flags for [[IMG_Init]]. +export type IMG_InitFlags = enum int { + NONE = 0, + JPG = 0x00000001, + PNG = 0x00000002, + TIF = 0x00000004, + WEBP = 0x00000008, +}; + +@symbol("IMG_Init") fn _IMG_Init(flags: IMG_InitFlags) int; + +// Loads dynamic libraries and prepares them for use. Flags should be one or +// more flags from [[IMG_InitFlags]] OR'd together. +export fn IMG_Init(flags: IMG_InitFlags) (void | sdl2::error) = { + return sdl2::wrapvoid(_IMG_Init(flags)); +}; + +// Unloads libraries loaded with [[IMG_Init]] +export @symbol("IMG_Quit") fn IMG_Quit() void; + +@symbol("IMG_Load") fn _IMG_Load(file: const *c::char) nullable *sdl2::SDL_Surface; + +// Load an image from a file path. +export fn IMG_Load(file: str) (*sdl2::SDL_Surface | sdl2::error) = { + const file = c::fromstr(file); + defer free(file); + return sdl2::wrapptr(_IMG_Load(file))?: *sdl2::SDL_Surface; +}; + +@symbol("IMG_LoadTexture") fn _IMG_LoadTexture(SDL_Renderer: *sdl2::SDL_Renderer, + file: const *c::char) nullable *sdl2::SDL_Texture; + +// Load an image directly into a render texture. +export fn IMG_LoadTexture( + SDL_Renderer: *sdl2::SDL_Renderer, + file: str, +) (*sdl2::SDL_Texture | sdl2::error) = { + const file = c::fromstr(file); + defer free(file); + return sdl2::wrapptr(_IMG_LoadTexture(SDL_Renderer, file))?: *sdl2::SDL_Texture; +}; -- cgit v1.2.3