2021-12-08 01:31:37 +03:00
|
|
|
import os
|
|
|
|
import stbi
|
|
|
|
|
2022-11-03 10:24:52 +03:00
|
|
|
const tfolder = os.join_path(os.vtmp_dir(), 'v', 'stbi')
|
2022-09-16 04:56:19 +03:00
|
|
|
|
|
|
|
fn testsuite_begin() {
|
|
|
|
os.mkdir_all(tfolder) or {}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn testsuite_end() {
|
|
|
|
os.rmdir_all(tfolder) or {}
|
|
|
|
}
|
|
|
|
|
2021-12-08 01:31:37 +03:00
|
|
|
fn test_stbi_read_write() {
|
|
|
|
vroot := @VEXEROOT
|
|
|
|
path := os.join_path(vroot, 'examples', 'assets', 'logo.png')
|
|
|
|
println('Source path: $path')
|
|
|
|
d_s := stbi.load(path) or { panic(err) }
|
|
|
|
println('Image source data:\n $d_s')
|
|
|
|
|
2022-09-16 04:56:19 +03:00
|
|
|
out_path := os.join_path(tfolder, 'test.png')
|
2021-12-08 01:31:37 +03:00
|
|
|
println('Out path: $out_path')
|
|
|
|
stbi.stbi_write_png(out_path, d_s.width, d_s.height, 4, d_s.data, d_s.width * 4) or {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
d_d := stbi.load(out_path) or { panic(err) }
|
|
|
|
println('Image dest data:\n $d_d')
|
|
|
|
|
|
|
|
assert d_s.width == d_d.width
|
|
|
|
assert d_s.height == d_d.height
|
|
|
|
assert d_s.nr_channels == d_d.nr_channels
|
|
|
|
|
|
|
|
mut v_s := &u32(d_s.data)
|
|
|
|
mut v_d := &u32(d_d.data)
|
|
|
|
mut delta := i64(0)
|
|
|
|
for index in 0 .. (d_d.width * d_d.width) {
|
|
|
|
unsafe {
|
|
|
|
delta += v_s[index] - v_d[index]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert 0 == delta
|
|
|
|
os.rm(out_path) or {}
|
|
|
|
}
|