Added automatic translation of pathnames via namestring.
[cl-devil.git] / il.lisp
blob5be79ea790ac16583659ac16ffbe1ebc7538013b
1 ;;;; cl-devil -- DevIL binding for CL. See README for licensing information.
3 (in-package :il)
5 (define-foreign-library il
6 (:unix (:or "libIL" "libIL.so.1"))
7 (t (:default "libIL")))
8 (use-foreign-library il)
10 (defctype handle :pointer)
11 (defcenum image-type
12 (:unknown #x0000)
13 (:bmp #x0420)
14 (:cut #x0421)
15 (:doom #x0422)
16 (:doom-flat #x0423)
17 (:ico #x0424)
18 (:jpg #x0425)
19 (:jfif #x0425)
20 (:lbm #x0426)
21 (:pcd #x0427)
22 (:pcx #x0428)
23 (:pic #x0429)
24 (:png #x042A)
25 (:pnm #x042B)
26 (:sgi #x042C)
27 (:tga #x042D)
28 (:tif #x042E)
29 (:chead #x042F)
30 (:raw #x0430)
31 (:mdl #x0431)
32 (:wal #x0432)
33 (:lif #x0434)
34 (:mng #x0435)
35 (:jng #x0435)
36 (:gif #x0436)
37 (:dds #x0437)
38 (:dcx #x0438)
39 (:psd #x0439)
40 (:exif #x043A)
41 (:psp #x043B)
42 (:pix #x043C)
43 (:pxr #x043D)
44 (:xpm #x043E)
45 (:hdr #x043F)
46 (:jasc-pal #x0475))
48 (defcenum data-format
49 (:colour-index #x1900)
50 (:color-index #x1900)
51 (:rgb #x1907)
52 (:rgba #x1908)
53 (:bgr #x80E0)
54 (:bgra #x80E1)
55 (:luminance #x1909)
56 (:luminance-alpha #x190A))
58 (defcenum data-type
59 (:byte #x1400)
60 (:unsigned-byte #x1401)
61 (:short #x1402)
62 (:unsigned-short #x1403)
63 (:int #x1404)
64 (:unsigned-int #x1405)
65 (:float #x1406)
66 (:double #x140A))
68 (defcenum error
69 (:no-error #x0000)
70 (:invalid-enum #x0501)
71 (:out-of-memory #x0502)
72 (:format-not-supported #x0503)
73 (:internal-error #x0504)
74 (:invalid-value #x0505)
75 (:illegal-operation #x0506)
76 (:illegal-file-value #x0507)
77 (:invalid-file-header #x0508)
78 (:invalid-param #x0509)
79 (:could-not-open-file #x050A)
80 (:invalid-extension #x050B)
81 (:file-already-exists #x050C)
82 (:out-format-same #x050D)
83 (:stack-overflow #x050E)
84 (:stack-underflow #x050F)
85 (:invalid-conversion #x0510)
86 (:bad-dimensions #x0511)
87 (:file-read-error #x0512)
88 (:file-write-error #x0512)
89 (:lib-gif-error #x05E1)
90 (:lib-jpeg-error #x05E2)
91 (:lib-png-error #x05E3)
92 (:lib-tiff-error #x05E4)
93 (:lib-mng-error #x05E5)
94 (:unknown-error #x05FF))
96 (defcenum mode ; there are some awfully
97 (:version-num #x0DE2) ; non-descript names in
98 (:image-width #x0DE4) ; DevIL...
99 (:image-height #x0DE5)
100 (:image-depth #x0DE6)
101 (:image-size-of-data #x0DE7)
102 (:image-bpp #x0DE8)
103 (:image-bytes-per-pixel #x0DE8)
104 (:image-bits-per-pixel #x0DE9)
105 (:image-format #x0DEA)
106 (:image-type #x0DEB)
107 (:palette-type #x0DEC)
108 (:palette-size #x0DED)
109 (:palette-bpp #x0DEE)
110 (:palette-num-cols #x0DEF)
111 (:palette-base-type #x0DF0)
112 (:num-images #x0DF1)
113 (:num-mipmaps #x0DF2)
114 (:num-layers #x0DF3)
115 (:active-image #x0DF4)
116 (:active-mipmap #x0DF5)
117 (:active-layer #x0DF6)
118 (:cur-image #x0DF7)
119 (:image-duration #x0DF8)
120 (:image-planesize #x0DF9)
121 (:image-bpc #x0DFA)
122 (:image-offx #x0DFB)
123 (:image-offy #x0DFC)
124 (:image-cubeflags #x0DFD)
125 (:image-origin #x0DFE)
126 (:image-channels #x0DFF))
128 (define-foreign-type pathname-string-type ()
130 (:actual-type :string)
131 (:simple-parser pathname-string))
132 (eval-when (:compile-toplevel :load-toplevel)
133 (defmethod expand-to-foreign-dyn (value var body (type pathname-string-type))
134 `(with-foreign-string (,var (if (pathnamep ,value) (namestring ,value) ,value))
135 ,@body)))
137 (defcfun ("ilInit" init) :void)
138 (defcfun ("ilShutDown" shutdown) :void)
139 (defcfun ("ilGenImages" %gen-images) :void (num :int) (images :pointer))
140 (defcfun ("ilBindImage" bind-image) :void (image :int))
141 (defcfun ("ilDeleteImages" delete-images) :void (num :int) (images :pointer))
142 (defcfun ("ilLoadImage" load-image) :boolean (file-name pathname-string))
143 (defcfun ("ilLoad" load) :boolean (type image-type) (file-name pathname-string))
144 (defcfun ("ilLoadF" load-f) :boolean (type image-type) (file handle))
145 (defcfun ("ilLoadL" load-l) :boolean (type image-type) (lump :pointer) (size :uint))
146 (defcfun ("ilSaveImage" save-image) :boolean (file-name pathname-string))
147 (defcfun ("ilSave" save) :boolean (type image-type) (file-name pathname-string))
148 (defcfun ("ilSaveF" save-f) :boolean (type image-type) (file handle))
149 (defcfun ("ilSaveL" save-l) :boolean (type image-type) (lump :pointer) (size :uint))
150 (defcfun ("ilTexImage" tex-image) :boolean
151 (width :uint) (height :uint) (depth :uint) (bpp :uint8) (format data-format) (type data-type) (data :pointer))
152 (defcfun ("ilGetData" get-data) :pointer)
153 (defcfun ("ilCopyPixels" copy-pixels) :uint
154 (x-offset :uint) (y-offset :uint) (z-offset :uint) (width :uint) (height :uint) (depth :uint) (format data-format) (type data-type) (data :pointer))
155 (defcfun ("ilSetData" set-data) :pointer)
156 (defcfun ("ilSetPixels" set-pixels) :uint
157 (x-offset :uint) (y-offset :uint) (z-offset :uint) (width :uint) (height :uint) (depth :uint) (format data-format) (type data-type) (data :pointer))
158 (defcfun ("ilCopyImage" copy-image) :boolean (source :uint))
159 (defcfun ("ilOverlayImage" overlay-image) :boolean (source :uint) (x-coord :int) (y-coord :int) (z-coord :int))
160 (defcfun ("ilBlit" blit) :boolean (source :uint) (dest-x :int) (dest-y :int) (dest-z :int) (src-x :int) (src-y :int) (src-z :int) (width :uint) (height :uint) (depth :uint))
161 (defcfun ("ilGetError" get-error) error)
163 (defcfun ("ilGetInteger" get-integer) :uint (mode mode))