[racket-dev] bitmap-dc% ignores alpha on set-pixel

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat May 11 11:27:53 EDT 2013

The change looks ok to me.

At Fri, 10 May 2013 19:23:35 -0600, Jay McCarthy wrote:
> No matter what the input color's alpha is, set-pixel uses 100%
> opacity. Similarly, get-pixel ignores the alpha in the image.
> 
> I think we should change this with the patch below, but I wonder if
> there is some deeper reason it works this way and it shouldn't change.
> Matthew?
> 
> Jay
> 
> diff --git a/collects/racket/draw/private/bitmap-dc.rkt
> b/collects/racket/draw/private/bitmap-dc.rkt
> index 08bb51c..5d9e241 100644
> --- a/collects/racket/draw/private/bitmap-dc.rkt
> +++ b/collects/racket/draw/private/bitmap-dc.rkt
> @@ -119,14 +119,18 @@
>        (internal-get-bitmap))
> 
>      (define/public (set-pixel x y c)
> -      (let ([s (bytes 255 (color-red c) (color-green c) (color-blue c))])
> +      (let ([s (bytes (inexact->exact (round (* 255 (color-alpha c))))
> +                      (color-red c)
> +                      (color-green c)
> +                      (color-blue c))])
>          (set-argb-pixels x y 1 1 s)))
> 
>      (define/public (get-pixel x y c)
>        (let-values ([(w h) (get-size)])
>          (let ([b (make-bytes 4)])
>            (get-argb-pixels x y 1 1 b)
> -          (send c set (bytes-ref b 1) (bytes-ref b 2) (bytes-ref b 3))
> +          (send c set (bytes-ref b 1) (bytes-ref b 2) (bytes-ref b 3)
> +                (/ (bytes-ref b 0) 255))
>            (and (<= 0 x w) (<= 0 y h)))))
> 
>      (define/public (set-argb-pixels x y w h bstr
> 
> 
> --
> Jay McCarthy <jay at cs.byu.edu>
> Assistant Professor / Brigham Young University
> http://faculty.cs.byu.edu/~jay
> 
> "The glory of God is Intelligence" - D&C 93
> _________________________
>   Racket Developers list:
>   http://lists.racket-lang.org/dev

Posted on the dev mailing list.