From 0c8dc41d9f8da0dae8a171880efd9de3010328a1 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 16 Dec 2016 15:49:58 -0500 Subject: image: Add IMG_SavePNG binding. --- sdl2/bindings/image.scm | 3 +++ sdl2/image.scm | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/sdl2/bindings/image.scm b/sdl2/bindings/image.scm index cfdb31d..598c024 100644 --- a/sdl2/bindings/image.scm +++ b/sdl2/bindings/image.scm @@ -54,3 +54,6 @@ RETURN-TYPE and accept arguments of ARG-TYPES." (define-foreign img-load '* "IMG_Load" '(*)) + +(define-foreign img-save-png + int "IMG_SavePNG" '(* *)) diff --git a/sdl2/image.scm b/sdl2/image.scm index e741a04..ba0119b 100644 --- a/sdl2/image.scm +++ b/sdl2/image.scm @@ -29,7 +29,8 @@ #:use-module ((sdl2 bindings image) #:prefix ffi:) #:export (image-init image-quit - load-image)) + load-image + save-png)) (define (image-init) "Initialize dynamically loaded image libraries." @@ -49,3 +50,9 @@ (if (null-pointer? ptr) (sdl-error "load-image" "failed to load image: ~a" file) ((@@ (sdl2 surface) wrap-surface) ptr)))) + +(define (save-png surface file) + "Save SURFACE to FILE as a PNG formatted image." + (unless (zero? (ffi:img-save-png ((@@ (sdl2 surface) unwrap-surface) surface) + (string->pointer file))) + (sdl-error "save-png" "failed to save surface as PNG: ~a" file))) -- cgit v1.2.3