Skip to content

Commit

Permalink
* The IL:CLEAR-IMAGE function I wrote was a re-write of an existing f…
Browse files Browse the repository at this point in the history
…unction, so I replaced it with the DevIL version and removed my own.

* Enabled the ILU:IMAGE-PARAMETER function by writing the missing C enums.
  • Loading branch information
jtza8 committed May 6, 2011
1 parent b9c7f7c commit ce72ca3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 46 deletions.
4 changes: 4 additions & 0 deletions il.lisp
Expand Up @@ -245,6 +245,10 @@
(deferrwrap flip-image))

(defcfun ("ilDetermineType" determine-type) image-type (pathname pathname-string))
(defcfun ("ilClearColour" clear-colour) :void
(red :uint8) (green :uint8) (blue :uint8) (alpha :uint8))
(defcfun ("ilClearImage" %clear-image) :boolean)
(deferrwrap clear-image)

(defun check-error ()
(let ((error (get-error)))
Expand Down
24 changes: 23 additions & 1 deletion ilu.lisp
Expand Up @@ -46,6 +46,27 @@
(:image-origin #x0DFE)
(:image-channels #x0DFF))

(defcenum img-param-name
(:filter #x2600)
(:placement #x700))

(defcenum img-param
(:bilinear #x2603)
(:linear #x2602)
(:nearest #x2601)
(:scale-bell #x2606)
(:scale-box #x2604)
(:scale-bspline #x2607)
(:scale-lanczos3 #x2608)
(:scale-mitchell #x2609)
(:scale-triangle #x2605)
(:center #x705)
(:lower-left #x701)
(:lower-right #x702)
(:upper-left #x703)
(:upper-right #x704))


(defcfun ("iluInit" init) :void)

(defcfun ("iluAlienify" %alienify) :boolean)
Expand Down Expand Up @@ -88,7 +109,8 @@
;; (defcfun ("iluGetImageInfo" get-image-info) :void (info :pointer))
(defcfun ("iluGetInteger" get-integer) :int (mode mode))
;; (defcfun ("iluGetString" get-string) :string)
;; (defcfun ("iluImageParameter" image-parameter) :void (pname pname) (param param))
(defcfun ("iluImageParameter" image-parameter) :void
(pname img-param-name) (param img-param))
(defcfun ("iluInvertAlpha" %invert-alpha) :boolean)
(deferrwrap invert-alpha)
(defcfun ("iluMirror" %mirror) :boolean)
Expand Down
3 changes: 2 additions & 1 deletion package.lisp
Expand Up @@ -28,6 +28,7 @@
#:image-bits-per-pixel
#:image-origin
#:copy-palette
#:clear-colour
#:clear-image
;; bindings
#:BIND-IMAGE
Expand Down Expand Up @@ -134,7 +135,7 @@
:swap-colors
;; :get-image-info
;; :get-string
;; :image-parameter
:image-parameter
))

(defpackage #:ilut
Expand Down
44 changes: 0 additions & 44 deletions utilities.lisp
Expand Up @@ -94,47 +94,3 @@
(pointer (get-palette)))
(bind-image dest)
(register-palette pointer (* ncols bpp) type)))

; The standard C lib is loaded by default. I'm not entirely sure where to put
; the following:
(defcfun ("memset" memset) :pointer
(dest :pointer) (value :int) (size :unsigned-int))

(defcfun ("memcpy" memcpy) :pointer
(dest :pointer) (src :pointer) (size :unsigned-int))

(defun clear-image (&rest channel-values)
"Clears the bound image by setting the channel values for all pixels."
(let* ((iterator (get-data))
(data iterator)
(bytes-per-pixel (get-integer :image-bytes-per-pixel))
(width (get-integer :image-width))
(height (get-integer :image-height))
(data-type (ecase (foreign-enum-keyword
'data-type (get-integer :image-type))
(:byte :int8)
(:double :double)
(:float :float)
(:int :int)
(:short :short)
(:unsigned-int :unsigned-int)
(:unsigned-byte :uint8)
(:unsigned-short :unsigned-short)))
(data-type-size (foreign-type-size data-type))
(row-size (* width bytes-per-pixel)))
(assert (= (* data-type-size (length channel-values)) bytes-per-pixel) ()
"incorrect channel count")
(if (apply #'= (cons 0 channel-values))
(memset data 0 (* width height bytes-per-pixel))
(with-foreign-object (src-pixel :uint8 bytes-per-pixel)
(let ((iterator src-pixel))
(dolist (channel channel-values)
(setf (mem-aref iterator data-type)
channel)
(incf-pointer iterator data-type-size)))
(dotimes (i width)
(memcpy iterator src-pixel bytes-per-pixel)
(incf-pointer iterator bytes-per-pixel))
(dotimes (i (1- height))
(memcpy iterator data row-size)
(incf-pointer iterator row-size))))))

0 comments on commit ce72ca3

Please sign in to comment.