diff options
-rw-r--r-- | chickadee/graphics/path.scm | 23 |
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)) |