當前位置: 首頁>>代碼示例>>Golang>>正文


Golang C.vips_thread_shutdown函數代碼示例

本文整理匯總了Golang中C.vips_thread_shutdown函數的典型用法代碼示例。如果您正苦於以下問題:Golang vips_thread_shutdown函數的具體用法?Golang vips_thread_shutdown怎麽用?Golang vips_thread_shutdown使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了vips_thread_shutdown函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Metadata

// Metadata returns the image metadata (size, type, alpha channel, profile, EXIF orientation...).
func Metadata(buf []byte) (ImageMetadata, error) {
	defer C.vips_thread_shutdown()

	image, imageType, err := vipsRead(buf)
	if err != nil {
		return ImageMetadata{}, err
	}
	defer C.g_object_unref(C.gpointer(image))

	size := ImageSize{
		Width:  int(image.Xsize),
		Height: int(image.Ysize),
	}

	metadata := ImageMetadata{
		Size:        size,
		Channels:    int(image.Bands),
		Orientation: vipsExifOrientation(image),
		Alpha:       vipsHasAlpha(image),
		Profile:     vipsHasProfile(image),
		Space:       vipsSpace(image),
		Type:        ImageTypeName(imageType),
	}

	return metadata, nil
}
開發者ID:greut,項目名稱:bimg,代碼行數:27,代碼來源:metadata.go

示例2: Resize

func Resize(buf []byte, o Options) ([]byte, error) {
	debug("%#+v", o)

	// detect (if possible) the file type
	typ := UNKNOWN
	switch {
	case bytes.Equal(buf[:2], MARKER_JPEG):
		typ = JPEG
	case bytes.Equal(buf[:2], MARKER_PNG):
		typ = PNG
	default:
		return nil, errors.New("unknown image format")
	}

	// create an image instance
	var image, tmpImage *C.struct__VipsImage

	// feed it
	switch typ {
	case JPEG:
		C.vips_jpegload_buffer_seq(unsafe.Pointer(&buf[0]), C.size_t(len(buf)), &image)
	case PNG:
		C.vips_pngload_buffer_seq(unsafe.Pointer(&buf[0]), C.size_t(len(buf)), &image)
	}

	// cleanup
	defer func() {
		C.vips_thread_shutdown()
		C.vips_error_clear()
	}()

	// defaults
	if o.Quality == 0 {
		o.Quality = 100
	}

	// get WxH
	inWidth := int(image.Xsize)
	inHeight := int(image.Ysize)

	// prepare for factor
	factor := 0.0

	// image calculations
	switch {
	// Fixed width and height
	case o.Width > 0 && o.Height > 0:
		xf := float64(inWidth) / float64(o.Width)
		yf := float64(inHeight) / float64(o.Height)
		if o.Crop {
			factor = math.Min(xf, yf)
		} else {
			factor = math.Max(xf, yf)
		}
	// Fixed width, auto height
	case o.Width > 0:
		factor = float64(inWidth) / float64(o.Width)
		o.Height = int(math.Floor(float64(inHeight) / factor))
	// Fixed height, auto width
	case o.Height > 0:
		factor = float64(inHeight) / float64(o.Height)
		o.Width = int(math.Floor(float64(inWidth) / factor))
	// Identity transform
	default:
		factor = 1
		o.Width = inWidth
		o.Height = inHeight
	}

	debug("transform from %dx%d to %dx%d", inWidth, inHeight, o.Width, o.Height)

	// shrink
	shrink := int(math.Floor(factor))
	if shrink < 1 {
		shrink = 1
	}

	// residual
	residual := float64(shrink) / factor

	// Do not enlarge the output if the input width *or* height are already less than the required dimensions
	if !o.Enlarge {
		if inWidth < o.Width && inHeight < o.Height {
			factor = 1
			shrink = 1
			residual = 0
			o.Width = inWidth
			o.Height = inHeight
		}
	}

	debug("factor: %v, shrink: %v, residual: %v", factor, shrink, residual)

	// Try to use libjpeg shrink-on-load
	shrinkOnLoad := 1
	if typ == JPEG && shrink >= 2 {
		switch {
		case shrink >= 8:
			factor = factor / 8
			shrinkOnLoad = 8
//.........這裏部分代碼省略.........
開發者ID:opendoor-labs,項目名稱:gothumb,代碼行數:101,代碼來源:vips.go

示例3: catchVipsError

func catchVipsError() error {
	s := C.GoString(C.vips_error_buffer())
	C.vips_error_clear()
	C.vips_thread_shutdown()
	return errors.New(s)
}
開發者ID:godeep,項目名稱:bimg,代碼行數:6,代碼來源:vips.go

示例4: Resize

func Resize(buf []byte, o Options) ([]byte, error) {
	defer C.vips_thread_shutdown()

	if len(buf) == 0 {
		return nil, errors.New("Image buffer is empty")
	}

	image, imageType, err := vipsRead(buf)
	if err != nil {
		return nil, err
	}

	// Defaults
	if o.Quality == 0 {
		o.Quality = QUALITY
	}
	if o.Compression == 0 {
		o.Compression = 6
	}
	if o.Type == 0 {
		o.Type = imageType
	}

	if IsTypeSupported(o.Type) == false {
		return nil, errors.New("Unsupported image output type")
	}

	debug("Options: %#v", o)

	inWidth := int(image.Xsize)
	inHeight := int(image.Ysize)

	// image calculations
	factor := imageCalculations(&o, inWidth, inHeight)
	shrink := calculateShrink(factor, o.Interpolator)
	residual := calculateResidual(factor, shrink)

	// Do not enlarge the output if the input width *or* height are already less than the required dimensions
	if o.Enlarge == false {
		if inWidth < o.Width && inHeight < o.Height {
			factor = 1.0
			shrink = 1
			residual = 0
			o.Width = inWidth
			o.Height = inHeight
		}
	}

	// Try to use libjpeg shrink-on-load
	if imageType == JPEG && shrink >= 2 {
		tmpImage, factor, err := shrinkJpegImage(buf, image, factor, shrink)
		if err != nil {
			return nil, err
		}

		image = tmpImage
		factor = math.Max(factor, 1.0)
		shrink = int(math.Floor(factor))
		residual = float64(shrink) / factor
	}

	// Zoom image, if necessary
	image, err = zoomImage(image, o.Zoom)
	if err != nil {
		return nil, err
	}

	// Rotate / flip image, if necessary
	image, err = rotateAndFlipImage(image, o)
	if err != nil {
		return nil, err
	}

	// Transform image, if necessary
	transformImage := o.Width != inWidth || o.Height != inHeight || o.AreaWidth > 0 || o.AreaHeight > 0

	if transformImage {

		// Use vips_shrink with the integral reduction
		if shrink > 1 {
			image, residual, err = shrinkImage(image, o, residual, shrink)
			if err != nil {
				return nil, err
			}
		}

		debug("Transform: factor=%v, shrink=%v, residual=%v, interpolator=%v",
			factor, shrink, residual, o.Interpolator.String())

		// Affine with the remaining float part
		if residual != 0 {
			image, err = affineImage(image, o, residual)
			if err != nil {
				return nil, err
			}
		}

		// Extract area from image
		image, err = extractImage(image, o)
		if err != nil {
//.........這裏部分代碼省略.........
開發者ID:slav123,項目名稱:bimg,代碼行數:101,代碼來源:resize.go

示例5: Resize

func Resize(buf []byte, o Options) ([]byte, error) {
	defer C.vips_thread_shutdown()

	if len(buf) == 0 {
		return nil, errors.New("Image buffer is empty")
	}

	image, imageType, err := vipsRead(buf)
	if err != nil {
		return nil, err
	}

	// Define default options
	applyDefaults(&o, imageType)

	if IsTypeSupported(o.Type) == false {
		return nil, errors.New("Unsupported image output type")
	}

	debug("Options: %#v", o)

	inWidth := int(image.Xsize)
	inHeight := int(image.Ysize)

	// Infer the required operation based on the in/out image sizes for a coherent transformation
	normalizeOperation(&o, inWidth, inHeight)

	// image calculations
	factor := imageCalculations(&o, inWidth, inHeight)
	shrink := calculateShrink(factor, o.Interpolator)
	residual := calculateResidual(factor, shrink)

	// Do not enlarge the output if the input width or height
	// are already less than the required dimensions
	if !o.Enlarge && !o.Force {
		if inWidth < o.Width && inHeight < o.Height {
			factor = 1.0
			shrink = 1
			residual = 0
			o.Width = inWidth
			o.Height = inHeight
		}
	}

	// Try to use libjpeg shrink-on-load
	if imageType == JPEG && shrink >= 2 {
		tmpImage, factor, err := shrinkJpegImage(buf, image, factor, shrink)
		if err != nil {
			return nil, err
		}

		image = tmpImage
		factor = math.Max(factor, 1.0)
		shrink = int(math.Floor(factor))
		residual = float64(shrink) / factor
	}

	// Zoom image, if necessary
	image, err = zoomImage(image, o.Zoom)
	if err != nil {
		return nil, err
	}

	// Rotate / flip image, if necessary
	image, err = rotateAndFlipImage(image, o)
	if err != nil {
		return nil, err
	}

	// Transform image, if necessary
	if shouldTransformImage(o, inWidth, inHeight) {
		image, err = transformImage(image, o, shrink, residual)
		if err != nil {
			return nil, err
		}
	}

	// Add watermark, if necessary
	image, err = watermakImage(image, o.Watermark)
	if err != nil {
		return nil, err
	}

	saveOptions := vipsSaveOptions{
		Quality:        o.Quality,
		Type:           o.Type,
		Compression:    o.Compression,
		Interlace:      o.Interlace,
		NoProfile:      o.NoProfile,
		Interpretation: o.Interpretation,
	}

	// Finally get the resultant buffer
	buf, err = vipsSave(image, saveOptions)
	if err != nil {
		return nil, err
	}

	return buf, nil
}
開發者ID:chickenlove,項目名稱:bimg,代碼行數:100,代碼來源:resize.go

示例6: ThreadShutdown

// ThreadShutdown frees any thread-private data and flushes any profiling
// information.  This function needs to be called when a thread that has
// been using vips exits or there will be memory leaks.  It may be called
// many times, and you can continue using vips after calling it.  Calling it
// too often will reduce performance.
func ThreadShutdown() {
	C.vips_thread_shutdown()
}
開發者ID:kitwalker12,項目名稱:fotomat,代碼行數:8,代碼來源:init.go

示例7: AutoRotate

func AutoRotate(file string, o Options) ([]byte, error) {
	debug("%#+v", o)

	// detect (if possible) the file type
	/*typ := UNKNOWN
	   	switch {
	   	case bytes.Equal(buf[:2], MARKER_JPEG):
	   		typ = JPEG
	   	case bytes.Equal(buf[:2], MARKER_PNG):
	   		typ = PNG
	   	default:
	   		return nil, errors.New("unknown image format")
	   	}

	   	// create an image instance
	   	var image, tmpImage *C.struct__VipsImage

		// feed it
	   	switch typ {
	   	case JPEG:
	   		C.vips_jpegload_buffer_seq(unsafe.Pointer(&buf[0]), C.size_t(len(buf)), &image)
	   	case PNG:
	   		C.vips_pngload_buffer_seq(unsafe.Pointer(&buf[0]), C.size_t(len(buf)), &image)
	   	}*/
	// create an image instance
	var image, tmpImage *C.struct__VipsImage

	image = C.vips_load_from_file(C.CString(file))

	// cleanup
	defer func() {
		C.vips_thread_shutdown()
		C.vips_error_clear()
	}()

	if image == nil {
		return nil, catchVipsError()
	}

	rotate, flip := calculateRotationAndFlip(image, 0)

	if rotate == 0 && !flip {
		return nil, nil //Remain unchanged
	}

	ret := C.vips_autorotate(image, &tmpImage)

	if ret != 0 {
		return nil, catchVipsError()
	}

	if o.Quality == 0 {
		o.Quality = 100
	}

	length := C.size_t(0)
	var ptr unsafe.Pointer

	switch o.Savetype {
	case WEBP:
		C.vips_webpsave_custom(tmpImage, &ptr, &length, C.int(o.Quality))
	case PNG:
		C.vips_pngsave_custom(tmpImage, &ptr, &length, 1, C.int(o.Quality), 0)
	default:
		C.vips_jpegsave_custom(tmpImage, &ptr, &length, 1, C.int(o.Quality), 0)
	}

	C.g_object_unref(C.gpointer(tmpImage))

	// get back the buffer
	var buf []byte
	buf = C.GoBytes(ptr, C.int(length))
	C.g_free(C.gpointer(ptr))
	return buf, nil
}
開發者ID:julianshen,項目名稱:vips,代碼行數:75,代碼來源:vips.go


注:本文中的C.vips_thread_shutdown函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。