pixie/tests/test_images.nim

46 lines
1 KiB
Nim
Raw Normal View History

2021-01-23 20:17:28 +00:00
import pixie, chroma, vmath
2020-11-22 20:12:53 +00:00
2020-11-20 06:12:44 +00:00
block:
2021-01-23 20:17:28 +00:00
let image = newImage(10, 10)
2020-11-20 06:12:44 +00:00
image[0, 0] = rgba(255, 255, 255, 255)
doAssert image[0, 0] == rgba(255, 255, 255, 255)
block:
2021-01-23 20:17:28 +00:00
let image = newImage(10, 10)
2020-11-28 00:54:10 +00:00
image.fill(rgba(255, 0, 0, 255))
2020-11-20 06:12:44 +00:00
doAssert image[0, 0] == rgba(255, 0, 0, 255)
2020-11-21 18:34:57 +00:00
2021-01-20 00:50:51 +00:00
block:
2021-01-23 20:17:28 +00:00
let
image = newImage(256, 256)
subImage = image.subImage(0, 0, 128, 128)
doAssert subImage.width == 128 and subImage.height == 128
block:
let image = newImage(10, 10)
2021-01-20 00:50:51 +00:00
image.fill(rgba(255, 0, 0, 128))
image.toPremultipliedAlpha()
2021-01-20 00:50:51 +00:00
doAssert image[9, 9] == rgba(128, 0, 0, 128)
block:
2021-01-23 20:17:28 +00:00
let image = newImage(10, 10)
2021-01-20 00:50:51 +00:00
image.fill(rgba(128, 0, 0, 128))
image.toStraightAlpha()
2021-01-24 22:03:35 +00:00
doAssert image[9, 9] == rgba(254, 0, 0, 128)
2021-01-20 00:50:51 +00:00
2021-01-23 05:33:05 +00:00
block:
let
a = newImage(101, 101)
b = newImage(50, 50)
a.fill(rgba(255, 0, 0, 255))
b.fill(rgba(0, 255, 0, 255))
a.draw(b, vec2(0, 0))
a.writeFile("tests/images/flipped1.png")
a.flipVertical()
a.writeFile("tests/images/flipped2.png")
a.flipHorizontal()
a.writeFile("tests/images/flipped3.png")