diff options
author | 2024-08-31 08:41:38 +0000 | |
---|---|---|
committer | 2024-08-31 10:41:38 +0200 | |
commit | 0a1555521d8579b6971f408d298b201c8fd59140 (patch) | |
tree | d1179eb3c223c2989d1e6cd088e3da7ec3a5980b /vendor/github.com/disintegration/imaging/histogram.go | |
parent | [chore] Close copied request body in SignDelivery (#3254) (diff) | |
download | gotosocial-0a1555521d8579b6971f408d298b201c8fd59140.tar.xz |
[performance] use single-threaded image transforms (#3252)
* use single-threaded image resizing in native code so we have more control over goroutines
* implement parallel-free versions of image transform functions also
* remove debug code
Diffstat (limited to 'vendor/github.com/disintegration/imaging/histogram.go')
-rw-r--r-- | vendor/github.com/disintegration/imaging/histogram.go | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/vendor/github.com/disintegration/imaging/histogram.go b/vendor/github.com/disintegration/imaging/histogram.go deleted file mode 100644 index c547fe822..000000000 --- a/vendor/github.com/disintegration/imaging/histogram.go +++ /dev/null @@ -1,52 +0,0 @@ -package imaging - -import ( - "image" - "sync" -) - -// 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 { - var mu sync.Mutex - var histogram [256]float64 - var total float64 - - src := newScanner(img) - if src.w == 0 || src.h == 0 { - return histogram - } - - 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++ { - s := scanLine[i : i+3 : i+3] - r := s[0] - g := s[1] - b := s[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 -} |