From 62f4b7e9d52402fb3d17392cf8847b94f9f0c88c Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Thu, 2 Sep 2010 10:59:38 -0500 Subject: [PATCH] fixed a performance bug (avoids computing the rotation of a bitmap when it isnt actually rotated...) original commit: 09bd56081b68ddbcbc46201af5ee2f4855e5d7a5 --- collects/mrlib/image-core.rkt | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/collects/mrlib/image-core.rkt b/collects/mrlib/image-core.rkt index 73392117..6259dace 100644 --- a/collects/mrlib/image-core.rkt +++ b/collects/mrlib/image-core.rkt @@ -829,18 +829,23 @@ the mask bitmap and the original bitmap are all together in a single bytes! (do-rotate bitmap flipped?)]))))) (define (do-rotate bitmap flip?) - (let ([θ (degrees->radians (bitmap-angle bitmap))]) - (let-values ([(bytes w h) (bitmap->bytes (bitmap-rendered-bitmap bitmap) - (bitmap-rendered-mask bitmap))]) - (let-values ([(rotated-bytes rotated-w rotated-h) - (rotate-bytes bytes w h θ)]) - (let* ([flipped-bytes (if flip? - (flip-bytes rotated-bytes rotated-w rotated-h) - rotated-bytes)] - [bm (bytes->bitmap flipped-bytes rotated-w rotated-h)] - [mask (send bm get-loaded-mask)]) - (set-bitmap-rendered-bitmap! bitmap bm) - (set-bitmap-rendered-mask! bitmap mask)))))) + (cond + [(zero? (bitmap-angle bitmap)) + ;; don't rotate anything in this case. + (void)] + [else + (let ([θ (degrees->radians (bitmap-angle bitmap))]) + (let-values ([(bytes w h) (bitmap->bytes (bitmap-rendered-bitmap bitmap) + (bitmap-rendered-mask bitmap))]) + (let-values ([(rotated-bytes rotated-w rotated-h) + (rotate-bytes bytes w h θ)]) + (let* ([flipped-bytes (if flip? + (flip-bytes rotated-bytes rotated-w rotated-h) + rotated-bytes)] + [bm (bytes->bitmap flipped-bytes rotated-w rotated-h)] + [mask (send bm get-loaded-mask)]) + (set-bitmap-rendered-bitmap! bitmap bm) + (set-bitmap-rendered-mask! bitmap mask)))))])) (define (do-scale bitmap) (let* ([bdc (make-object bitmap-dc%)]