go-libwebp

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

commit 75195ca41678d8ff1d21aafe03b0dec5bdd03f7e
parent 3bdb8c52844faed6a2cef991282bb0a2dfaaca1b
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date:   Thu,  7 Mar 2024 15:24:39 +0800

lib/dynamic/webp: allow generic naming

Allow for arch delineated naming and generic naming.

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

Diffstat:
Mlib/dynamic/webp/lib.go | 18+++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/lib/dynamic/webp/lib.go b/lib/dynamic/webp/lib.go @@ -4,6 +4,7 @@ import ( "fmt" "image" "io" + "runtime" "git.sr.ht/~jackmordaunt/go-libwebp/lib/common" "github.com/ebitengine/purego" @@ -18,12 +19,23 @@ var ( WebPFree func(ptr uintptr) ) +func genericLibraryName() string { + switch runtime.GOOS { + case "windows": + return "libwebp.dll" + case "darwin": + return "libwebp.dylib" + default: + return "libwebp.so" + } +} + func loadLibrary() (uintptr, error) { handle, err := dlopen(libraryName) if err != nil { - return 0, fmt.Errorf("loading library: %w", err) + handle, err = dlopen(genericLibraryName()) } - return handle, nil + return handle, err } func Init() (err error) { @@ -33,7 +45,7 @@ func Init() (err error) { _libwebp, err = loadLibrary() if err != nil { - return err + return fmt.Errorf("loading library: %w", err) } purego.RegisterLibFunc(&WebPEncodeLosslessRGBA, _libwebp, "WebPEncodeLosslessRGBA")