pixie/tests/test_bmp.nim

65 lines
1.9 KiB
Nim
Raw Normal View History

2022-08-20 07:37:54 +00:00
import os, pixie, pixie/fileformats/bmp
2020-11-20 17:14:33 +00:00
2021-02-25 22:11:36 +00:00
# block:
# var image = newImage(4, 2)
# image[0, 0] = rgba(0, 0, 255, 255)
# image[1, 0] = rgba(0, 255, 0, 255)
# image[2, 0] = rgba(255, 0, 0, 255)
# image[3, 0] = rgba(255, 255, 255, 255)
# image[0, 1] = rgba(0, 0, 255, 127)
# image[1, 1] = rgba(0, 255, 0, 127)
# image[2, 1] = rgba(255, 0, 0, 127)
# image[3, 1] = rgba(255, 255, 255, 127)
2021-10-03 22:17:04 +00:00
# writeFile("tests/fileformats/bmp/test4x2.bmp", encodeBmp(image))
2021-02-25 22:11:36 +00:00
# var image2 = decodeBmp(encodeBmp(image))
# doAssert image2.width == image.width
# doAssert image2.height == image.height
# doAssert image2.data == image.data
# block:
# var image = newImage(16, 16)
# image.fill(rgba(255, 0, 0, 127))
2021-10-03 22:17:04 +00:00
# writeFile("tests/fileformats/bmp/test16x16.bmp", encodeBmp(image))
2021-02-25 22:11:36 +00:00
# var image2 = decodeBmp(encodeBmp(image))
# doAssert image2.width == image.width
# doAssert image2.height == image.height
# doAssert image2.data == image.data
2020-11-20 17:56:34 +00:00
block:
for bits in [32, 24]:
let
path = "tests/fileformats/bmp/knight." & $bits & ".master.bmp"
image = decodeBmp(readFile(path))
2021-10-03 22:17:04 +00:00
writeFile("tests/fileformats/bmp/knight." & $bits & ".bmp", encodeBmp(image))
2022-02-11 22:27:11 +00:00
block:
let image = decodeBmp(readFile(
"tests/fileformats/bmp/rgb.24.master.bmp"
))
writeFile("tests/fileformats/bmp/rgb.24.bmp", encodeBmp(image))
2022-02-12 04:08:09 +00:00
block:
for file in walkFiles("tests/fileformats/bmp/bmpsuite/*"):
2022-02-12 05:08:24 +00:00
# echo file
let
image = decodeBmp(readFile(file))
dimensions = decodeBmpDimensions(readFile(file))
2022-02-12 05:08:24 +00:00
#image.writeFile(file.replace("bmpsuite", "output") & ".png")
doAssert image.width == dimensions.width
doAssert image.height == dimensions.height
2022-08-20 07:37:54 +00:00
block:
let image = newImage(100, 100)
image.fill(color(1, 0, 0, 1))
let
encoded = encodeDib(image)
decoded = decodeDib(encoded.cstring, encoded.len, true)
doAssert image.data == decoded.data