Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameter plot-background-alpha has no effect (since 8.1) #96

Closed
bksaiki opened this issue Jun 3, 2021 · 3 comments
Closed

Parameter plot-background-alpha has no effect (since 8.1) #96

bksaiki opened this issue Jun 3, 2021 · 3 comments
Labels

Comments

@bksaiki
Copy link

bksaiki commented Jun 3, 2021

It seems that plot-background-alpha no longer works when generating png files with plot-file. This bug was introduced after Racket 8.0. Here's a quick example:

(require plot/no-gui)

(define out (open-output-file "img.png" #:exists 'replace))

(parameterize ([plot-width 800] [plot-height 300]
               [plot-background-alpha 0])
  (define xs (build-list 20 (λ _ (random))))
  (define ys (build-list 20 (λ _ (random))))
  (define pts (points (map vector xs ys)
                      #:color "black"))
  (plot-file (list pts) out 'png
             #:x-min 0 #:x-max 1
             #:y-min 0 #:y-max 1))

Please let me know if something has changed with this parameter.

@alex-hhh alex-hhh added the bug label Jun 3, 2021
@alex-hhh
Copy link
Sponsor Collaborator

alex-hhh commented Jun 3, 2021

Thanks for reporting this. This was likely introduced by the plot-metrics changes in #90. A call to (make-bitmap ...) was replaced with a call to (make-object bitmap% ...) but the two calls have different defaults for whether to create an alpha channel or not. The (make-object bitmap% ...) variant defaults to not having an alpha channel, introducing this bug.

The workaround for now is to create the bitmap separately and use plot/dc:

#lang racket
(require plot/no-gui racket/draw)

(define out (open-output-file "img.png" #:exists 'replace))
(define bm (make-bitmap 800 300))
(define dc (send bm make-dc))

(parameterize ([plot-width 800] [plot-height 300]
               [plot-background-alpha 0])
  (define xs (build-list 20 (λ _ (random))))
  (define ys (build-list 20 (λ _ (random))))
  (define pts (points (map vector xs ys)
                      #:color "black"))
  (plot/dc (list pts)
           dc 0 0 800 300
           #:x-min 0 #:x-max 1
           #:y-min 0 #:y-max 1))

(send bm save-file out 'png)

The fix is to specify that an alpha channel needs to be created in these places:

(make-object (plot-metrics-mixin bitmap%) (λ () pm) width height))

(make-object (plot-metrics-mixin (class bitmap% (super-new))) (λ () pm) width height))

@bksaiki
Copy link
Author

bksaiki commented Jun 4, 2021

Thanks @alex-hhh. I'll use the workaround until a fix gets merged.

alex-hhh added a commit to alex-hhh/plot that referenced this issue Jun 7, 2021
As part of racket#90, calls to `(make-bitmap ...)` were replaced with `(make-object
bitmap% ...)` but the two calls have different defaults for whether to create
an alpha channel for the bitmap or not. The `(make-object bitmap% ...)`
variant defaults to not having an alpha channel, so it needs to be explicitly
specified.
@alex-hhh
Copy link
Sponsor Collaborator

Racket snapshot builds now contain a fix for this issue and the fix will also be available in Racket 8.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants