From 6e2cb00008cbf09e556b00f87603797fcaa47e09 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Mon, 16 Apr 2018 05:37:14 -0700 Subject: Depenancy upgrades and movign to dep. (#8630) --- vendor/github.com/disintegration/imaging/utils.go | 88 +++++++++++++---------- 1 file changed, 50 insertions(+), 38 deletions(-) (limited to 'vendor/github.com/disintegration/imaging/utils.go') diff --git a/vendor/github.com/disintegration/imaging/utils.go b/vendor/github.com/disintegration/imaging/utils.go index 9f5926aaa..3b6ad2e49 100644 --- a/vendor/github.com/disintegration/imaging/utils.go +++ b/vendor/github.com/disintegration/imaging/utils.go @@ -1,53 +1,38 @@ package imaging import ( + "image" "runtime" "sync" - "sync/atomic" ) -// parallel starts parallel image processing based on the current GOMAXPROCS value. -// If GOMAXPROCS = 1 it uses no parallelization. -// If GOMAXPROCS > 1 it spawns N=GOMAXPROCS workers in separate goroutines. -func parallel(dataSize int, fn func(partStart, partEnd int)) { - numGoroutines := 1 - partSize := dataSize - - numProcs := runtime.GOMAXPROCS(0) - if numProcs > 1 { - numGoroutines = numProcs - partSize = dataSize / (numGoroutines * 10) - if partSize < 1 { - partSize = 1 - } +// parallel processes the data in separate goroutines. +func parallel(start, stop int, fn func(<-chan int)) { + count := stop - start + if count < 1 { + return } - if numGoroutines == 1 { - fn(0, dataSize) - } else { - var wg sync.WaitGroup - wg.Add(numGoroutines) - idx := uint64(0) + procs := runtime.GOMAXPROCS(0) + if procs > count { + procs = count + } - for p := 0; p < numGoroutines; p++ { - go func() { - defer wg.Done() - for { - partStart := int(atomic.AddUint64(&idx, uint64(partSize))) - partSize - if partStart >= dataSize { - break - } - partEnd := partStart + partSize - if partEnd > dataSize { - partEnd = dataSize - } - fn(partStart, partEnd) - } - }() - } + c := make(chan int, count) + for i := start; i < stop; i++ { + c <- i + } + close(c) - wg.Wait() + var wg sync.WaitGroup + for i := 0; i < procs; i++ { + wg.Add(1) + go func() { + defer wg.Done() + fn(c) + }() } + wg.Wait() } // absint returns the absolute value of i. @@ -69,3 +54,30 @@ func clamp(x float64) uint8 { } return 0 } + +func reverse(pix []uint8) { + if len(pix) <= 4 { + return + } + i := 0 + j := len(pix) - 4 + for i < j { + pix[i+0], pix[j+0] = pix[j+0], pix[i+0] + pix[i+1], pix[j+1] = pix[j+1], pix[i+1] + pix[i+2], pix[j+2] = pix[j+2], pix[i+2] + pix[i+3], pix[j+3] = pix[j+3], pix[i+3] + i += 4 + j -= 4 + } +} + +func toNRGBA(img image.Image) *image.NRGBA { + if img, ok := img.(*image.NRGBA); ok { + return &image.NRGBA{ + Pix: img.Pix, + Stride: img.Stride, + Rect: img.Rect.Sub(img.Rect.Min), + } + } + return Clone(img) +} -- cgit v1.2.3-1-g7c22