mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-08 23:18:19 -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"
|
||||
"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")
|
||||
}
|
||||
|
||||
err := C.vips_init(C.CString("bimg"))
|
||||
if err != 0 {
|
||||
C.vips_shutdown()
|
||||
panic("unable to start vips!")
|
||||
}
|
||||
Initialize()
|
||||
|
||||
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(500) // 500 operations
|
||||
}
|
||||
|
||||
type Vips struct {
|
||||
buf []byte
|
||||
func Initialize() {
|
||||
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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue