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 }
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 }
func runBlur(cmd *Command, args []string) { if _, ok := styleNames[blurStyle]; !ok { utils.Warn("--style must be one of 'clamp', 'ignore' or 'wrap'") os.Exit(2) } style, _ := styleNames[blurStyle] i := utils.ReadStdin() if blurBox { i = blur.Box(i, blurRadius, style) } else { i = blur.Gaussian(i, blurRadius, blurGaussian, style) } utils.WriteStdout(i) }
// 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 }