From a12e82aa155c23a6fcc6f49d40fa8df52b43b539 Mon Sep 17 00:00:00 2001 From: Casper Kuethe <43839798+Casper64@users.noreply.github.com> Date: Thu, 22 Jun 2023 15:47:52 +0200 Subject: [PATCH] stbi: allow customisation of number of channels in stbi.load (#18491) --- vlib/stbi/stbi.c.v | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/vlib/stbi/stbi.c.v b/vlib/stbi/stbi.c.v index b488cf4d04..37f4aec7ca 100644 --- a/vlib/stbi/stbi.c.v +++ b/vlib/stbi/stbi.c.v @@ -110,8 +110,15 @@ fn C.stbi_load(filename &char, x &int, y &int, channels_in_file &int, desired_ch fn C.stbi_load_from_file(f voidptr, x &int, y &int, channels_in_file &int, desired_channels int) &u8 fn C.stbi_load_from_memory(buffer &u8, len int, x &int, y &int, channels_in_file &int, desired_channels int) &u8 +[params] +pub struct LoadParams { + // the number of channels you expect the image to have. + // If set to 0 stbi will figure out the correct number of channels + desired_channels int = C.STBI_rgb_alpha +} + // load load an image from a path -pub fn load(path string) !Image { +pub fn load(path string, params LoadParams) !Image { ext := path.all_after_last('.') mut res := Image{ ok: true @@ -119,7 +126,7 @@ pub fn load(path string) !Image { data: 0 } res.data = C.stbi_load(&char(path.str), &res.width, &res.height, &res.nr_channels, - C.STBI_rgb_alpha) + params.desired_channels) if isnil(res.data) { return error('stbi_image failed to load from "${path}"')