Skip to content

Commit

Permalink
Use new named arg calls for bitmap-draw-b* in SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Corry committed Nov 12, 2023
1 parent 244e5f8 commit 5a25c50
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/four_gray.toit
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ class OpaquePixmapTexture extends BitmapTextureBase_:
draw_ bx by orientation canvas/TwoBitCanvas_:
// The area was already zeroed, add in the 1s as needed.
bitmap_draw_bitmap bx by 1 orientation bytes_ 0 w canvas.plane_0_ canvas.width_ false
bitmap_draw_bitmap bx by 1 orientation bytes_2_ 0 w canvas.plane_1_ canvas.width_ false
bitmap_draw_bitmap bx by --color=1 --orientation=orientation --source=bytes_ --source_width=w --destination=canvas.plane_0_ --destination_width=canvas.width_
bitmap_draw_bitmap bx by --color=1 --orientation=orientation --source=bytes_2_ --source_width=w --destination=canvas.plane_1_ --destination_width=canvas.width_

// A texture backed by a P4 (binary two-level) PBM file. The white areas
// (zeros) are rendered transparent and the black areas (ones) are rendered in
Expand Down
4 changes: 2 additions & 2 deletions src/gray_scale.toit
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ class PixmapTexture extends PixmapTexture_:

draw_ bx by orientation canvas/Canvas:
if transparency_:
bitmap_draw_bytemap bx by 42 orientation bytes_ w palette_ canvas.pixels_ canvas.width_
bitmap_draw_bytemap bx by --transparent_index=42 --orientation=orientation --source=bytes_ --source_width=w --palette=palette_ --destination=canvas.pixels_ --destination_width=canvas.width_
else:
bitmap_draw_bytemap bx by -1 orientation bytes_ w palette_ canvas.pixels_ canvas.width_
bitmap_draw_bytemap bx by --orientation=orientation --source=bytes_ --source_width=w --palette=palette_ --destination=canvas.pixels_ --destination_width=canvas.width_

class BarCodeEan13 extends OneByteBarCodeEan13_:
constructor code/string x/int y/int transform/Transform:
Expand Down
6 changes: 3 additions & 3 deletions src/one_byte.toit
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class OneByteCanvas_ extends AbstractCanvas:
--source_width/int
--orientation/int=ORIENTATION_0:
transform.xyo x y orientation: | x2 y2 o2 |
bitmap_draw_bytemap x2 y2 -1 o2 pixels source_width palette pixels_ width_
bitmap_draw_bytemap x2 y2 --orientation=o2 --source=pixels --source_width=source_width --palette=palette --destination=pixels_ --destination_width=width_

class OneByteFilledRectangle_ extends FilledRectangle_:
color_ := ?
Expand Down Expand Up @@ -115,7 +115,7 @@ class OneByteBitmapTexture_ extends BitmapTexture_:
super x y w h transform

draw_ bx by orientation canvas/OneByteCanvas_:
bitmap_draw_bitmap bx by color_ orientation bytes_ 0 w canvas.pixels_ canvas.width_ true
bitmap_draw_bitmap bx by --color=color_ --orientation=orientation --source=bytes_ --source_width=w --destination=canvas.pixels_ --destination_width=canvas.width_ --bytewise=true

/**
A two color bitmap texture where foreground and background pixels in the
Expand Down Expand Up @@ -162,7 +162,7 @@ class OneBytePbmTexture_ extends BitmapTexture_:
super.no_allocate_ x y parser.width parser.height transform

draw_ bx by orientation canvas/OneByteCanvas_:
bitmap_draw_bitmap bx by color_ orientation bytes_ 0 w canvas.pixels_ canvas.width_ true
bitmap_draw_bitmap bx by --color=color_ --orientation=orientation --source=bytes_ --source_width=w --destination=canvas.pixels_ --destination_width=canvas.width_ --bytewise

abstract class OneByteBarCodeEan13_ extends BarCodeEan13_:
constructor code/string x/int y/int transform/Transform:
Expand Down
44 changes: 22 additions & 22 deletions src/true_color.toit
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,24 @@ class Canvas extends AbstractCanvas:
// Draw the zeros.
rectangle x y --w=source_width --h=h --color=(BIG_ENDIAN.uint24 palette 0)
// Draw the ones.
transform.xyo x y 0: | x2 y2 orientation |
bitmap_draw_bitmap x2 y2 palette[3] orientation pixels 0 source_width line_stride red_ width_ true
bitmap_draw_bitmap x2 y2 palette[4] orientation pixels 0 source_width line_stride green_ width_ true
bitmap_draw_bitmap x2 y2 palette[5] orientation pixels 0 source_width line_stride blue_ width_ true
transform.xyo x y 0: | x2 y2 o2 |
bitmap_draw_bitmap x2 y2 --color=palette[3] --orientation=o2 --source=pixels --source_width=source_width --source_stride=line_stride --destination=red_ --destination_width=width_ --bytewise
bitmap_draw_bitmap x2 y2 --color=palette[4] --orientation=o2 --source=pixels --source_width=source_width --source_stride=line_stride --destination=green_ --destination_width=width_ --bytewise
bitmap_draw_bitmap x2 y2 --color=palette[5] --orientation=o2 --source=pixels --source_width=source_width --source_stride=line_stride --destination=blue_ --destination_width=width_ --bytewise
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
// bitmap_draw_bytemap.
h := pixels.size / source_byte_width
bytemap := ByteArray source_width * h
bitmap_draw_bitmap 0 0 1 0 pixels 0 source_width line_stride bytemap source_width true
transform.xyo x y 0: | x2 y2 orientation |
bitmap_draw_bytemap x2 y2 alpha orientation bytemap source_width source_width palette red_ width_
bitmap_draw_bytemap x2 y2 alpha orientation bytemap source_width source_width palette[1..] green_ width_
bitmap_draw_bytemap x2 y2 alpha orientation bytemap source_width source_width palette[2..] blue_ width_
bitmap_draw_bitmap 0 0 --color=1 --source=pixels --source_width=source_width --destination=bytemap --destination_width=source_width --bytewise
transform.xyo x y 0: | x2 y2 o2 |
bitmap_draw_bytemap x2 y2 --alpha=alpha --orientation=o2 --source=bytemap --source_width=source_width --palette=palette --destination=red_ --destination_width=width_
bitmap_draw_bytemap x2 y2 --alpha=alpha --orientation=o2 --source=bytemap --source_width=source_width --palette=palette[1..] --destination=green_ --destination_width=width_
bitmap_draw_bytemap x2 y2 --alpha=alpha --orientation=o2 --source=bytemap --source_width=source_width --palette=palette[2..] --destination=blue_ --destination_width=width_

rgb_pixmap x/int y/int --r/ByteArray --g/ByteArray --b/ByteArray
--alpha=-1
--alpha/ByteArray=#[]
--palette/ByteArray?=null
--source_width/int
--orientation/int=ORIENTATION_0
Expand All @@ -138,9 +138,9 @@ class Canvas extends AbstractCanvas:
palette_g := palette ? palette[1..] : #[]
palette_b := palette ? palette[2..] : #[]
transform.xyo x y orientation: | x2 y2 o2 |
bitmap_draw_bytemap x2 y2 alpha o2 r source_width line_stride palette_r red_ width_
bitmap_draw_bytemap x2 y2 alpha o2 g source_width line_stride palette_g green_ width_
bitmap_draw_bytemap x2 y2 alpha o2 b source_width line_stride palette_b blue_ width_
bitmap_draw_bytemap x2 y2 --alpha=alpha --orientation=o2 --source=r --source_width=source_width --source_stride=line_stride --palette=palette_r --destination=red_ --destination_width=width_
bitmap_draw_bytemap x2 y2 --alpha=alpha --orientation=o2 --source=g --source_width=source_width --source_stride=line_stride --palette=palette_g --destination=green_ --destination_width=width_
bitmap_draw_bytemap x2 y2 --alpha=alpha --orientation=o2 --source=b --source_width=source_width --source_stride=line_stride --palette=palette_b --destination=blue_ --destination_width=width_

class FilledRectangle extends FilledRectangle_:
color_ := ?
Expand Down Expand Up @@ -205,9 +205,9 @@ class BitmapTexture extends BitmapTexture_:
super x y w h transform

draw_ bx by orientation canvas/Canvas:
bitmap_draw_bitmap bx by (red_component color_) orientation bytes_ 0 w canvas.red_ canvas.width_ true
bitmap_draw_bitmap bx by (green_component color_) orientation bytes_ 0 w canvas.green_ canvas.width_ true
bitmap_draw_bitmap bx by (blue_component color_) orientation bytes_ 0 w canvas.blue_ canvas.width_ true
bitmap_draw_bitmap bx by --color=(red_component color_) --orientation=orientation --source=bytes_ --source_width=w --destination=canvas.red_ --destination_width=canvas.width_ --bytewise
bitmap_draw_bitmap bx by --color=(green_component color_) --orientation=orientation --source=bytes_ --source_width=w --destination=canvas.green_ --destination_width=canvas.width_ --bytewise
bitmap_draw_bitmap bx by --color=(blue_component color_) --orientation=orientation --source=bytes_ --source_width=w --destination=canvas.blue_ --destination_width=canvas.width_ --bytewise

/**
A two color bitmap texture where foreground and background pixels in the
Expand Down Expand Up @@ -252,9 +252,9 @@ class PbmTexture extends BitmapTexture_:
super.no_allocate_ x y parser.width parser.height transform

draw_ bx by orientation canvas/Canvas:
bitmap_draw_bitmap bx by (red_component color_) orientation bytes_ 0 w canvas.red_ canvas.width_ true
bitmap_draw_bitmap bx by (green_component color_) orientation bytes_ 0 w canvas.green_ canvas.width_ true
bitmap_draw_bitmap bx by (blue_component color_) orientation bytes_ 0 w canvas.blue_ canvas.width_ true
bitmap_draw_bitmap bx by --color=(red_component color_) --orientation=orientation --source=bytes_ --source_width=w --destination=canvas.red_ --destination_width=canvas.width_ --bytewise
bitmap_draw_bitmap bx by --color=(green_component color_) --orientation=orientation --source=bytes_ --source_width=w --destination=canvas.green_ --destination_width=canvas.width_ --bytewise
bitmap_draw_bitmap bx by --color=(blue_component color_) --orientation=orientation --source=bytes_ --source_width=w --destination=canvas.blue_ --destination_width=canvas.width_ --bytewise

/**
A rectangular pixmap that can be drawn in any of 4 orientations on a canvas.
Expand Down Expand Up @@ -354,9 +354,9 @@ class IndexedPixmapTexture extends PixmapTexture_:
draw_ bx by orientation canvas/Canvas:
if not green_palette_: green_palette_ = palette_[1..]
if not blue_palette_: blue_palette_ = palette_[2..]
bitmap_draw_bytemap bx by 0 orientation bytes_ w w palette_ canvas.red_ canvas.width_
bitmap_draw_bytemap bx by 0 orientation bytes_ w w green_palette_ canvas.green_ canvas.width_
bitmap_draw_bytemap bx by 0 orientation bytes_ w w blue_palette_ canvas.blue_ canvas.width_
bitmap_draw_bytemap bx by --transparent_index=0 --orientation=orientation --source=bytes_ --source_width=w --palette=palette_ --destination=canvas.red_ --destination_width=canvas.width_
bitmap_draw_bytemap bx by --transparent_index=0 --orientation=orientation --source=bytes_ --source_width=w --palette=green_palette_ --destination=canvas.green_ --destination_width=canvas.width_
bitmap_draw_bytemap bx by --transparent_index=0 --orientation=orientation --source=bytes_ --source_width=w --palette=blue_palette_ --destination=canvas.blue_ --destination_width=canvas.width_

class BarCodeEan13 extends BarCodeEan13_:
constructor code/string x/int y/int transform/Transform:
Expand Down
8 changes: 4 additions & 4 deletions src/two_bit_texture.toit
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ class TwoBitBitmapTexture_ extends BitmapTexture_:
super x y w h transform

draw_ bx by orientation canvas/TwoBitCanvas_:
bitmap_draw_bitmap bx by (color_ & 1) orientation bytes_ 0 w canvas.plane_0_ canvas.width_ false
bitmap_draw_bitmap bx by ((color_ & 2) >> 1) orientation bytes_ 0 w canvas.plane_1_ canvas.width_ false
bitmap_draw_bitmap bx by --color=(color_ & 1) --orientation=orientation --source=bytes_ --source_width=w --destination=canvas.plane_0_ --destination_width=canvas.width_
bitmap_draw_bitmap bx by --color=((color_ & 2) >> 1) --orientation=orientation --source=bytes_ --source_width=w --destination=canvas.plane_1_ --destination_width=canvas.width_

/**
A two color bitmap texture where foreground and background pixels in the
Expand Down Expand Up @@ -165,8 +165,8 @@ class PbmTexture_ extends BitmapTexture_:
super.no_allocate_ x y parser.width parser.height transform

draw_ bx by orientation canvas/TwoBitCanvas_:
bitmap_draw_bitmap bx by (color_ & 1) orientation bytes_ 0 w canvas.plane_0_ canvas.width_ false
bitmap_draw_bitmap bx by ((color_ & 2) >> 1) orientation bytes_ 0 w canvas.plane_1_ canvas.width_ false
bitmap_draw_bitmap bx by --color=(color_ & 1) --orientation=orientation --source=bytes_ --source_width=w --destination=canvas.plane_0_ --destination_width=canvas.width_
bitmap_draw_bitmap bx by --color=((color_ & 2) >> 1) --orientation=orientation --source=bytes_ --source_width=w --destination=canvas.plane_1_ --destination_width=canvas.width_

class TwoBitBarCodeEan13_ extends BarCodeEan13_:
black_ := 0
Expand Down
8 changes: 3 additions & 5 deletions src/two_color.toit
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ class Canvas extends AbstractCanvas:
--source_width/int
--orientation/int:
transform.xyo x y orientation: | x2 y2 o2 |
bytewise := false
offset := 0
bitmap_draw_bitmap x2 y2 1 o2 pixels offset source_width pixels_ width_ bytewise
bitmap_draw_bitmap x2 y2 --color=1 --orientation=o2 --source=pixels --source_width=source_width --destination=pixels_ --destination_width=width_

class FilledRectangle extends FilledRectangle_:
color_ := ?
Expand Down Expand Up @@ -142,7 +140,7 @@ class BitmapTexture extends BitmapTexture_:
super x y w h transform

draw_ bx by orientation canvas/Canvas:
bitmap_draw_bitmap bx by color_ orientation bytes_ 0 w canvas.pixels_ canvas.width_ false
bitmap_draw_bitmap bx by --color=color_ --orientation=orientation --source=bytes_ --source_width=w --destination=canvas.pixels_ --destination_width=canvas.width_

/**
A two color bitmap texture where foreground and background pixels in the
Expand Down Expand Up @@ -305,7 +303,7 @@ class PbmTexture extends BitmapTexture_:
super.no_allocate_ x y parser.width parser.height transform

draw_ bx by orientation canvas/Canvas:
bitmap_draw_bitmap bx by color_ orientation bytes_ 0 w canvas.pixels_ canvas.width_ false
bitmap_draw_bitmap bx by --color=color_ --orientation=orientation --source=bytes_ --source_width=w --destination=canvas.pixels_ --destination_width=canvas.width_

// A texture backed by a P4 (binary two-level) PBM file. This is normally more
// efficient than the Pbm class, but it cannot scale the image.
Expand Down

0 comments on commit 5a25c50

Please sign in to comment.