Exemple #1
0
// ResizeBlur returns a new image resized to the given dimensions using the provided
// filter and blur factor (where > 1 is blurry, < 1 is sharp). If width or height is
// < 0, it's calculated proportionally to the other dimension. If both of them are < 0,
// an error is returned.
func (im *Image) ResizeBlur(width, height int, filter Filter, blur float64) (*Image, error) {
	var data C.ResizeData
	if width < 0 {
		if height < 0 {
			return nil, fmt.Errorf("invalid resize %dx%d", width, height)
		}
		h := float64(im.Height())
		var ratio float64
		if h != 0 {
			ratio = float64(im.Width()) / h
		}
		width = int(float64(height) * ratio)
	}
	if height < 0 {
		if width < 0 {
			return nil, fmt.Errorf("invalid resize %dx%d", width, height)
		}
		var ratio float64
		w := float64(im.Width())
		if w != 0 {
			ratio = float64(im.Height()) / w
		}
		height = int(float64(width) * ratio)
	}
	data.columns = C.ulong(width)
	data.rows = C.ulong(height)
	data.filter = C.FilterTypes(filter)
	data.blur = C.double(blur)
	return im.applyDataFunc("resizing", C.ImageDataFunc(C.resizeImage), &data)
}
Exemple #2
0
// Composite modifies the image, drawing the draw Image argument at offset
// (x, y) using the c Composite operation.
func (im *Image) Composite(c Composite, draw *Image, x int, y int) error {
	op, err := im.compositeOperator(c)
	if err != nil {
		return err
	}
	var ex C.ExceptionInfo
	C.GetExceptionInfo(&ex)
	defer C.DestroyExceptionInfo(&ex)
	var data C.CompositeData
	data.composite = C.int(op)
	data.draw = draw.image
	data.x = C.int(x)
	data.y = C.int(y)
	res, err := im.applyDataFunc("compositing", C.ImageDataFunc(C.compositeImage), &data)
	// res.image will be != than im.image when im is a non
	// coalesced animation
	if res.image != im.image {
		unrefImages(im.image)
		initializeRefCounts(res.image)
		refImages(res.image)
		im.image = res.image
		dontFree(res)
	}
	return err
}
Exemple #3
0
// ResizeBlur returns a new image resized to the given dimensions using the provided
// filter and blur factor (where > 1 is blurry, < 1 is sharp).
func (im *Image) ResizeBlur(width, height int, filter Filter, blur float64) (*Image, error) {
	var data C.ResizeData
	data.columns = C.ulong(width)
	data.rows = C.ulong(height)
	data.filter = C.FilterTypes(filter)
	data.blur = C.double(blur)
	return im.applyDataFunc("resizing", C.ImageDataFunc(C.resizeImage), &data)
}
Exemple #4
0
// Composite modifies the image, drawing the draw Image argument at offset
// (x, y) using the c Composite operation.
func (im *Image) Composite(c Composite, draw *Image, x int, y int) error {
	op, err := im.compositeOperator(c)
	if err != nil {
		return err
	}
	var ex C.ExceptionInfo
	C.GetExceptionInfo(&ex)
	defer C.DestroyExceptionInfo(&ex)
	var data C.CompositeData
	data.composite = C.int(op)
	data.draw = draw.image
	data.x = C.int(x)
	data.y = C.int(y)
	_, err = im.applyDataFunc("compositing", C.ImageDataFunc(C.compositeImage), &data)
	return err
}
Exemple #5
0
// Convolve applies the given convolution kernel to the image. The
// order parameter must be a non-negative odd number, while the kernel
// parameter must have either order*order elements or just one element
// (in the latter case, it's interpreted as having all elements set to
// that first value).
func (im *Image) Convolve(order int, kernel []float64) (*Image, error) {
	count := order * order
	if len(kernel) < count {
		if len(kernel) != 1 {
			return nil, fmt.Errorf("kernel for order %d must have %d or %d elements, not %d", order, count, 1, len(kernel))
		}
		newKernel := make([]float64, count)
		for ii := range newKernel {
			newKernel[ii] = kernel[0]
		}
		kernel = newKernel
	}
	var data C.ConvolveData
	data.order = C.int(order)
	data.kernel = (*C.double)(unsafe.Pointer(&kernel[0]))
	return im.applyDataFunc("convolving", C.ImageDataFunc(C.convolveImage), &data)
}
Exemple #6
0
// Thumbnail changes the size of an image to the given dimensions. This
// method was designed by Bob Friesenhahn as a low cost thumbnail generator.
func (im *Image) Thumbnail(width, height int) (*Image, error) {
	return im.sizeFunc("thumbnailing", width, height, C.ImageDataFunc(C.thumbnailImage))
}
Exemple #7
0
// Scale changes the size of an image to the given dimensions.
func (im *Image) Scale(width, height int) (*Image, error) {
	return im.sizeFunc("scaling", width, height, C.ImageDataFunc(C.scaleImage))
}
Exemple #8
0
func (im *Image) Shave(r Rect) (*Image, error) {
	return im.applyRectFunc("shaving", C.ImageDataFunc(C.ShaveImage), r)
}
Exemple #9
0
func (im *Image) Extent(r Rect) (*Image, error) {
	return im.applyRectFunc("extenting", C.ImageDataFunc(C.ExtentImage), r)
}
Exemple #10
0
func (im *Image) Crop(r Rect) (*Image, error) {
	return im.applyRectFunc("cropping", C.ImageDataFunc(C.CropImage), r)
}
Exemple #11
0
func (im *Image) transformColorspace(cs Colorspace) (*Image, error) {
	return im.applyDataFunc("transforming-colorspace", C.ImageDataFunc(C.transformImageColorspace), &cs)
}
Exemple #12
0
// AffineTransform returns a new image created by transforming
// the original image as dictated by the affine matrix.
func (im *Image) AffineTransform(m *Matrix) (*Image, error) {
	return im.applyDataFunc("transforming (affine)", C.ImageDataFunc(C.AffineTransformImage), m.matrix())
}