[mcclim-devel] Image-reading in McCLIM
Troels Henriksen
athas at sigkill.dk
Sat Jan 5 21:32:13 UTC 2008
Currently, there is no obvious way to read images from a file and
display them on a pane in McCLIM. If you know the secret rites, you
can use CLIM-INTERNALS::XPM-PARSE-FILE, but:
1) It is limited to XPM files.
2) It is internal and looks scary.
To rectify this, I think we should bundle some simple library with
McCLIM for converting image files to CLIM patterns, just like
CLIM-INTERNALS::XPM-PARSE-FILE does. (I see something called
rgb-image.lisp in mcclim/Extensions, what is it used for?) It would
not be loaded by default, but applications could depend on a
MCCLIM-IMAGES ASDF system that would define a package, load some
simple scaffolding code and export a symbol, LOAD-IMAGE, from its
package. The MCCLIM-IMAGES system would not actually support any image
formats, and thus not have any dependencies, and applications with
specific needs could thus depend on systems like MCCLIM-IMAGES-XPM,
MCCLIM-IMAGES-GIF, etc., all of which depend on MCCLIM-IMAGES and
whatever libraries necessary to read the specific image file
format. These format-support-systems would define a method on
LOAD-IMAGE for the specific image format(s) handled by them. This way,
an application that needs to read JPEG files would not have to drag in
a library for reading, say, GIF files, and at the same time, the same
well-defined function interface would be used for all image reading.
Since image formats are different, and may have unique options for
controlling exactly how they are loaded, the LOAD-IMAGE function would
probably take an unspecified set of keywords, permitting each image
format to define their own keywords semantics.
Writing such a library would probably be extremely simple, if we are
willing to use external libraries for most of the actual image
reading. For example, here is how to turn the first image of a GIF
file into a CLIM pattern using the Skippy library:
(defun gif-to-pattern (pathname)
(let* ((data-stream (skippy:load-data-stream pathname))
(first-image (aref (skippy:images data-stream) 0))
(pattern-array (make-array (list (skippy:height first-image)
(skippy:width first-image))))
(designs (coerce (loop with color-table = (skippy:color-table data-stream)
for i below 255
collecting (multiple-value-bind (r g b)
(skippy:color-rgb (skippy:color-table-entry color-table i))
(make-rgb-color (/ r 255) (/ g 255) (/ b 255))))
'vector)))
(dotimes (y (skippy:height first-image))
(dotimes (x (skippy:width first-image))
(setf (aref pattern-array y x) (skippy:pixel-ref first-image x y))))
(make-pattern pattern-array designs)))
--
\ Troels
/\ Henriksen
More information about the mcclim-devel
mailing list