Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save LeifAndersen/8a4b9e5b80e3de35c4f8c289a2dd46c9 to your computer and use it in GitHub Desktop.

Select an option

Save LeifAndersen/8a4b9e5b80e3de35c4f8c289a2dd46c9 to your computer and use it in GitHub Desktop.
(define (grayscale-pict s)
(define buf (pict->argb-pixels s))
(define gray-buf
(apply bytes
(append*
(for/list ([i (in-range 0 (bytes-length buf) 4)])
(define a (bytes-ref buf i))
(define r (bytes-ref buf (+ i 1)))
(define g (bytes-ref buf (+ i 2)))
(define b (bytes-ref buf (+ i 3)))
(define av (exact-floor (/ (+ r g b) 3)))
(list a av av av)))))
(argb-pixels->pict gray-buf (pict-width s)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment