summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/disintegration/imaging/histogram.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2017-02-02 09:32:00 -0500
committerHarrison Healey <harrisonmhealey@gmail.com>2017-02-02 09:32:00 -0500
commit701d1ab638b23c24877fc41824add66232446676 (patch)
treeec120c88d38ac9d38d9eabdd3270b52bb6ac9d96 /vendor/github.com/disintegration/imaging/histogram.go
parentca3211bc04f6dea34e8168217182637d1419f998 (diff)
downloadchat-701d1ab638b23c24877fc41824add66232446676.tar.gz
chat-701d1ab638b23c24877fc41824add66232446676.tar.bz2
chat-701d1ab638b23c24877fc41824add66232446676.zip
Updating server dependancies (#5249)
Diffstat (limited to 'vendor/github.com/disintegration/imaging/histogram.go')
-rw-r--r--vendor/github.com/disintegration/imaging/histogram.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/vendor/github.com/disintegration/imaging/histogram.go b/vendor/github.com/disintegration/imaging/histogram.go
new file mode 100644
index 000000000..aef333822
--- /dev/null
+++ b/vendor/github.com/disintegration/imaging/histogram.go
@@ -0,0 +1,43 @@
+package imaging
+
+import (
+ "image"
+)
+
+// Histogram returns a normalized histogram of an image.
+//
+// Resulting histogram is represented as an array of 256 floats, where
+// histogram[i] is a probability of a pixel being of a particular luminance i.
+func Histogram(img image.Image) [256]float64 {
+ src := toNRGBA(img)
+ width := src.Bounds().Max.X
+ height := src.Bounds().Max.Y
+
+ var histogram [256]float64
+ var total float64
+
+ if width == 0 || height == 0 {
+ return histogram
+ }
+
+ for y := 0; y < height; y++ {
+ for x := 0; x < width; x++ {
+ i := y*src.Stride + x*4
+
+ r := src.Pix[i+0]
+ g := src.Pix[i+1]
+ b := src.Pix[i+2]
+
+ var y float32 = 0.299*float32(r) + 0.587*float32(g) + 0.114*float32(b)
+
+ histogram[int(y+0.5)]++
+ total++
+ }
+ }
+
+ for i := 0; i < 256; i++ {
+ histogram[i] = histogram[i] / total
+ }
+
+ return histogram
+}