|
|
|
|
@ -10,9 +10,15 @@ import (
|
|
|
|
|
"errors"
|
|
|
|
|
"runtime"
|
|
|
|
|
"strings"
|
|
|
|
|
"sync"
|
|
|
|
|
"unsafe"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
initialized bool = false
|
|
|
|
|
m sync.Mutex
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type vipsImage C.struct__VipsImage
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
@ -23,19 +29,30 @@ func init() {
|
|
|
|
|
panic("unsupported old vips version")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Initialize()
|
|
|
|
|
|
|
|
|
|
C.vips_concurrency_set(0) // single-thread
|
|
|
|
|
C.vips_cache_set_max_mem(100 * 1024 * 1024) // 100 MB
|
|
|
|
|
C.vips_cache_set_max(500) // 500 operations
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Initialize() {
|
|
|
|
|
err := C.vips_init(C.CString("bimg"))
|
|
|
|
|
if err != 0 {
|
|
|
|
|
C.vips_shutdown()
|
|
|
|
|
Shutdown()
|
|
|
|
|
panic("unable to start vips!")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
C.vips_concurrency_set(1) // single-thread
|
|
|
|
|
C.vips_cache_set_max_mem(100 * 1024 * 1024) // 100 MB
|
|
|
|
|
C.vips_cache_set_max(500) // 500 operations
|
|
|
|
|
m.Lock()
|
|
|
|
|
defer m.Unlock()
|
|
|
|
|
initialized = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Vips struct {
|
|
|
|
|
buf []byte
|
|
|
|
|
func Shutdown() {
|
|
|
|
|
m.Lock()
|
|
|
|
|
defer m.Unlock()
|
|
|
|
|
C.vips_shutdown()
|
|
|
|
|
initialized = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func vipsRotate(image *C.struct__VipsImage, angle Angle) (*C.struct__VipsImage, error) {
|
|
|
|
|
|