diff --git a/vlib/gg/image.c.v b/vlib/gg/image.c.v index 03d852ab9d..ec57680c50 100644 --- a/vlib/gg/image.c.v +++ b/vlib/gg/image.c.v @@ -227,9 +227,8 @@ pub fn (mut ctx Context) create_image_from_memory(buf &u8, bufsize int) Image { ok: stb_img.ok data: stb_img.data ext: stb_img.ext + id: ctx.image_cache.len } - img.init_sokol_image() - img.id = ctx.image_cache.len ctx.image_cache << img return img } diff --git a/vlib/stbi/stbi.c.v b/vlib/stbi/stbi.c.v index e233e39b01..dbadf43fda 100644 --- a/vlib/stbi/stbi.c.v +++ b/vlib/stbi/stbi.c.v @@ -108,21 +108,13 @@ pub fn load(path string) ?Image { // load_from_memory load an image from a memory buffer pub fn load_from_memory(buf &u8, bufsize int) ?Image { - return load_from_memory_with_channels(buf, bufsize, 0) -} - -// load_from_memory_with_channels an image from a memory buffer, with user-defined number of image channels -pub fn load_from_memory_with_channels(buf &u8, bufsize int, desired_channels int) ?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, - desired_channels) - if desired_channels == 4 && res.nr_channels == 3 { - // Fix an alpha png bug - res.nr_channels = 4 - } + flag) if isnil(res.data) { return error('stbi_image failed to load from memory') }