mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
gg,stbi: implement gg.create_image_from_memory/2
This commit is contained in:
parent
216b6bf285
commit
f9d241ae27
24
vlib/gg/gg.v
24
vlib/gg/gg.v
@ -272,6 +272,23 @@ pub fn create_image(file string) Image {
|
|||||||
return img
|
return img
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn create_image_from_memory(buf byteptr, bufsize int) Image {
|
||||||
|
stb_img := stbi.load_from_memory(buf, bufsize)
|
||||||
|
mut img := Image{
|
||||||
|
width: stb_img.width
|
||||||
|
height: stb_img.height
|
||||||
|
nr_channels: stb_img.nr_channels
|
||||||
|
ok: stb_img.ok
|
||||||
|
data: stb_img.data
|
||||||
|
ext: stb_img.ext
|
||||||
|
}
|
||||||
|
return img
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn create_image_from_byte_array(b []byte) Image {
|
||||||
|
return create_image_from_memory(b.data, b.len)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn (mut img Image) init_sokol_image() &Image {
|
pub fn (mut img Image) init_sokol_image() &Image {
|
||||||
mut img_desc := C.sg_image_desc{
|
mut img_desc := C.sg_image_desc{
|
||||||
width: img.width
|
width: img.width
|
||||||
@ -291,13 +308,6 @@ pub fn (mut img Image) init_sokol_image() &Image {
|
|||||||
return img
|
return img
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_image_from_memory(buf byteptr) u32 {
|
|
||||||
// texture := gl.gen_texture()
|
|
||||||
// img := stbi.load_from_memory(buf)
|
|
||||||
// img.free()
|
|
||||||
return 0 // texture
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn (gg &Context) begin() {
|
pub fn (gg &Context) begin() {
|
||||||
if gg.render_text && gg.font_inited {
|
if gg.render_text && gg.font_inited {
|
||||||
gg.ft.flush()
|
gg.ft.flush()
|
||||||
|
@ -38,23 +38,20 @@ pub fn load(path string) Image {
|
|||||||
flag := if ext == 'png' { C.STBI_rgb_alpha } else { 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) {
|
if isnil(res.data) {
|
||||||
println('stbi image failed to load')
|
panic('stbi image failed to load')
|
||||||
exit(1)
|
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
//pub fn load_from_memory(buf []byte) Image {
|
pub fn load_from_memory(buf byteptr, bufsize int) Image {
|
||||||
pub fn load_from_memory(buf byteptr) Image {
|
|
||||||
mut res := Image {
|
mut res := Image {
|
||||||
ok: true
|
ok: true
|
||||||
data: 0
|
data: 0
|
||||||
}
|
}
|
||||||
flag := C.STBI_rgb_alpha
|
flag := C.STBI_rgb_alpha
|
||||||
res.data = C.stbi_load_from_memory(buf, 3812, &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) {
|
if isnil(res.data) {
|
||||||
println('stbi image failed to load from memory')
|
panic('stbi image failed to load from memory')
|
||||||
exit(1)
|
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user