summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2022-07-06 23:59:25 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2022-07-07 00:19:00 +0200
commit56de18783a48ebb4ab2b9d8c346751256a10b12b (patch)
treee4530315daf8a5b9b8d957f7c3c602c8a7818420
parent2393c1191cb4f1ed3b1a00a33a1b8db2b2366c6f (diff)
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
-rw-r--r--bytepusher.scm23
1 files 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))