From 3c25f506ed2e66802a0a2b07c5650d0cb6cf5257 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 10 Oct 2022 10:37:39 +0300 Subject: [PATCH] Revert "stbi: fix loading image from memory (#15981); breaks UI's rectangle example on macos, probably others too" This reverts commit 07d5612347b408b0933a02c893d6122135f2b374. --- vlib/gg/image.c.v | 3 +-- vlib/stbi/stbi.c.v | 12 ++---------- 2 files changed, 3 insertions(+), 12 deletions(-) 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') }