Ejemplo n.º 1
0
// ChannelDepth returns the depth of the given channel.
func (im *Image) ChannelDepth(ch Channel) (uint, error) {
	var ex C.ExceptionInfo
	C.GetExceptionInfo(&ex)
	defer C.DestroyExceptionInfo(&ex)
	ret := C.GetImageChannelDepth(im.image, C.ChannelType(ch), &ex)
	if ex.severity != C.UndefinedException {
		return 0, exError(&ex, "getting channel info")
	}
	return uint(ret), nil
}
Ejemplo n.º 2
0
// Sharpens an image. We convolve the image with a Gaussian operator of the
// given radius and standard deviation (sigma). For reasonable results, the
// radius should be larger than sigma.
// Use a radius of 0 and selects a suitable radius for you.
// You can pass 0 as channel number - to use default channels
func (self *Canvas) SharpenImage(radius float32, sigma float32, channel int) error {
	if channel == 0 {
		channel = C.DefaultChannels
	}

	success := C.MagickSharpenImageChannel(self.wand, C.ChannelType(channel), C.double(radius), C.double(sigma))
	if success == C.MagickFalse {
		return fmt.Errorf("Could not resize: %s", self.Error())
	}

	return nil
}
Ejemplo n.º 3
0
func (im *Image) importChannel(src *Image, ch Channel) error {
	C.ImportImageChannel(src.image, im.image, C.ChannelType(ch))
	return nil
}
Ejemplo n.º 4
0
func (im *Image) toChannel(ch Channel) error {
	if C.ChannelImage(im.image, C.ChannelType(ch)) == 0 {
		return errors.New("error extracting channel")
	}
	return nil
}
Ejemplo n.º 5
0
// SetChannelDepth sets the depth of the channel. The range
// of depth is 1 to QuantumDepth.
func (im *Image) SetChannelDepth(ch Channel, depth uint) error {
	if C.SetImageChannelDepth(im.image, C.ChannelType(ch), magickUint(depth)) == 0 {
		return errors.New("error setting channel")
	}
	return nil
}
Ejemplo n.º 6
0
func (im *Image) operateChannel(op Operator, ch Channel, value float64) error {
	var cop C.QuantumOperator
	switch op {
	case OpAdd:
		cop = C.AddQuantumOp
	case OpAnd:
		cop = C.AndQuantumOp
	case OpAssign:
		cop = C.AssignQuantumOp
	case OpDepth:
		cop = C.DepthQuantumOp
	case OpDivide:
		cop = C.DivideQuantumOp
	case OpGamma:
		cop = C.GammaQuantumOp
	case OpLog:
		cop = C.LogQuantumOp
	case OpLShift:
		cop = C.LShiftQuantumOp
	case OpMax:
		cop = C.MaxQuantumOp
	case OpMin:
		cop = C.MinQuantumOp
	case OpMultiply:
		cop = C.MultiplyQuantumOp
	case OpGaussianNoise:
		cop = C.GammaQuantumOp
	case OpImpulseNoise:
		cop = C.NoiseImpulseQuantumOp
	case OpLaplacianNoise:
		cop = C.NoiseLaplacianQuantumOp
	case OpMultiplicativeNoise:
		cop = C.NoiseMultiplicativeQuantumOp
	case OpPoissonNoise:
		cop = C.NoisePoissonQuantumOp
	case OpRandomNoise:
		cop = C.NoiseRandomQuantumOp
	case OpUniformNoise:
		cop = C.NoisePoissonQuantumOp
	case OpOr:
		cop = C.OrQuantumOp
	case OpPow:
		cop = C.PowQuantumOp
	case OpRShift:
		cop = C.RShiftQuantumOp
	case OpSubstract:
		cop = C.SubtractQuantumOp
	case OpThresholdBlack:
		cop = C.ThresholdBlackQuantumOp
	case OpThreshold:
		cop = C.ThresholdQuantumOp
	case OpThresholdWhite:
		cop = C.ThresholdWhiteQuantumOp
	case OpXor:
		cop = C.XorQuantumOp
	default:
		return notImplementedError(fmt.Sprintf("operator %s", op))
	}
	var ex C.ExceptionInfo
	C.GetExceptionInfo(&ex)
	defer C.DestroyExceptionInfo(&ex)
	if C.QuantumOperatorImage(im.image, C.ChannelType(ch), cop, C.double(value), &ex) != C.MagickTrue {
		return exError(&ex, "operating")
	}
	return nil
}
Ejemplo n.º 7
0
func (im *Image) toChannel(ch Channel) error {
	if C.SeparateImageChannel(im.image, C.ChannelType(ch)) == 0 {
		return errors.New("could no extract channel")
	}
	return nil
}