about summary refs log tree commit diff stats
path: root/src/img/bitmap.nim
blob: 9f9b3401384cafb281a669660c7139279e593e70 (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[ARGBColor]
    width*: uint64
    height*: uint64

  ImageBitmap* = ref object of Bitmap

proc newBitmap*(width, height: uint64): Bitmap =
  return ImageBitmap(
    px: newSeq[ARGBColor](width * height),
    width: width,
    height: height
  )

proc setpx*(bmp: Bitmap; x, y: uint64; color: ARGBColor) {.inline.} =
  bmp.px[bmp.width * y + x] = color

proc getpx*(bmp: Bitmap; x, y: uint64): ARGBColor {.inline.} =
  return bmp.px[bmp.width * y + x]

proc setpxb*(bmp: Bitmap; x, y: uint64; color: ARGBColor) {.inline.} =
  if color.a == 255:
    bmp.setpx(x, y, color)
  else:
    bmp.setpx(x, y, bmp.getpx(x, y).blend(color))