1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
import types/color
type
CanvasFillRule* = enum
NON_ZERO = "nonzero"
EVEN_ODD = "evenodd"
Bitmap* = ref object of RootObj
px*: seq[RGBAColor]
width*: uint64
height*: uint64
ImageBitmap* = ref object of Bitmap
proc newBitmap*(width, height: uint64): Bitmap =
return ImageBitmap(
px: newSeq[RGBAColor](width * height),
width: width,
height: height
)
proc setpx*(bmp: Bitmap, x, y: uint64, color: RGBAColor) {.inline.} =
bmp.px[bmp.width * y + x] = color
proc getpx*(bmp: Bitmap, x, y: uint64): RGBAColor {.inline.} =
return bmp.px[bmp.width * y + x]
proc setpxb*(bmp: Bitmap, x, y: uint64, color: RGBAColor) {.inline.} =
if color.a == 255:
bmp.setpx(x, y, color)
else:
bmp.setpx(x, y, bmp.getpx(x, y).blend(color))
|