[imago-devel] IMAGO images <-> SDL surfaces
matthieu.villeneuve at free.fr
matthieu.villeneuve at free.fr
Mon Oct 18 10:50:00 UTC 2004
Hello,
Selon Vladimir Sedach <sedachv at cpsc.ucalgary.ca>:
> I've written a bit of code to shuffle between IMAGO images and SDL
> surfaces. It should be fast enough to do manipulations on small
> sprites in real-time on a reasonably fast machine.
Nice!
> (defun convert-to-image (surface)
> "Given a 24 or 32-bit depth SDL surface, returns an IMAGO RGB image
> of the same width and height and RGB pixel contents."
> (assert (or (= 24 (sdl:pixel-format-bits-per-pixel
> (sdl:surface-format surface)))
> (= 32 (sdl:pixel-format-bits-per-pixel
> (sdl:surface-format surface)))))
> (let* ((width (sdl:surface-w surface)) (height (sdl:surface-h surface))
> (image (make-instance 'imago:rgb-image :width width :height height))
> (image-array (imago:image-pixels image)))
> ;; Note that on 32 bit machines, width and height are 32 bit ints
> (declare (type fixnum width height)
> (type (simple-array (unsigned-byte 32) (* *)) image-array))
> (with-surface-lock surface
> (dotimes (y height)
> (declare (type fixnum y))
> (dotimes (x width)
> (declare (type fixnum x))
> (setf (aref image-array y x) (sdl:get-pixel surface x y)))))
> image))
A little note: using the IMAGO:DO-IMAGE-PIXELS macro could make the
code a little bit more abstract as well as more efficient. Here is
what the body of that function would look like:
(defun convert-to-image (surface)
(let ((image (make-instance 'imago:rgb-image
:width (sdl:surface-w surface)
:height (sdl:surface-h surface))))
(with-surface-lock surface
(imago:do-image-pixels (image pixel x y)
(setf pixel (sdl:get-pixel surface x y)))))
image))
--
Matthieu Villeneuve
More information about the Imago-devel
mailing list