diff options
-rw-r--r-- | sdl2/bindings/image.scm | 3 | ||||
-rw-r--r-- | sdl2/image.scm | 9 |
2 files changed, 11 insertions, 1 deletions
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))) |