Esempio n. 1
0
File: vips.go Progetto: godeep/bimg
// Explicit thread-safe start of libvips.
// Only call this function if you've previously shutdown libvips
func Initialize() {
	if C.VIPS_MAJOR_VERSION <= 7 && C.VIPS_MINOR_VERSION < 40 {
		panic("unsupported libvips version!")
	}

	m.Lock()
	runtime.LockOSThread()
	defer m.Unlock()
	defer runtime.UnlockOSThread()

	err := C.vips_init(C.CString("bimg"))
	if err != 0 {
		panic("unable to start vips!")
	}

	// Set libvips cache params
	C.vips_cache_set_max_mem(maxCacheMem)
	C.vips_cache_set_max(maxCacheSize)

	// Define a custom thread concurrency limit in libvips (this may generate thread-unsafe issues)
	// See: https://github.com/jcupitt/libvips/issues/261#issuecomment-92850414
	if os.Getenv("VIPS_CONCURRENCY") == "" {
		C.vips_concurrency_set(1)
	}

	// Enable libvips cache tracing
	if os.Getenv("VIPS_TRACE") != "" {
		C.vips_enable_cache_set_trace()
	}

	initialized = true
}
Esempio n. 2
0
func init() {
	runtime.LockOSThread()
	defer runtime.UnlockOSThread()
	err := C.vips_initialize()
	if err != 0 {
		C.vips_shutdown()
		panic("unable to start vips!")
	}
	C.vips_concurrency_set(1)
	C.vips_cache_set_max_mem(100 * 1048576) // 100Mb
	C.vips_cache_set_max(500)
}
Esempio n. 3
0
// Initialize starts up the world of VIPS. You should call this on program
// startup before using any other VIPS operations.
func Initialize() {
	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	_ = os.Setenv("VIPS_WARNING", "disable")

	if err := C.cgo_vips_init(); err != 0 {
		C.vips_shutdown()
		panic("vips_initialize error")
	}

	C.vips_concurrency_set(1)
	C.vips_cache_set_max_mem(0)
	C.vips_cache_set_max(0)

	// Vips 8.3 sometimes produces 1px smaller images than desired without rounding help.
	if C.VIPS_MAJOR_VERSION == 8 && C.VIPS_MINOR_VERSION < 4 {
		ResizeOffset = 0.5
	}
}