Skip to content

Commit

Permalink
Merge pull request #11 from julyskies/develop
Browse files Browse the repository at this point in the history
Updates for 2.0.4
  • Loading branch information
peterdee authored Mar 21, 2023
2 parents 5c8d517 + c851137 commit d986d36
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 14 deletions.
4 changes: 4 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ func controller(context *fiber.Ctx) error {

Full Fiber example is available at https://github.com/peterdee/filtering-backend

### Performance

Brille uses `sync.WaitGroup` for performance optimization starting with version **v2.0.4**. Image processing can be done in several threads (by default Brille uses `runtime.NumCPU()` value).

### Available filters

- **Binary**: converts an image to 1-bit black and white. Requires a threshold value (`uint8`, 0 to 255):
Expand Down
4 changes: 2 additions & 2 deletions filters/emboss.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ func Emboss(file io.Reader) (io.Reader, string, error) {
if convertationError != nil {
return nil, "", convertationError
}
width, height := img.Rect.Max.X, img.Rect.Max.Y
pixLen := len(img.Pix)
result := make([]uint8, pixLen)
threads := utilities.GetThreads()
pixPerThread := utilities.GetPixPerThread(pixLen, threads)
result := make([]uint8, pixLen)
width, height := img.Rect.Max.X, img.Rect.Max.Y
var wg sync.WaitGroup
processing := func(thread int) {
defer wg.Done()
Expand Down
10 changes: 2 additions & 8 deletions filters/gaussian-blur.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ func GaussianBlur(file io.Reader, sigma float64) (io.Reader, string, error) {
sigma = utilities.Clamp(sigma, 99, 0)
kernel := createKernel(sigma)
pixLen := len(img.Pix)
width, height := img.Rect.Max.X, img.Rect.Max.Y
temp := make([]uint8, pixLen)
threads := utilities.GetThreads()
pixPerThread := utilities.GetPixPerThread(pixLen, threads)
temp := make([]uint8, pixLen)
width, height := img.Rect.Max.X, img.Rect.Max.Y
var wg sync.WaitGroup

processing := func(start int, direction string) {
defer wg.Done()
end := utilities.ClampMax(start+pixPerThread, pixLen)
Expand Down Expand Up @@ -88,20 +87,15 @@ func GaussianBlur(file io.Reader, sigma float64) (io.Reader, string, error) {
}
}
}

// horizontal
for t := 0; t < threads; t += 1 {
wg.Add(1)
go processing(pixPerThread*t, "horizontal")
}
wg.Wait()

// vertical
for t := 0; t < threads; t += 1 {
wg.Add(1)
go processing(pixPerThread*t, "vertical")
}
wg.Wait()

return utilities.EncodeResult(img, format)
}
2 changes: 1 addition & 1 deletion filters/kuwahara.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ func Kuwahara(file io.Reader, radius uint) (io.Reader, string, error) {
if convertationError != nil {
return nil, "", convertationError
}
width, height := img.Rect.Max.X, img.Rect.Max.Y
radiusInt := int(radius)
pixLen := len(img.Pix)
threads := utilities.GetThreads()
pixPerThread := utilities.GetPixPerThread(pixLen, threads)
result := make([]uint8, pixLen)
width, height := img.Rect.Max.X, img.Rect.Max.Y
var wg sync.WaitGroup
processing := func(thread int) {
defer wg.Done()
Expand Down
2 changes: 1 addition & 1 deletion filters/laplacian.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ func Laplacian(file io.Reader) (io.Reader, string, error) {
if convertationError != nil {
return nil, "", convertationError
}
width, height := img.Rect.Max.X, img.Rect.Max.Y
pixLen := len(img.Pix)
threads := utilities.GetThreads()
pixPerThread := utilities.GetPixPerThread(pixLen, threads)
result := make([]uint8, pixLen)
width, height := img.Rect.Max.X, img.Rect.Max.Y
var wg sync.WaitGroup
processing := func(thread int) {
defer wg.Done()
Expand Down
2 changes: 1 addition & 1 deletion filters/sharpen.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func Sharpen(file io.Reader, amount uint) (io.Reader, string, error) {
pixLen := len(img.Pix)
threads := utilities.GetThreads()
pixPerThread := utilities.GetPixPerThread(pixLen, threads)
width, height := img.Rect.Max.X, img.Rect.Max.Y
result := make([]uint8, pixLen)
width, height := img.Rect.Max.X, img.Rect.Max.Y
var wg sync.WaitGroup
processing := func(thread int) {
defer wg.Done()
Expand Down
2 changes: 1 addition & 1 deletion filters/sobel.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func Sobel(file io.Reader) (io.Reader, string, error) {
pixLen := len(img.Pix)
threads := utilities.GetThreads()
pixPerThread := utilities.GetPixPerThread(pixLen, threads)
width, height := img.Rect.Max.X, img.Rect.Max.Y
result := make([]uint8, pixLen)
width, height := img.Rect.Max.X, img.Rect.Max.Y
var wg sync.WaitGroup
processing := func(thread int) {
defer wg.Done()
Expand Down

0 comments on commit d986d36

Please sign in to comment.