[closure-devel] PATCH: load GIF files without an external application

Eric Marsden eric.marsden at free.fr
Thu Dec 28 17:21:37 EST 2006


Hi,

Closure currently loads GIF files by saving the contents to a
temporary file, running gif2png on the file, then slurping in that
file. The attached patch (well, it isn't packaged as a proper patch)
allows Closure to load GIF files directly, thanks to Zach Beane's
Skippy library.

  http://www.xach.com/lisp/skippy/

Interlaced GIF files are not currently supported by Skippy (but this
should change shortly). Only the last frame of animated GIFs will be
displayed (yes, this is a feature). 
  
-------------- next part --------------
;;; gif-skippy.lisp
;;;
;;; Author: Eric Marsden <eric.marsden at free.fr>
;;; Time-stamp: <2006-12-28 emarsden>


(eval-when (:compile-toplevel :load-toplevel :execute)
  (asdf:oos 'asdf:load-op :skippy)
  (asdf:oos 'asdf:load-op :flexi-streams))


(in-package :renderer)

(defun gstream->flexi-stream (gstream)
  (let ((data (make-array 1024 :element-type '(unsigned-byte 8)
                          :fill-pointer 0
                          :adjustable t)))
    (loop :for b = (g/read-byte gstream nil nil)
          :while b
          :do (vector-push-extend b data))
    (g/close gstream)
    (flexi-streams:make-in-memory-input-stream data)))


(defun gif-stream->aimage (gstream)
  (let* ((data-stream (skippy::read-data-stream (gstream->flexi-stream gstream)))
         (image (skippy:last-image data-stream))
         (gif-color-table (skippy:color-table data-stream))
         (aimage (make-aimage (skippy:width image)
                              (skippy:height image) :alpha-p nil))
         (aimage-data (aimage-data aimage)))
    (dotimes (x (skippy:width image))
      (dotimes (y (skippy:height image))
        (multiple-value-bind (r g b)
            (skippy:color-rgb
             (skippy:color-table-entry gif-color-table (skippy:pixel-ref image x y)))
          (setf (aref aimage-data y x)
                (dpb r (byte 8 0)
                     (dpb g (byte 8 8)
                          (dpb b (byte 8 16)
                               (dpb (- 255 0) (byte 8 24) 0))))))))
    aimage))


;; EOF
-------------- next part --------------
-- 
Eric Marsden


More information about the closure-devel mailing list