diff options
author | hmhealey <harrisonmhealey@gmail.com> | 2015-09-17 11:08:47 -0400 |
---|---|---|
committer | hmhealey <harrisonmhealey@gmail.com> | 2015-09-17 19:13:42 -0400 |
commit | d83be6df2d8b0e2fef4cb6866cfdb6434bbef5c4 (patch) | |
tree | a4677163f2aa762c75988fe402b9aea89d95e0be /Godeps/_workspace/src/code.google.com/p/graphics-go/graphics/blur.go | |
parent | 82127341cacd4299f9a59e76b5f68d6d7222c45b (diff) | |
download | chat-d83be6df2d8b0e2fef4cb6866cfdb6434bbef5c4.tar.gz chat-d83be6df2d8b0e2fef4cb6866cfdb6434bbef5c4.tar.bz2 chat-d83be6df2d8b0e2fef4cb6866cfdb6434bbef5c4.zip |
PLT-173 Added graphics-go and goexif libraries for image manipulation
Diffstat (limited to 'Godeps/_workspace/src/code.google.com/p/graphics-go/graphics/blur.go')
-rw-r--r-- | Godeps/_workspace/src/code.google.com/p/graphics-go/graphics/blur.go | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/Godeps/_workspace/src/code.google.com/p/graphics-go/graphics/blur.go b/Godeps/_workspace/src/code.google.com/p/graphics-go/graphics/blur.go new file mode 100644 index 000000000..9a54d5ad5 --- /dev/null +++ b/Godeps/_workspace/src/code.google.com/p/graphics-go/graphics/blur.go @@ -0,0 +1,68 @@ +// Copyright 2011 The Graphics-Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package graphics + +import ( + "code.google.com/p/graphics-go/graphics/convolve" + "errors" + "image" + "image/draw" + "math" +) + +// DefaultStdDev is the default blurring parameter. +var DefaultStdDev = 0.5 + +// BlurOptions are the blurring parameters. +// StdDev is the standard deviation of the normal, higher is blurrier. +// Size is the size of the kernel. If zero, it is set to Ceil(6 * StdDev). +type BlurOptions struct { + StdDev float64 + Size int +} + +// Blur produces a blurred version of the image, using a Gaussian blur. +func Blur(dst draw.Image, src image.Image, opt *BlurOptions) error { + if dst == nil { + return errors.New("graphics: dst is nil") + } + if src == nil { + return errors.New("graphics: src is nil") + } + + sd := DefaultStdDev + size := 0 + + if opt != nil { + sd = opt.StdDev + size = opt.Size + } + + if size < 1 { + size = int(math.Ceil(sd * 6)) + } + + kernel := make([]float64, 2*size+1) + for i := 0; i <= size; i++ { + x := float64(i) / sd + x = math.Pow(1/math.SqrtE, x*x) + kernel[size-i] = x + kernel[size+i] = x + } + + // Normalize the weights to sum to 1.0. + kSum := 0.0 + for _, k := range kernel { + kSum += k + } + for i, k := range kernel { + kernel[i] = k / kSum + } + + return convolve.Convolve(dst, src, &convolve.SeparableKernel{ + X: kernel, + Y: kernel, + }) +} |