Example #1
0
File: blur.go Project: hawx/img
func runBlur(cmd *hadfield.Command, args []string) {
	var style blur.Style

	switch blurStyle {
	case "clamp":
		style = blur.CLAMP
	case "ignore":
		style = blur.IGNORE
	case "wrap":
		style = blur.WRAP
	default:
		utils.Warn("--style must be one of 'clamp', 'ignore' or 'wrap'")
		os.Exit(2)
	}

	i, data := utils.ReadStdin()

	if blurBox {
		i = blur.Box(i, blurRadius, style)
	} else {
		i = blur.Gaussian(i, blurRadius, blurGaussian, style)
	}

	utils.WriteStdout(i, data)
}
Example #2
0
File: blur.go Project: hawx/img
func NewVerticalKernel(height int, f func(y int) float64) Kernel {
	if !correct(height) {
		utils.Warn("Error: kernel size wrong!")
		os.Exit(2)
	}

	my := (height - 1) / 2
	k := make([][]float64, height)

	for y := 0; y < height; y++ {
		k[y] = []float64{f(my - y)}
	}

	return k
}
Example #3
0
File: blur.go Project: hawx/img
func NewHorizontalKernel(width int, f func(x int) float64) Kernel {
	if !correct(width) {
		utils.Warn("Error: kernel size wrong!")
		os.Exit(2)
	}

	mx := (width - 1) / 2
	k := [][]float64{make([]float64, width)}

	for x := 0; x < width; x++ {
		k[0][x] = f(mx - x)
	}

	return k
}
Example #4
0
File: blur.go Project: hawx/img
// NewKernel creates a new Kernel of the dimensions given, it is populated by
// the given function which itself is passed the signed x and y offsets from the
// mid point.
func NewKernel(height, width int, f func(x, y int) float64) Kernel {
	if !correct(width) || !correct(height) {
		utils.Warn("Error: kernel size wrong!")
		os.Exit(2)
		// should return error really!
	}

	mx := (width - 1) / 2
	my := (height - 1) / 2
	k := make([][]float64, height)

	for y := 0; y < height; y++ {
		k[y] = make([]float64, width)
		for x := 0; x < width; x++ {
			k[y][x] = f(mx-x, my-y)
		}
	}

	return k
}