about summary refs log tree commit diff stats
path: root/src/img/bitmap.nim
blob: 064e574df1e8239431179331ade3dcb4b53f12d6 (plain) (blame)
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
import types/color

type
  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))