Skip to content

Latest commit

 

History

History
1356 lines (864 loc) · 12 KB

displayref.md

File metadata and controls

1356 lines (864 loc) · 12 KB

LispBM Display Library

The display extensions contains a graphics library designed for platforms for with very limited memory resources. The drawing routines in the library operate on rectangular images (arrays) of pixels , called an image buffer.

The values stored in image buffers represents colors via an encoding determined by the image buffer pixel format. A pixel buffer has one of the following formats:

  • indexed2 : 2 colors (1 bit per pixel)
  • indexed4 : 4 colors (2 bits per pixel)
  • indexed16 : 16 colors (4 bits per pixel)
  • rgb332 : 8Bit color
  • rgb565 : 16bit color
  • rgb888 : 24bit color

Note that the RAM requirenment of a 100x100 image is;

  • at indexed2: 1250 Bytes
  • at indexed4: 2500 Bytes
  • at indexed16: 5000 Bytes
  • at rgb332: 10000 Bytes
  • at rgb565: 20000 Bytes
  • at rgb888; 30000 Bytes

So on an embedded platform you most likely not be able to be working with rgb565, rgb888 other than in very limited areas.

At the low-level end of things you will want to display graphics onto an display. The interface towards the low-level end needs to be implemented for the particular hardware platform and display. For examples of this see vesc_express. The LBM linux REPL has SDL and png backends for the display library.

the display library is specifically designed to allow for using many colors simultaneously on screen, without needing to use full screen high-color buffers. This is done by delaying the choice of collor mapping in the indexed2, indexed4 and indexed16 images until they are presented on screen.

images are rendered onto a display using the function disp-render. disp-render takes an image, a position (x,y) where to draw the image, and a colormapping that can be expressed as a list of colors. for example:

Example Image Result
(disp-render llama-bin 10 10 '(0x000000 0xFFFFFF))
t
(disp-render llama-bin 20 20 '(0x000000 0xFF0000))
t
(disp-render llama-bin 30 30 '(0x000000 0x00FF00))
t
(disp-render llama-bin 30 30 '(0x000000 0x0000FF))
t
(disp-clear)
t
Example Image Result
(disp-render img-100-100 0 0 '(0x000000 0xFFFFFF))
t
(disp-render img-100-100 0 100 '(0x000000 0xFF0000))
t
(disp-render img-100-100 100 0 '(0x000000 0x00FF00))
t
(disp-render img-100-100 100 100 '(0x000000 0x0000FF))
t
(disp-render img-100-100 200 0 '(0x000000 0x00FFFF))
t
(disp-render img-100-100 200 100 '(0x000000 0xFF00FF))
t

Reference

img-buffer

Allocate an image buffer from lbm memory or from a compactible region. The form of an img-buffer expression is (img-buffer opt-dm format width height).

Example Result
(define my-img (img-buffer 'indexed2 320 200))
[1 64 0 200 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Example Result
 (define my-dm (dm-create 10000))
 (define my-img (img-buffer my-dm 'indexed2 320 200))
[1 64 0 200 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

img-buffer?

Checks if the argument is likely to be an image buffer.

Example Result
(img-buffer? llama-bin)
t
(img-buffer? 'apa)
nil

img-blit

Example Image Result
(img-blit my-img llama-bin 10 10 -1)
t
(img-blit my-img llama-bin 10 10 -1 '(rotate 128 128 45))
t
(img-blit my-img llama-bin 10 10 -1 '(scale 0.500000f32))
t

img-arc

Example Image Result
(img-arc my-img 100 100 50 160 100 1)
t
(img-arc my-img 100 100 50 160 100 1 '(dotted 15 15))
t
(img-arc my-img 100 100 50 160 100 1 '(filled))
t
(img-arc my-img 100 100 50 160 100 1 '(thickness 10))
t
(img-arc my-img 100 100 50 160 100 1 '(rounded))
t
Example Image Result
(img-arc my-img 100 100 50 160 100 1 '(dotted 15 15) '(resolution 3))
t
(img-arc my-img 100 100 50 160 100 1 '(thickness 10) '(rounded))
t

img-circle

Example Image Result
(img-circle my-img 100 100 80 1)
t
(img-circle my-img 100 100 80 1 '(thickness 5))
t
(img-circle my-img 100 100 80 1 '(dotted 14 14))
t
(img-circle my-img 100 100 80 1 '(filled))
t
Example Image Result
(img-circle my-img 100 100 80 1 '(dotted 14 14) '(resolution 6))
t

img-circle-sector

Example Image Result
(img-circle-sector my-img 220 40 40 90 200 1)
t
(img-circle-sector my-img 220 40 40 90 200 1 '(thickness 3))
t

img-circle-segment

Example Image Result
(img-circle-segment my-img 100 100 80 0 100 1)
t
(img-circle-segment my-img 100 100 80 0 100 1 '(filled))
t

img-line

Example Image Result
(img-line my-img 0 0 320 200 1)
t
(img-line my-img 0 200 320 0 1 '(thickness 5))
t
(img-line my-img 0 0 320 200 1 '(dotted 4 20))
t

img-rectangle

Example Image Result
(img-rectangle my-img 10 10 120 180 1)
t
(img-rectangle my-img 10 10 120 180 1 '(filled))
t
(img-rectangle my-img 10 10 120 180 1 '(rounded 45))
t

img-setpix

Example Image Result
(img-setpix my-img 10 10 1)
t

img-text

Example Image Result
(img-text my-img 40 40 1 0 font "LispBM")
t
(img-text my-img 40 120 1 0 font "LispBM" 'up)
t
(img-text my-img 40 40 1 0 font "LispBM" 'down)
t

img-triangle

Example Image Result
(img-triangle my-img 30 60 160 120 10 180 1)
t
(img-triangle my-img 30 60 160 120 10 180 1 '(filled))
t
(img-triangle my-img 30 60 160 120 10 180 1 '(dotted 14 14))
t

Examples

Example: Sierpinsky triangle

Example Image Result
 (define w 320)
 (define h 200)
 (define corners (list (cons 10 (- h 10)) (cons (- w 10) (- h 10)) (cons (/ w 2) 10)))
 (define s-img (img-buffer 'indexed2 w h))
 (defun point (p) (img-setpix s-img (car p) (cdr p) 1))
 (defun mid-point (p1 p2) (progn (let ((x (/ (+ (car p1) (car p2)) 2))
      (y (/ (+ (cdr p1) (cdr p2)) 2)))
     (cons x y))))
 (defun sierp (n corners p) (if (= n 0) nil (let ((i (mod (rand) 3))
      (target (ix corners i))
      (mid (mid-point p target)))
     (progn (point mid)
            (sierp (- n 1) corners mid)))))
 (sierp 25000 corners (car corners))
 (disp-render s-img 0 0 '(0 16777215))
t

This document was generated by LispBM version 0.26.0