refactor(vips)

master
Tomas Aparicio 11 years ago
parent cfb218cd19
commit 6904c9a061

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

Loading…
Cancel
Save