summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2016-12-16 15:49:58 -0500
committerDavid Thompson <dthompson2@worcester.edu>2016-12-16 21:52:36 -0500
commit0c8dc41d9f8da0dae8a171880efd9de3010328a1 (patch)
treef842fd2fac1a69abeb83edc328d2bcc1e05752b5
parent53eb88ff721968299dd59e1c604e1b5714c5f0a5 (diff)
image: Add IMG_SavePNG binding.
-rw-r--r--sdl2/bindings/image.scm3
-rw-r--r--sdl2/image.scm9
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)))