Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Corry committed Nov 8, 2023
1 parent 7bdd009 commit 444a842
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/true_color.toit
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,33 @@ class Canvas extends AbstractCanvas:
source_byte_width := (source_width + 7) >> 3
zero_alpha := alpha[0]
one_alpha := alpha[1]
one_r := palette[3]
one_g := palette[4]
one_b := palette[5]
draw_pixels := pixels
if one_alpha == 0:
if zero_alpha == 0: return
if zero_alpha == 0xff:
if zero_alpha == 0: return // Both transparent.
if zero_alpha == 0xff: // Swap 0 and 1.
inverted := ByteArray pixels.size --filler=0xff
blit pixels inverted source_byte_width --operation=XOR
draw_pixels = inverted
zero_alpha = 0
one_alpha = 0xff
one_r = palette[0]
one_g = palette[1]
one_b = palette[2]
if one_alpha == 0xff:
if zero_alpha == 0xff or zero_alpha == 0:
if zero_alpha == 0xff:
h := pixels.size / source_byte_width
// Draw the zeros.
bytemap_rectangle x y palette[0] source_width h red_ width_
bytemap_rectangle x y palette[1] source_width h green_ width_
bytemap_rectangle x y palette[2] source_width h blue_ width_
bitmap_draw_bitmap x y palette[3] orientation pixels 0 source_width red_ width_ true
bitmap_draw_bitmap x y palette[4] orientation pixels 0 source_width green_ width_ true
bitmap_draw_bitmap x y palette[5] orientation pixels 0 source_width blue_ width_ true
// Draw the ones.
bitmap_draw_bitmap x y one_r orientation pixels 0 source_width red_ width_ true
bitmap_draw_bitmap x y one_g orientation pixels 0 source_width green_ width_ true
bitmap_draw_bitmap x y one_b orientation pixels 0 source_width blue_ width_ true
return
// Unfortunately one of the alpha values is not 0 or 0xff, so we can't use
// the bitmap draw primitive. We can blow it up to bytes, then use the
Expand Down

0 comments on commit 444a842

Please sign in to comment.