[racket-dev] [plt] Push #28009: master branch updated

From: Neil Toronto (neil.toronto at gmail.com)
Date: Fri Jan 3 21:33:22 EST 2014

On 01/03/2014 06:12 PM, mflatt at racket-lang.org wrote:
> bd4d0b7 Matthew Flatt <mflatt at racket-lang.org> 2014-01-03 17:57
> :
> | if a bitmap has a non-1 backing scale, always draw smoothly to other contexts
> :
>    M pkgs/draw-pkgs/draw-lib/racket/draw/private/dc.rkt | 11 ++++++-----

Cool. It looks like this solved another issue as well: drawing 2x 
bitmaps in the REPL would smooth only intermittently.

There appears to be a problem with drawing in 'unsmoothed mode onto a 
bitmap with a backing scale. I've attached a program that demonstrates 
using a single polygon and with plots.

In the single polygon test, the triangle drawn onto the 2x bitmap is 
shifted down and to the right one pixel.

The code that draws a plot onto a 2x bitmap simulates the change I would 
make to Plot to take advantage of the new backing scale feature. The 
edge of the sphere looks lumpy, probably because polygons are drawn 
unsmoothed and their vertices are being snapped to the wrong places. The 
second plot shows how it's supposed to look.

The last two plots show how each looks before being scaled down. The 
lumpiness around the edge is probably easier to see this way.

Neil ⊥

-------------- next part --------------
#lang racket

(require plot

(define (get-backing-bitmap bm)
  (define s (send bm get-backing-scale))
  (define bm2 (make-bitmap (exact-ceiling (* s (send bm get-width)))
                           (exact-ceiling (* s (send bm get-height)))))
  (define dc (make-object bitmap-dc% bm2))
  (send dc set-scale s s)
  (send dc set-smoothing 'unsmoothed)
  (send dc draw-bitmap bm 0 0)

(define (draw-unsmoothed-triangle dc)
  (send dc set-smoothing 'unsmoothed)
  (send dc set-background "orange")
  (send dc clear)
  (send dc set-pen (make-object pen% "black" 1 'transparent))
  (send dc set-brush (make-object brush% "black"))
  (send dc draw-polygon '((0 . 0) (9 . 3) (4 . 6))))

(define bm1 (make-bitmap 10 10 #:backing-scale 2))
(define dc1 (make-object bitmap-dc% bm1))
(draw-unsmoothed-triangle dc1)

(define bm2 (make-bitmap 20 20))
(define dc2 (make-object bitmap-dc% bm2))
(send dc2 set-scale 2 2)
(draw-unsmoothed-triangle dc2)

(printf "Triangles drawn in unsmoothed mode (top uses backing scale):~n")
(values (get-backing-bitmap bm1) bm2)

(printf "Plot rendered to bitmap with backing scale:~n")
(define bm3 (make-bitmap 400 400 #:backing-scale 2))
(define dc3 (make-object bitmap-dc% bm3))
(plot3d/dc (polar3d (λ (θ ρ) 1) #:color 2 #:line-style 'transparent)
           dc3 0 0 400 400
           #:altitude 25)

(printf "Plot rendered 2x and downscaled:~n")
(plot3d-bitmap (polar3d (λ (θ ρ) 1) #:color 2 #:line-style 'transparent)
               #:altitude 25)

(printf "Actual 2x bitmap:~n")
(get-backing-bitmap bm3)

(printf "Plot rendered 2x:~n")
(define bm4 (make-bitmap 800 800))
(define dc4 (make-object bitmap-dc% bm4))
(plot3d/dc (polar3d (λ (θ ρ) 1) #:color 2 #:line-style 'transparent)
           dc4 0 0 800 800
           #:altitude 25)

Posted on the dev mailing list.