diff options
author | bptato <nincsnevem662@gmail.com> | 2024-06-20 21:28:23 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-06-20 22:38:33 +0200 |
commit | 7f66b5ebc88936db974e3320d77c7ec9d4ab85e6 (patch) | |
tree | 669b2c307e2ea84476d6bbfd46ef127c0fc1c6f9 /src/img/bitmap.nim | |
parent | 2ab1e53b4bc15af3319994fdb25bb739b4b8e6db (diff) | |
download | chawan-7f66b5ebc88936db974e3320d77c7ec9d4ab85e6.tar.gz |
img: use stb_image, drop zlib as dependency
Now we have decoders for gif, jpeg, bmp. Also, the in-house PNG decoder has been replaced in favor of the stbi implementation; this means we no longer depend on zlib, since stbi comes with a built in inflate implementation.
Diffstat (limited to 'src/img/bitmap.nim')
-rw-r--r-- | src/img/bitmap.nim | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/img/bitmap.nim b/src/img/bitmap.nim index a186b47f..70244643 100644 --- a/src/img/bitmap.nim +++ b/src/img/bitmap.nim @@ -2,7 +2,7 @@ import types/color type Bitmap* = ref object of RootObj - px*: seq[ARGBColor] + px*: seq[RGBAColorBE] width*: uint64 height*: uint64 @@ -14,19 +14,25 @@ type proc newBitmap*(width, height: uint64): ImageBitmap = return ImageBitmap( - px: newSeq[ARGBColor](width * height), + px: newSeq[RGBAColorBE](width * height), width: width, height: height ) -proc setpx*(bmp: Bitmap; x, y: uint64; color: ARGBColor) {.inline.} = +proc setpx*(bmp: Bitmap; x, y: uint64; color: RGBAColorBE) {.inline.} = bmp.px[bmp.width * y + x] = color -proc getpx*(bmp: Bitmap; x, y: uint64): ARGBColor {.inline.} = +proc setpx*(bmp: Bitmap; x, y: uint64; color: ARGBColor) {.inline.} = + bmp.px[bmp.width * y + x] = rgba_be(color.r, color.g, color.b, color.a) + +proc getpx*(bmp: Bitmap; x, y: uint64): RGBAColorBE {.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) +proc setpxb*(bmp: Bitmap; x, y: uint64; c: RGBAColorBE) {.inline.} = + if c.a == 255: + bmp.setpx(x, y, c) else: - bmp.setpx(x, y, bmp.getpx(x, y).blend(color)) + bmp.setpx(x, y, bmp.getpx(x, y).blend(c)) + +proc setpxb*(bmp: Bitmap; x, y: uint64; c: ARGBColor) {.inline.} = + bmp.setpxb(x, y, rgba_be(c.r, c.g, c.b, c.a)) |