Skip to content

Instantly share code, notes, and snippets.

@gingerBill
Created November 15, 2016 21:18
Show Gist options
  • Save gingerBill/29fd3f66c721848b506caabe3b7b4410 to your computer and use it in GitHub Desktop.
Save gingerBill/29fd3f66c721848b506caabe3b7b4410 to your computer and use it in GitHub Desktop.
#foreign_library "stb_image"
DEFAULT :: 0
GREY :: 1
GREY_ALPHA :: 2
RGB :: 3
RGB_ALPHA :: 4
io_callbacks :: struct #ordered {
read: proc(user: rawptr, data: ^byte, size: i32) -> i32 // fill 'data' with 'size' bytes. return number of bytes actually read
skip: proc(user: rawptr, n: i32) // skip the next 'n' bytes, or 'unget' the last -n bytes if negative
eof: proc(user: rawptr) -> i32 // returns nonzero if we are at end of file/data
}
load :: proc(filename: ^byte, x, y, comp: ^i32, req_comp: i32) -> ^byte #foreign "stbi_load"
load_from_memory :: proc(buffer: ^byte, len: i32, x, y, comp: ^i32, req_comp: i32) -> ^byte #foreign "stbi_load_from_memory"
load_from_callbacks :: proc(clbk: ^io_callbacks, user: rawptr, x, y, comp: ^i32, req_comp: i32) -> ^byte #foreign "stbi_load_from_callbacks"
hdr_to_ldr_gamma :: proc(gamma: f32) #foreign "stbi_hdr_to_ldr_gamma"
hdr_to_ldr_scale :: proc(scale: f32) #foreign "stbi_hdr_to_ldr_scale"
ldr_to_hdr_gamma :: proc(gamma: f32) #foreign "stbi_ldr_to_hdr_gamma"
ldr_to_hdr_scale :: proc(scale: f32) #foreign "stbi_ldr_to_hdr_scale"
is_hdr_from_memory :: proc(buffer: ^byte, len: i32) -> i32 #foreign "stbi_is_hdr_from_memory"
is_hdr_from_callbacks :: proc(clbk: ^io_callbacks, user: rawptr) -> i32 #foreign "stbi_is_hdr_from_callbacks"
is_hdr :: proc(filename: ^byte) -> i32 #foreign "stbi_is_hdr"
// get a VERY brief reason for failure
// NOT THREADSAFE
failure_reason :: proc() -> ^byte #foreign "stbi_failure_reason"
image_free :: proc(retval_from_stbi_load: rawptr) #foreign "stbi_image_free"
info :: proc(filename: ^byte, x, y, comp: ^i32) -> i32 #foreign "stbi_info"
info_from_memory :: proc(buffer: ^byte, len: i32, x, y, comp: ^i32) -> i32 #foreign "stbi_info_from_memory"
info_from_callbacks :: proc(clbk: ^io_callbacks, user: rawptr, x, y, comp: ^i32) -> i32 #foreign "stbi_info_from_callbacks"
set_unpremultiply_on_load :: proc(flag_true_if_should_unpremultiply: i32) #foreign "stbi_set_unpremultiply_on_load"
convert_iphone_png_to_rgb :: proc(flag_true_if_should_convert: i32) #foreign "stbi_convert_iphone_png_to_rgb"
set_flip_vertically_on_load :: proc(flag_true_if_should_flip: i32) #foreign "stbi_set_flip_vertically_on_load"
zlib_decode_malloc_guesssize :: proc(buffer: ^byte, len, initial_size: i32, outlen: ^i32) -> ^byte #foreign "stbi_zlib_decode_malloc_guesssize"
zlib_decode_malloc_guesssize_headerflag :: proc(buffer: ^byte, len, initial_size: i32, outlen: ^i32, parse_header: i32) -> ^byte #foreign "stbi_zlib_decode_malloc_guesssize_headerflag"
zlib_decode_malloc :: proc(buffer: ^byte, len: i32, outlen: ^i32) -> ^byte #foreign "stbi_zlib_decode_malloc"
zlib_decode_buffer :: proc(obuffer: ^byte, olen: i32, ibuffer: ^byte, ilen: i32) -> i32 #foreign "stbi_zlib_decode_buffer"
zlib_decode_noheader_malloc :: proc(buffer: ^byte, len: i32, outlen: ^i32) -> ^byte #foreign "stbi_zlib_decode_noheader_malloc"
zlib_decode_noheader_buffer :: proc(obuffer: ^byte, olen: i32, ibuffer: ^byte, ilen: i32) -> i32 #foreign "stbi_zlib_decode_noheader_buffer"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment