summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2023-03-25 11:08:25 -0400
committerDavid Thompson <dthompson2@worcester.edu>2023-03-25 11:10:00 -0400
commitce655168b7e5989b09ed1f1c4ca313636db0b871 (patch)
treeadcd2f3ebbe83c1650300ab0d397896f6107c117
parent0986daec0526c041446d3e35c9151277bc969d67 (diff)
graphics: path: Add canvas->pixbuf and write-canvas procedures.
-rw-r--r--chickadee/graphics/path.scm23
1 files changed, 22 insertions, 1 deletions
diff --git a/chickadee/graphics/path.scm b/chickadee/graphics/path.scm
index b14936f..7e2d351 100644
--- a/chickadee/graphics/path.scm
+++ b/chickadee/graphics/path.scm
@@ -28,11 +28,14 @@
#:use-module (chickadee graphics buffer)
#:use-module (chickadee graphics color)
#:use-module (chickadee graphics engine)
+ #:use-module (chickadee graphics framebuffer)
#:use-module (chickadee graphics gl)
#:use-module (chickadee graphics multisample)
#:use-module (chickadee graphics polygon)
#:use-module (chickadee graphics shader)
#:use-module (chickadee graphics stencil)
+ #:use-module (chickadee graphics texture)
+ #:use-module (chickadee image)
#:use-module (chickadee math)
#:use-module (chickadee math bezier)
#:use-module (chickadee math matrix)
@@ -98,7 +101,9 @@
set-canvas-painter!
set-canvas-matrix!
draw-canvas*
- draw-canvas))
+ draw-canvas
+ canvas->pixbuf
+ write-canvas))
;;;
@@ -1634,3 +1639,19 @@
(define (draw-canvas canvas)
(draw-canvas* canvas %identity-matrix))
+
+(define (canvas->pixbuf canvas)
+ "Return a new pixbuf containing the rasterized CANVAS."
+ (let* ((bb (painter-bounding-box (canvas-painter canvas)))
+ (width (inexact->exact (ceiling (rect-width bb))))
+ (height (inexact->exact (ceiling (rect-height bb))))
+ (framebuffer (make-framebuffer width height)))
+ (with-framebuffer framebuffer
+ (draw-canvas* canvas (make-identity-matrix4)))
+ (texture->pixbuf (framebuffer-texture framebuffer))))
+
+(define* (write-canvas canvas
+ #:optional (file-name (temp-image-file-name 'png))
+ #:key (format 'png))
+ "Write CANVAS to FILE-NAME using FORMAT ('png' by default.)"
+ (write-image (canvas->pixbuf canvas) file-name #:format format))