fix `draw-bitmap-section-smooth' method of bitmap-dc<%>

This commit is contained in:
Matthew Flatt 2010-11-25 10:52:15 -07:00
parent e9562a8ddc
commit 8e8844641c
4 changed files with 44 additions and 9 deletions

View File

@ -82,7 +82,10 @@
(inherit draw-bitmap-section
internal-set-bitmap
internal-get-bitmap
get-size)
get-size
get-transformation
set-transformation
scale)
(super-new)
@ -131,13 +134,20 @@
(def/public (draw-bitmap-section-smooth [bitmap% src]
[real? dest-x]
[real? dest-y]
[nonnegative-real? dest-w]
[nonnegative-real? dest-h]
[real? src-x]
[real? src-y]
[real? src-w]
[real? src-h]
[nonnegative-real? src-w]
[nonnegative-real? src-h]
[(symbol-in solid opaque xor) [style 'solid]]
[(make-or-false color%) [color black]]
[(make-or-false bitmap%) [mask #f]])
(draw-bitmap-section src dest-x dest-y src-x src-y src-w src-h style color mask))))
(let ([sx (if (zero? src-w) 1.0 (/ dest-w src-w))]
[sy (if (zero? src-h) 1.0 (/ dest-h src-h))])
(let ([t (get-transformation)])
(scale sx sy)
(draw-bitmap-section src (/ dest-x sx) (/ dest-y sy) src-x src-y src-w src-h style color mask)
(set-transformation t))))))
(install-bitmap-dc-class! bitmap-dc%)

View File

@ -1450,8 +1450,8 @@
[real? dest-y]
[real? src-x]
[real? src-y]
[real? src-w]
[real? src-h]
[nonnegative-real? src-w]
[nonnegative-real? src-h]
[(symbol-in solid opaque xor) [style 'solid]]
[(make-or-false color%) [color black]]
[(make-or-false bitmap%) [mask #f]])

View File

@ -39,10 +39,14 @@ Creates a new memory DC. If @scheme[bitmap] is not @scheme[#f], it is
[mask (or/c (is-a?/c bitmap%) false/c)])
boolean?]{
The same as @method[dc<%> draw-bitmap-section]. In older version, this
method smoothed drawing more than @method[dc<%> draw-bitmap-section], but
smoothing is now provided by @method[dc<%> draw-bitmap-section].
The same as @method[dc<%> draw-bitmap-section], except that
@racket[dest-width] and @racket[dest-height] cause the DC's
transformation to be adjusted while drawing the bitmap so
that the bitmap is scaled.
In older versions, this method smoothed drawing more than
@method[dc<%> draw-bitmap-section], but smoothing is now provided by
@method[dc<%> draw-bitmap-section].
}
@defmethod[(get-argb-pixels [x real?]

View File

@ -194,6 +194,27 @@
#"\377\377\377\377\377\377\377\377\377\0\0\0\377\0\0\0\377\0\0\0")))
(test #t 'same-bits (equal? bs bs2)))
;; ----------------------------------------
;; Test draw-bitmap-section-smooth
(let* ([bm (make-bitmap 100 100)]
[dc (make-object bitmap-dc% bm)]
[bm2 (make-bitmap 70 70)]
[dc2 (make-object bitmap-dc% bm2)]
[bm3 (make-bitmap 70 70)]
[dc3 (make-object bitmap-dc% bm3)])
(send dc draw-ellipse 0 0 100 100)
(send dc2 draw-bitmap-section-smooth bm
10 10 50 50
0 0 100 100)
(send dc3 scale 0.5 0.5)
(send dc3 draw-bitmap bm 20 20)
(let ([s2 (make-bytes (* 4 70 70))]
[s3 (make-bytes (* 4 70 70))])
(send bm2 get-argb-pixels 0 0 70 70 s2)
(send bm3 get-argb-pixels 0 0 70 70 s3)
(test #t 'same-scaled (equal? s2 s3))))
;; ----------------------------------------
(report-errs)