[racket] reading pixels from a file...
On 04/11/2012 02:49 PM, geb a wrote:
> Some students are trying to do a pixel by pixel operation on a 640x480
> size picture and my student's code is operating very slowly. I've heard
> that Racket can process images quickly but apparently we are doing
> something very wrong. There are a few parts to this problem. This is the
> first one: Reading the image into a representation. I'm not sure how to
> make this more efficient. Is there something I'm missing?
>
> We have very new computers running the latest stable version of Racket.
> Operating system is Fedora Core 14 (64 bit version).
>
>
> #lang racket
> (require mred)
> (define bmdc (make-object bitmap% "apple.jpg"))
> (define-struct rect (x y w h))
>
>
>
> (define pw (send bmdc get-width))
> (define ph (send bmdc get-height))
>
> ;get-my-colors: num num num num -> byte-string
> (define (get-mycolors x y w h)
> (let* (
> (pixels (make-bytes (* w h 4) 0))
> (myrectangle (send bmdc get-argb-pixels x y w h pixels false)))
> pixels))
> (get-mycolors 0 0 pw ph)
I just tried this in DrRacket. Getting the pixels is very fast; printing
the huge bytevector in the interactions window is very slow.
That might be the problem.
Try changing the last line to either
(define pixels (get-mycolors 0 0 pw ph))
or, to also see how long it takes,
(define pixels (time (get-mycolors 0 0 pw ph)))
Ryan