NET.HEXAPODIA.IMAGE - a cool library


 

Abstract

Image is an image-drawing with a few drawing primitives (circles, ellipses, lines, rectangles, text). It currently has code or "dumping" an image to either X11 drawables or GIF files (via Skippy). It currently only has a single font available for drawing text, but it should be possible to extend the font handling to load fonts from other formats. under MIT License, so you can basically do with it whatever you want.

Download shortcut: http://src.hexapodia.net/image.tar.gz.


 

Contents

  1. Download
  2. Examples
  3. The NET.HEXAPODIA.IMAGE dictionary
    1. circle
    2. circle-fill
    3. cut-image
    4. ellipsis
    5. export-to-gif
    6. get-pixel
    7. height
    8. import-image
    9. line
    10. make-image
    11. plot
    12. poly-line
    13. put-image
    14. rect
    15. text
    16. width
  4. Acknowledgements

 

Download

IMAGE can be downloaded from http://src.hexapodia.net/image.tar.gz. The current version is 0.10.
 

Example

(in-package :image)
(defparameter *height* 200)
(defparameter *width* 300)

(defmacro with-image ((var width height) &body body)
  `(let ((,var (make-image ,width ,height)))
     ,@body))

(defun draw-border (img &optional (thickness 5) (r 0) (g 0) (b 0))
  (let ((width (width img))
	(height (height img)))
    (rect img 0 0 width thickness t r g b)
    (rect img 0 0 thickness height t r g b)
    (rect img 0 (- height thickness) width height t r g b)
    (rect img (- width thickness) height width 0 t r g b)))
Then
  
(defun draw-japanese-flag (file-name)
  (with-image (img *width* *height*)
    (rect img 0 0 *width* *height* t #xff #xff #xff)
    (circle-fill img (/ *width* 2) (/ *height* 2) (/ (max *width* *height*) 6) #xff #x00 #x00)
    (text img "Japan" (/ *width* 4) (- *height* 40) 0 0 #xff)
    (draw-border img 10)
    (export-to-gif img file-name))))

(defun draw-french-flag (file-name)
  (let ((width/3 (/ *width* 3)))
    (with-image (img *width* *height*)
      (rect img 0 0 *width* *height* t #xff #xff #xff)
      (rect img 0 0 width/3 *height* t #xff 0 0)
      (rect img (- *width* width/3) 0 *width* *height* t 0 0 #xff)
      (text img "San France CISCO" (/ *width* 4) (- *height* 40) 0 0 #xff)
      (export-to-gif img file-name))))

Drawing the flag of Wales using only the IMAGE primitives is left as an exercise to the reader.


 

The IMAGE dictionary


[Function]
circle image x-centre y-centre radius r g b &optional alpha => result


Draw a circle in IMAGE, centred on <X-CENTER Y-CENTRE>, with the specified RADIUS. Use the R, G and B values provided and use ALPHA as the alpha-blend parameter (defaults to 1.0). Does not have a useful return value.


[Function]
circle-fill image x-centre y-centre radius r g b &optional alpha => result


Draw a filled circle in IMAGE centred on <X-CENTER Y-CENTRE>, with the specified DIAMETER. Use the R, G and B values provided and use ALPHA as the alpha-blend parameter (defaults to 1.0). Fill the circle.


[Function]
cut-image image x0 y0 x1 y1 &optional alpha => result


Create a copy of the area of IMAGE that extends from <X0,Y0> to <X1,Y1>, also create an alpha map that is initialised to the value given to ALPHA (default is 1.0). Note that this alpha-map is *not* automatically referenced!


[Function]
ellipsis image x0 y0 x1 y1 long-axis r g b &optional alpha => result


Draw an ellipsis in IMAGE. The two foci are <X0 Y0> and <X1 Y1>. The long axis is LONG-AXIS long and the colour of the ellipsis is the specified R, G and B values. Use ALPHA as the alpha-blend value (defaults to 1.0).


[Function]
export-to-gif image file-name &optional comment => result



[Function]
get-pixel image x y &optional type => result


Retrieve the R G B values of the <X,Y> pixel in IMAGE. Return the triplet as TYPE (defaults to list).


[Generic function]
height object => result



[Method]
height (object sub-image) => result


Gets the height of image in pixels


[Method]
height (object image) => result


Gets the height of image in pixels


[Generic function]
import-image source &key format &allow-other-keys => result



[Method]
import-image (source string) &key format &allow-other-keys => result



[Method]
import-image (source stream) &key format &allow-other-keys => result



[Function]
line image x0 y0 x1 y1 r g b &optional alpha => result


Draw a line in IMAGE from <X0 Y0> to <X1 Y1>, using R, G and B as colour. Use ALPHA as alpha-blend value (defaults to 1.0).


[Function]
make-image width height => result


Create an IMAGE object, with specified width and height


[Function]
plot image x y r g b &optional alpha => result


Draw a pixel in IMAGE, ar position <X Y>, with the specified R, G and B values. Use ALPHA as alpha-blend value (defaults to 1.0).


[Function]
poly-line image xy-pairs r g b &optional alpha => result


Draw a poly-line in IMAGE (all corners are specified in XY-PAIRS as elements in a flat list, as (X0 Y0 X1 Y1 X2 Y2 ...). Use R, G and B as colour and ALPHA as alpha-blend (defaults to 1.0).


[Function]
put-image source target x-offset y-offset &key alpha alpha-map source-x source-y source-width source-height => result


Copy a rectangle from SOURCE to TARGET, placing the result wit the upper left corner at <X-OFFSET, Y-OFFSET> in the target. Optionally, specily the ALPHA blend parameter to use (defaults to 1.0), an ALPHA-MAP, an array of wXh for the source image, having one alpha-blend per pixel stored in it. It's also possible to specify a sub-rectangle within the source image, with the upper left corner at <SOURCE-X, SOURCE-Y>, having SOURCE-WIDth and SOURCE-HEIGHT.


[Function]
rect image x0 y0 x1 y1 fill r g b &optional alpha => result


Draw a rectangle in IMAGE, with one corner at <X0 Y0> and the diagonally opposite at <X1 Y1>. Use R, G and B for colour and use ALPHA as alpha-blend (defaults to 1.0).


[Function]
text image text x y r g b &optional alpha => result


Draw the string TEXT in IMAGE, with upper left corner at <X Y>, using the specified R, G and B values. Use ALPHA as alpha-blend value. Returns (VALUE <max-x> <max-y>), to get exact bounding rectangle, plot at <0 0>, with an ALPHA of 0.0 and you will have (VALUES <width> <height>) as return value.


[Generic function]
width object => result



[Method]
width (object sub-image) => result


Gets the height of image in pixels


[Method]
width (object image) => result


Gets the width of image in pixels

 

Acknowledgements

This documentation was prepared with DOCUMENTATION-TEMPLATE.

$Header: /usr/local/cvsrep/documentation-template/output.lisp,v 1.17 2010/08/05 19:24:27 edi Exp $

BACK TO MY HOMEPAGE