diff options
author | Christopher Speller <crspeller@gmail.com> | 2018-04-16 05:37:14 -0700 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2018-04-16 08:37:14 -0400 |
commit | 6e2cb00008cbf09e556b00f87603797fcaa47e09 (patch) | |
tree | 3c0eb55ff4226a3f024aad373140d1fb860a6404 /vendor/github.com/disintegration/imaging/histogram.go | |
parent | bf24f51c4e1cc6286885460672f7f449e8c6f5ef (diff) | |
download | chat-6e2cb00008cbf09e556b00f87603797fcaa47e09.tar.gz chat-6e2cb00008cbf09e556b00f87603797fcaa47e09.tar.bz2 chat-6e2cb00008cbf09e556b00f87603797fcaa47e09.zip |
Depenancy upgrades and movign to dep. (#8630)
Diffstat (limited to 'vendor/github.com/disintegration/imaging/histogram.go')
-rw-r--r-- | vendor/github.com/disintegration/imaging/histogram.go | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/vendor/github.com/disintegration/imaging/histogram.go b/vendor/github.com/disintegration/imaging/histogram.go index 967ee6a25..5bcb001ca 100644 --- a/vendor/github.com/disintegration/imaging/histogram.go +++ b/vendor/github.com/disintegration/imaging/histogram.go @@ -2,6 +2,7 @@ package imaging import ( "image" + "sync" ) // Histogram returns a normalized histogram of an image. @@ -9,35 +10,42 @@ import ( // 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 mu sync.Mutex var histogram [256]float64 var total float64 - if width == 0 || height == 0 { + src := newScanner(img) + if src.w == 0 || src.h == 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] - - y := 0.299*float32(r) + 0.587*float32(g) + 0.114*float32(b) - - histogram[int(y+0.5)]++ - total++ + parallel(0, src.h, func(ys <-chan int) { + var tmpHistogram [256]float64 + var tmpTotal float64 + scanLine := make([]uint8, src.w*4) + for y := range ys { + src.scan(0, y, src.w, y+1, scanLine) + i := 0 + for x := 0; x < src.w; x++ { + r := scanLine[i+0] + g := scanLine[i+1] + b := scanLine[i+2] + y := 0.299*float32(r) + 0.587*float32(g) + 0.114*float32(b) + tmpHistogram[int(y+0.5)]++ + tmpTotal++ + i += 4 + } } - } + mu.Lock() + for i := 0; i < 256; i++ { + histogram[i] += tmpHistogram[i] + } + total += tmpTotal + mu.Unlock() + }) for i := 0; i < 256; i++ { histogram[i] = histogram[i] / total } - return histogram } |