<div>Problem: The dc% method 'draw-bitmap-section disregards the boundaries of the drawing section when the 'color argument is the color black.</div><div><br></div><div>Not only does the documentation clearly state that the 'color argument should be ignored for a color bitmap, but it's quite bizarre that, upon seeing black, it decides to draw the whole bitmap, whereas if black is replaced by (say) green, it correctly draws only the specified section. I have observed this on nightly builds from the last several days on both Mac OS X and Linux.</div>
<div><br></div><div>To reproduce:</div><div><br></div><div><div>#lang racket/gui</div><div>;(current-directory "/Users/john/Dropbox/rkt")</div><div>;Just make sure you can access the PNGs.</div>
<div>(define u (make-object bitmap% "valkyrie.png"))</div><div>(send u set-loaded-mask (make-object bitmap% "valkyrie-umask.png"))</div><div><div><br>
(define frame (new frame% [label "Example"]</div><div> (x 900) (y 100)</div><div> (width 600) (height 600)))</div><div><br></div><div>(define cv (new canvas% [parent frame]))</div>
<div>(define dc (send cv get-dc))</div><div>(send frame show #t)</div></div><div><br></div><div>And now, at the REPL:</div><div><br></div><div><div>;Works properly<br>
(let ((nonce-color (make-object color% "green")))</div><div> (send dc clear)</div><div> (send dc draw-bitmap-section u 0 0 0 0 48 48</div><div> 'solid nonce-color (send u get-loaded-mask)))</div></div>
<div><br></div><div>;Screws up</div><div>(let ((nonce-color (make-object color%))) ;defaults to "black"</div></div><div> (send dc clear)</div><div> (send dc draw-bitmap-section u 0 0 0 0 48 48</div><div> 'solid nonce-color (send u get-loaded-mask)))</div>
<div><br></div><div>For convenience, I have attached one of the bitmaps and masks I've used.</div><div><br></div><div>Next, I complain about some other weird behavior of bitmaps (this behavior has, I think, existed for a long time). In the following example (code at the bottom of this email), I load a black-and-white bitmap (which seems to load as color), then create two bitmaps inside bitmap-dc%s (one monochrome and the other color), draw the original black-and-white bitmap to each of these bitmap-dc%s, and extract the bitmaps from the bitmap-dc%s. Now I have three black-and-white bitmaps that all look identical: the originally loaded one, the monochrome copy, and the color copy.</div>
<div><br></div><div>Now I try to use them as masks to draw the "valkyrie" bitmaps. What happens? The first one works, the second and third don't. Why is this? I investigated and found that, while the pixels of the copies are identical to those of the original (at least, the color copy is identical to the original), the "alpha" channel is different: the alpha bytes are all 0 on the original, but they're all 255 on both of the copies.</div>
<div><br></div><div>Questions/complaints:</div><div>1. Why does the alpha channel of a bitmap matter when it's being used as a mask?</div><div>2. Why doesn't drawing a bitmap to another one of the same size produce an exact copy of the first? (Or, if, say, the second one is monochrome while the first is color, why doesn't it produce the monochrome equivalent of the first? And vice versa.)</div>
<div><br></div><div>Code for REPL (the PNGs are needed again):</div><div><br></div><div>;Constructs three black-and-white bitmaps as described above.</div><div>;For each, draws the bitmap, then draws the "valkyrie" thing using the bitmap</div>
<div>; as a mask, then prints out whether it's color and the value of the 0th alpha byte.</div><div><div><div>(let* ((u (make-object bitmap% "valkyrie.png"))</div><div> (um (make-object bitmap% "valkyrie-umask.png"))</div>
<div> (umm (make-object bitmap-dc%</div><div> (make-monochrome-bitmap (send um get-width) (send um get-height))))</div><div> (umc (make-object bitmap-dc%</div><div> (make-bitmap (send um get-width) (send um get-height)))))</div>
<div> (send umm draw-bitmap um 0 0)</div><div> (send umc draw-bitmap um 0 0)</div><div> (let ((mu (send umm get-bitmap))</div><div> (cu (send umc get-bitmap)))</div><div> (for-each (lambda (x)</div><div> (send dc clear)</div>
<div> (send dc draw-bitmap x 0 0)</div><div> (sleep 1)</div><div> (send dc clear)</div><div> (send dc draw-bitmap u 0 0 'solid (make-object color% "green")</div>
<div> x)</div><div> (for-each display (list "color? " (send x is-color?)</div><div> " alpha-byte " (let ((c (make-bytes 9000)))</div>
<div> (send x get-argb-pixels 0 0 10 10 c 't)</div><div> (bytes-ref c 0))))</div><div> (newline)</div>
<div> (sleep 1))</div><div> (list um mu cu))))</div></div></div>--John Boyle<br>