mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-19 04:06:32 -07:00
refactor(vips)
This commit is contained in:
parent
cfb218cd19
commit
6904c9a061
1 changed files with 25 additions and 8 deletions
33
vips.go
33
vips.go
|
|
@ -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")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := C.vips_init(C.CString("bimg"))
|
Initialize()
|
||||||
if err != 0 {
|
|
||||||
C.vips_shutdown()
|
|
||||||
panic("unable to start vips!")
|
|
||||||
}
|
|
||||||
|
|
||||||
C.vips_concurrency_set(1) // single-thread
|
C.vips_concurrency_set(0) // single-thread
|
||||||
C.vips_cache_set_max_mem(100 * 1024 * 1024) // 100 MB
|
C.vips_cache_set_max_mem(100 * 1024 * 1024) // 100 MB
|
||||||
C.vips_cache_set_max(500) // 500 operations
|
C.vips_cache_set_max(500) // 500 operations
|
||||||
}
|
}
|
||||||
|
|
||||||
type Vips struct {
|
func Initialize() {
|
||||||
buf []byte
|
err := C.vips_init(C.CString("bimg"))
|
||||||
|
if err != 0 {
|
||||||
|
Shutdown()
|
||||||
|
panic("unable to start vips!")
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Lock()
|
||||||
|
defer m.Unlock()
|
||||||
|
initialized = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func Shutdown() {
|
||||||
|
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…
Add table
Add a link
Reference in a new issue