Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add stbi.loadf #5

Closed
leyaocty opened this issue Jun 7, 2021 · 2 comments
Closed

add stbi.loadf #5

leyaocty opened this issue Jun 7, 2021 · 2 comments

Comments

@leyaocty
Copy link

leyaocty commented Jun 7, 2021

hi neil,
would you please help to wrap C.stbi_loadf()? I tried to wrap it based on your pkg but failed...

@neilpa
Copy link
Owner

neilpa commented Jun 14, 2021

@leyaocty do you have an example image that you can share to test with?

@leyaocty
Copy link
Author

@neilpa it works now, fyi
func Loadf(path string) (dt []float32, w int, h int, nre int, mfree func(), err error) {
// C.stbi_set_flip_vertically_on_load(1) // vertical reverse
cpath := C.CString(path)
defer C.free(unsafe.Pointer(cpath))

var x, y, nr C.int
data := C.stbi_loadf(cpath, &x, &y, &nr, 0)
if data == nil {
	msg := C.GoString(C.stbi_failure_reason())
	return nil, int(x), int(y), int(nr), nil, errors.New(msg)
}
var fs []float32
head := (*reflect.SliceHeader)(unsafe.Pointer(&fs))
head.Cap = 1
head.Len = head.Cap
head.Data = uintptr(unsafe.Pointer(data))
return fs, int(x), int(y), int(nr), func() { C.stbi_image_free(unsafe.Pointer(data)) }, nil

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants