Hello.

2008/7/19 Luke Crook <[EMAIL PROTECTED]>:
> On Fri, 18 Jul 2008 16:00:39 -0700, css <[EMAIL PROTECTED]> wrote:
>
>>
>> (defun load-image-from-byte-sequence (byteseq)
>>   (make-instance 'sdl:surface
>>                :surface
>>                (sdl-cffi::sdl-load-bmp-rw
>>                 (sdl-cffi::with-foreign-string (str byteseq)
>>                   (sdl-cffi::sdl-rw-from-mem str (length byteseq)))
>>                 1)))
>
> Try the following:
>
> (defun load-image-from-byte-sequence (array)
>   (cffi:with-foreign-object (mem-array :unsigned-char (length array))
>     (loop for i from 0 below (length array) do
>         (setf (cffi:mem-aref mem-array :unsigned-char i) (aref array i)))
>     (make-instance 'surface :surface (sdl-cffi::sdl-load-bmp-rw
> (sdl-cffi::sdl-rw-from-mem mem-array (length array)) 1))))
>
> - Luke

Thank you. It works. It may be a stupid question, but what is the main
difference between these both things? I mean they are both strings -
at least for C - a sequence of bytes. Just for my interest.

The following function also works for png-images (which I need) and
should work for the other stuff supported by lispbuilder-sdl-image,
too.

(defun load-image-from-byte-sequence (array)
  (cffi:with-foreign-object (mem-array :unsigned-char (length array))
    (loop for i from 0 below (length array) do
         (setf (cffi:mem-aref mem-array :unsigned-char i) (aref array i)))
    (make-instance 'sdl:surface
                   :surface
                   (sdl-image-cffi::img-load-rw
                    (sdl-cffi::sdl-rw-from-mem mem-array (length array)) nil))))

Under clisp, using a PNG-Image is much faster, I think the conversion
to this mem-array takes much time, if it is long (and the Bitmap is a
lot longer, than the PNG).

Is this function likely to work in newer versions of lispbuilder-sdl?
It is using lowlevel-stuff, but I think it would be a good Idea in
general to support RWOps in lispbuilder at a "higher" level, it can be
used for a lot of stuff, and makes it more "extensible".

 - Christoph
_______________________________________________
application-builder mailing list
[email protected]
http://www.lispniks.com/mailman/listinfo/application-builder

Reply via email to