the struggle

main
Matthew Butterick 8 years ago
parent 1cbfb6d591
commit 0e9de4a198

@ -87,11 +87,11 @@ Grab key chunks from PNG. Doesn't require heavy lifting from libpng.
(define pos 0)
(define c 0)
(report* width height)
#;(report* width height)
(parameterize ([current-input-port (open-input-bytes data)])
(for/fold ([_ #f]) ([row (in-naturals)]
#:break (eof-object? (peek-byte)))
(report row)
#;(report row)
(define b (read-byte))
(case b
[(0) ; none
@ -165,7 +165,7 @@ Grab key chunks from PNG. Doesn't require heavy lifting from libpng.
)]
[else (error 'invalid-filter-algorithm (format "~a" b))])))
(report (bytes-length pixels))
#;(report (bytes-length pixels))
(fn pixels))

@ -93,25 +93,28 @@
(define (pixel-proc pixels)
(define colorByteSize (* (· this image colors) (/ (· this image bits) 8)))
(define pixelCount (* (· this width) (· this height)))
(define imgData (make-bytes (* pixelCount colorByteSize)))
(define alphaChannel (make-bytes pixelCount))
#;(define imgData (make-bytes (* pixelCount colorByteSize)))
#;(define alphaChannel (make-bytes pixelCount))
(define i 0)
(define p 0)
(define a 0)
(define len (bytes-length pixels))
(for ([idx (in-naturals)]
#:when (< i len))
(bytes-set! imgData p (bytes-ref pixels i))
(increment! p) (increment! i)
(bytes-set! imgData p (bytes-ref pixels i))
(increment! p) (increment! i)
(bytes-set! imgData p (bytes-ref pixels i))
(increment! p) (increment! i)
(bytes-set! alphaChannel a (bytes-ref pixels i))
(increment! a) (increment! i))
#;(report* len (* pixelCount colorByteSize) pixelCount)
(define-values (imgBytes alphaBytes)
(for/fold ([img-bytes empty]
[alpha-bytes empty])
([b (in-bytes pixels)]
[i (in-naturals)])
(if (= (modulo i 4) 3)
(values img-bytes (cons b alpha-bytes))
(values (cons b img-bytes) alpha-bytes))))
(define imgData (apply bytes (reverse imgBytes)))
(define alphaChannel (apply bytes (reverse alphaBytes)))
#;(report* (bytes-length imgData) (bytes-length alphaChannel))
#;(error 'in-pixel-proc)
(define done 0)
(set-field! imgData this (deflate imgData))
(increment! done)
@ -121,7 +124,8 @@
(increment! done)
(when (= done 2) (· this finalize))
(report* done)
(void)
)
(decodePixels (· this imgData) (· this pixelBitlength) (· this width) (· this height) pixel-proc))

Loading…
Cancel
Save