stbi: add proper declarations for C.stbi_load etc.
parent
0081e77969
commit
e066e83041
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
module stbi
|
module stbi
|
||||||
|
|
||||||
|
|
||||||
#flag -I @VROOT/thirdparty/stb_image
|
#flag -I @VROOT/thirdparty/stb_image
|
||||||
#include "stb_image.h"
|
#include "stb_image.h"
|
||||||
#flag @VROOT/thirdparty/stb_image/stbi.o
|
#flag @VROOT/thirdparty/stb_image/stbi.o
|
||||||
|
@ -19,10 +18,15 @@ pub mut:
|
||||||
ext string
|
ext string
|
||||||
}
|
}
|
||||||
|
|
||||||
fn C.stbi_load() voidptr
|
fn C.stbi_load(filename charptr, x &int, y &int, channels_in_file &int, desired_channels int) byteptr
|
||||||
fn C.stbi_load_from_memory() voidptr
|
|
||||||
fn C.stbi_image_free()
|
fn C.stbi_load_from_file(f voidptr, x &int, y &int, channels_in_file &int, desired_channels int) byteptr
|
||||||
fn C.stbi_set_flip_vertically_on_load()
|
|
||||||
|
fn C.stbi_load_from_memory(buffer byteptr, len int, x &int, y &int, channels_in_file &int, desired_channels int) byteptr
|
||||||
|
|
||||||
|
fn C.stbi_image_free(retval_from_stbi_load byteptr)
|
||||||
|
|
||||||
|
fn C.stbi_set_flip_vertically_on_load(should_flip int)
|
||||||
|
|
||||||
fn init() {
|
fn init() {
|
||||||
set_flip_vertically_on_load(false)
|
set_flip_vertically_on_load(false)
|
||||||
|
@ -30,13 +34,13 @@ fn init() {
|
||||||
|
|
||||||
pub fn load(path string) ?Image {
|
pub fn load(path string) ?Image {
|
||||||
ext := path.all_after_last('.')
|
ext := path.all_after_last('.')
|
||||||
mut res := Image {
|
mut res := Image{
|
||||||
ok: true
|
ok: true
|
||||||
ext: ext
|
ext: ext
|
||||||
data: 0
|
data: 0
|
||||||
}
|
}
|
||||||
flag := if ext == 'png' { C.STBI_rgb_alpha } else { 0 }
|
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)
|
res.data = C.stbi_load(path.str, &res.width, &res.height, &res.nr_channels, flag)
|
||||||
if isnil(res.data) {
|
if isnil(res.data) {
|
||||||
return error('stbi image failed to load from "$path"')
|
return error('stbi image failed to load from "$path"')
|
||||||
}
|
}
|
||||||
|
@ -44,19 +48,19 @@ pub fn load(path string) ?Image {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_from_memory(buf byteptr, bufsize int) ?Image {
|
pub fn load_from_memory(buf byteptr, bufsize int) ?Image {
|
||||||
mut res := Image {
|
mut res := Image{
|
||||||
ok: true
|
ok: true
|
||||||
data: 0
|
data: 0
|
||||||
}
|
}
|
||||||
flag := C.STBI_rgb_alpha
|
flag := C.STBI_rgb_alpha
|
||||||
res.data = C.stbi_load_from_memory(buf, bufsize, &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) {
|
if isnil(res.data) {
|
||||||
return error('stbi image failed to load from memory')
|
return error('stbi image failed to load from memory')
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn (img &Image) free() {
|
pub fn (img &Image) free() {
|
||||||
C.stbi_image_free(img.data)
|
C.stbi_image_free(img.data)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue