From ce655168b7e5989b09ed1f1c4ca313636db0b871 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 25 Mar 2023 11:08:25 -0400 Subject: graphics: path: Add canvas->pixbuf and write-canvas procedures. --- chickadee/graphics/path.scm | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) 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)) -- cgit v1.2.3