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