1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

gg,stbi: implement gg.create_image_from_memory/2

This commit is contained in:
Delyan Angelov
2020-08-04 13:18:08 +03:00
parent 216b6bf285
commit f9d241ae27
2 changed files with 21 additions and 14 deletions

View File

@@ -38,23 +38,20 @@ pub fn load(path string) Image {
flag := if ext == 'png' { C.STBI_rgb_alpha } else { 0 }
res.data = C.stbi_load(path.str, &res.width, &res.height, &res.nr_channels, flag)
if isnil(res.data) {
println('stbi image failed to load')
exit(1)
panic('stbi image failed to load')
}
return res
}
//pub fn load_from_memory(buf []byte) Image {
pub fn load_from_memory(buf byteptr) Image {
pub fn load_from_memory(buf byteptr, bufsize int) Image {
mut res := Image {
ok: true
data: 0
}
flag := C.STBI_rgb_alpha
res.data = C.stbi_load_from_memory(buf, 3812, &res.width, &res.height, &res.nr_channels, flag)
res.data = C.stbi_load_from_memory(buf, bufsize, &res.width, &res.height, &res.nr_channels, flag)
if isnil(res.data) {
println('stbi image failed to load from memory')
exit(1)
panic('stbi image failed to load from memory')
}
return res
}