Add SDL2_image bindings.
[guile-sdl2.git] / sdl2 / bindings / image.scm
1 ;;; guile-sdl2 --- FFI bindings for SDL2
2 ;;; Copyright © 2015 David Thompson <davet@gnu.org>
3 ;;;
4 ;;; This file is part of guile-sdl2.
5 ;;;
6 ;;; Guile-sdl2 is free software; you can redistribute it and/or modify
7 ;;; it under the terms of the GNU Lesser General Public License as
8 ;;; published by the Free Software Foundation; either version 3 of the
9 ;;; License, or (at your option) any later version.
10 ;;;
11 ;;; Guile-sdl2 is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ;;; General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU Lesser General Public
17 ;;; License along with guile-sdl2. If not, see
18 ;;; <http://www.gnu.org/licenses/>.
19
20 ;;; Commentary:
21 ;;
22 ;; Low-level FFI bindings for SDL2_image.
23 ;;
24 ;;; Code:
25
26 (define-module (sdl2 bindings image)
27 #:use-module (system foreign)
28 #:use-module (sdl2 config))
29
30 (define sdl-image-func
31 (let ((lib (dynamic-link %libsdl2-image)))
32 (lambda (return-type function-name arg-types)
33 "Return a procedure for the foreign function FUNCTION-NAME in
34 the SDL2_image shared library. That function must return a value of
35 RETURN-TYPE and accept arguments of ARG-TYPES."
36 (pointer->procedure return-type
37 (dynamic-func function-name lib)
38 arg-types))))
39
40 (define-syntax-rule (define-foreign name return-type func-name arg-types)
41 (define-public name
42 (sdl-image-func return-type func-name arg-types)))
43
44 (define-public IMG_INIT_JPG #x00000001)
45 (define-public IMG_INIT_PNG #x00000002)
46 (define-public IMG_INIT_TIF #x00000004)
47 (define-public IMG_INIT_WEBP #x00000008)
48
49 (define-foreign img-init
50 int "IMG_Init" (list int))
51
52 (define-foreign img-quit
53 void "IMG_Quit" '())
54
55 (define-foreign img-load
56 '* "IMG_Load" '(*))