From 56de18783a48ebb4ab2b9d8c346751256a10b12b Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Wed, 6 Jul 2022 23:59:25 +0200 Subject: Make `get-pixels` fast: Using bytevectors inside makes the process way faster and now can be safely used in the loop, not only for debugging purposes --- bytepusher.scm | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/bytepusher.scm b/bytepusher.scm index d72aaf4..2a3eb67 100644 --- a/bytepusher.scm +++ b/bytepusher.scm @@ -89,15 +89,6 @@ ;; debug ---- -(define (get-pixels) - (let* ((initial (get-initial-pixel)) - (len (* width height)) - (base (make-bytevector len))) - (bytevector-copy! memory initial base 0 len) - (uint-list->bytevector - (map pixel->color-fast (bytevector->u8-list base)) - (endianness big) - 4))) (define (peek-memory start end) (for-each (lambda (i) (display "0x") @@ -126,6 +117,20 @@ ;; rendering ---- +(define (get-pixels) + (let* ((initial (get-initial-pixel)) + (len (* width height)) + (base (make-bytevector len)) + (final (make-bytevector (* 4 len)))) + (bytevector-copy! memory initial base 0 len) + (let loop ((i 0)) + (bytevector-u32-set! final + (* 4 i) + (pixel->color-fast (bytevector-u8-ref base i)) + (endianness big)) + (unless (= i (- len 1)) (loop (+ 1 i)))) + final)) + (define (make-display-texture renderer) (make-texture renderer 'argb8888 'streaming width height)) -- cgit v1.2.3