From e4c1fbf49082c091daf022b5157e7ef81ebf6cff Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 20 Nov 2016 13:51:48 +1300 Subject: [PATCH] PoC CGO wrapper and sample command-line utility --- .hgignore | 3 +++ cmd/gopngquant/main.go | 20 ++++++++++++++++++++ imagequant.go | 14 ++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 .hgignore create mode 100644 cmd/gopngquant/main.go create mode 100644 imagequant.go diff --git a/.hgignore b/.hgignore new file mode 100644 index 0000000..eb8f9e6 --- /dev/null +++ b/.hgignore @@ -0,0 +1,3 @@ +mode:regex + +\.exe$ diff --git a/cmd/gopngquant/main.go b/cmd/gopngquant/main.go new file mode 100644 index 0000000..183a77c --- /dev/null +++ b/cmd/gopngquant/main.go @@ -0,0 +1,20 @@ +package main + +import ( + "flag" + "fmt" + "os" + + "code.ivysaur.me/imagequant" +) + +func main() { + ShouldDisplayVersion := flag.Bool("Version", false, "") + + flag.Parse() + + if *ShouldDisplayVersion { + fmt.Printf("libimagequant %d\n", imagequant.GetLibraryVersion()) + os.Exit(1) + } +} diff --git a/imagequant.go b/imagequant.go new file mode 100644 index 0000000..39dac20 --- /dev/null +++ b/imagequant.go @@ -0,0 +1,14 @@ +package imagequant + +/* +#cgo CFLAGS: -O3 -fno-math-errno -fopenmp -funroll-loops -fomit-frame-pointer -Wall -Wno-attributes -std=c99 -DNDEBUG -DUSE_SSE=1 -msse -fexcess-precision=fast +#cgo LDFLAGS: -fopenmp -static +#include "libimagequant.h" +*/ +import ( + "C" +) + +func GetLibraryVersion() int { + return int(C.liq_version()) +}