applied Ian's patch to the bitmap rotation code
svn: r17513 original commit: b5e54fe2eb642c41bf70ceeaabe37eb34d84ac2a
This commit is contained in:
parent
f4c8b595d4
commit
2c7ebeae74
|
@ -90,9 +90,6 @@ has been moved out).
|
||||||
(define (image-normalized? p) (send p get-normalized?))
|
(define (image-normalized? p) (send p get-normalized?))
|
||||||
(define (set-image-shape! p s) (send p set-shape s))
|
(define (set-image-shape! p s) (send p set-shape s))
|
||||||
(define (set-image-normalized?! p n?) (send p set-normalized? n?))
|
(define (set-image-normalized?! p n?) (send p set-normalized? n?))
|
||||||
(define (image-right image) (bb-right (image-bb image)))
|
|
||||||
(define (image-bottom image) (bb-bottom (image-bb image)))
|
|
||||||
(define (image-baseline image) (bb-baseline (image-bb image)))
|
|
||||||
(define (image? p)
|
(define (image? p)
|
||||||
(or (is-a? p image%)
|
(or (is-a? p image%)
|
||||||
(is-a? p image-snip%)
|
(is-a? p image-snip%)
|
||||||
|
@ -242,11 +239,10 @@ has been moved out).
|
||||||
(init-field shape bb normalized?)
|
(init-field shape bb normalized?)
|
||||||
(define/public (equal-to? that eq-recur)
|
(define/public (equal-to? that eq-recur)
|
||||||
(or (eq? this that)
|
(or (eq? this that)
|
||||||
(and (eq-recur bb (send that get-bb))
|
(and (is-a? that image%)
|
||||||
(let* ([w (ceiling (max (inexact->exact (bb-right bb))
|
(same-bb? bb (send that get-bb))
|
||||||
(inexact->exact (bb-right (send that get-bb)))))]
|
(let* ([w (round (inexact->exact (bb-right bb)))]
|
||||||
[h (ceiling (max (inexact->exact (bb-bottom bb))
|
[h (round (inexact->exact (bb-bottom bb)))]
|
||||||
(inexact->exact (bb-bottom (send that get-bb)))))]
|
|
||||||
[bm1 (make-object bitmap% w h)]
|
[bm1 (make-object bitmap% w h)]
|
||||||
[bm2 (make-object bitmap% w h)]
|
[bm2 (make-object bitmap% w h)]
|
||||||
[bytes1 (make-bytes (* w h 4) 0)]
|
[bytes1 (make-bytes (* w h 4) 0)]
|
||||||
|
@ -341,6 +337,10 @@ has been moved out).
|
||||||
(inherit set-snipclass)
|
(inherit set-snipclass)
|
||||||
(set-snipclass snip-class)))
|
(set-snipclass snip-class)))
|
||||||
|
|
||||||
|
(define (same-bb? bb1 bb2)
|
||||||
|
(and (= (round (bb-right bb1)) (round (bb-right bb2)))
|
||||||
|
(= (round (bb-bottom bb1)) (round (bb-bottom bb2)))
|
||||||
|
(= (round (bb-baseline bb1)) (round (bb-baseline bb2)))))
|
||||||
(define scheme/base:read read)
|
(define scheme/base:read read)
|
||||||
|
|
||||||
(define image-snipclass%
|
(define image-snipclass%
|
||||||
|
@ -808,9 +808,6 @@ the mask bitmap and the original bitmap are all together in a single bytes!
|
||||||
ellipse-rotated-size
|
ellipse-rotated-size
|
||||||
|
|
||||||
image?
|
image?
|
||||||
image-right
|
|
||||||
image-bottom
|
|
||||||
image-baseline
|
|
||||||
|
|
||||||
text->font
|
text->font
|
||||||
compare-all-rotations
|
compare-all-rotations
|
||||||
|
|
|
@ -97,7 +97,7 @@ instead of this scaling code, we use the dc<%>'s scaling code.
|
||||||
(values (build-bmbytes new-w
|
(values (build-bmbytes new-w
|
||||||
new-h
|
new-h
|
||||||
(λ (x y)
|
(λ (x y)
|
||||||
(let* {[pre-image (* (make-rectangular (+ west x) (- nrth y))
|
(let* {[pre-image (* (make-rectangular (+ west x 1/2) (- nrth y 1/2))
|
||||||
theta-unrotation)]
|
theta-unrotation)]
|
||||||
}
|
}
|
||||||
(interpolate bmbytes w h
|
(interpolate bmbytes w h
|
||||||
|
@ -105,6 +105,16 @@ instead of this scaling code, we use the dc<%>'s scaling code.
|
||||||
(- (imag-part pre-image))))))
|
(- (imag-part pre-image))))))
|
||||||
new-w
|
new-w
|
||||||
new-h)))
|
new-h)))
|
||||||
|
;; Why the offsets of 1/2 in `rotate-bytes` and `interpolate`?
|
||||||
|
;; We consider a pixel's RGB as a point-sample taken from the 'true' image,
|
||||||
|
;; where the RGB is the sample at the *center* of the square covered by the pixel.
|
||||||
|
;; (When we assume the sample had been from the NW corner instead of the center,
|
||||||
|
;; we got weird artifacts upon rotation:
|
||||||
|
;; Consider a 1x1 bitmap rotated by 90 degrees.
|
||||||
|
;; The NW corner of our new value would be derived from the *NE* corner of
|
||||||
|
;; the original bitmap, which is a full pixel-width away from the original sample.
|
||||||
|
;; So a 1x1 bitmap being rotated would counterintuitively give a different bitmap.)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; interpolate: bytes natnum natum real real -> bytes
|
; interpolate: bytes natnum natum real real -> bytes
|
||||||
|
@ -114,10 +124,10 @@ instead of this scaling code, we use the dc<%>'s scaling code.
|
||||||
; where x,y are *real-valued* coordinates in [0,w), [0,h).
|
; where x,y are *real-valued* coordinates in [0,w), [0,h).
|
||||||
;
|
;
|
||||||
(define (interpolate bmbytes w h x y)
|
(define (interpolate bmbytes w h x y)
|
||||||
(let* {[x0 (floor/e x)]
|
(let* {[x0 (floor/e (- x 1/2))]
|
||||||
[y0 (floor/e y)]
|
[y0 (floor/e (- y 1/2))]
|
||||||
[dx (- x x0)]
|
[dx (- (- x 1/2) x0)]
|
||||||
[dy (- y y0)]
|
[dy (- (- y 1/2) y0)]
|
||||||
[1-dx (- 1 dx)]
|
[1-dx (- 1 dx)]
|
||||||
[1-dy (- 1 dy)]
|
[1-dy (- 1 dy)]
|
||||||
[nw (bmbytes-ref/safe bmbytes w h x0 y0 )]
|
[nw (bmbytes-ref/safe bmbytes w h x0 y0 )]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user