go-libwebp

Experimental translation from libwebp to Go source.
Log | Files | Refs | README | LICENSE

commit 09329a8ab82ad1a5948b0115d7d71218c2c6267c
parent 8000e873f42d591bd04c69a3479ee4f467eda880
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date:   Sat, 29 Jan 2022 19:31:28 +0800

webp: free out buffer

Signed-off-by: Jack Mordaunt <jackmordaunt.dev@gmail.com>

Diffstat:
Mwebp/encode.go | 7+++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/webp/encode.go b/webp/encode.go @@ -4,7 +4,6 @@ import ( "fmt" "image" "io" - "runtime" "unsafe" "git.sr.ht/~jackmordaunt/go-libwebp/lib" @@ -49,8 +48,6 @@ type Encoder struct { // Encode specified image as webp to w. func (enc *Encoder) Encode(w io.Writer, m image.Image) error { - runtime.LockOSThread() - defer runtime.UnlockOSThread() if enc.Quality <= 0.0 || enc.Quality > 1 { enc.Quality = 1.0 } @@ -62,11 +59,12 @@ func (enc *Encoder) Encode(w io.Writer, m image.Image) error { } } var ( + tls = libc.NewTLS() // out buffer to contain webp data. out *byte = nil ) size := lib.Encode( - libc.NewTLS(), + tls, uintptr(unsafe.Pointer(&rgbaImage.Pix[0])), int32(rect.Dx()), int32(rect.Dy()), @@ -85,6 +83,7 @@ func (enc *Encoder) Encode(w io.Writer, m image.Image) error { boolToInt32(enc.Lossless), uintptr(unsafe.Pointer(&out)), ) + defer lib.WebPFree(tls, uintptr(unsafe.Pointer(out))) if size == 0 { return fmt.Errorf("encoding webp image: size %d", size) }