Skip to content

Commit cdc7507

Browse files
committed
Updating go.mod and documentation with the new API
1 parent 38baa8e commit cdc7507

File tree

5 files changed

+22
-35
lines changed

5 files changed

+22
-35
lines changed

README.md

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,8 @@ Radius | Javascript | Go
1616

1717
## Installation
1818

19-
First, install Go, set your GOPATH, and make sure $GOPATH/bin is on your PATH.
20-
21-
```bash
22-
$ export GOPATH="$HOME/go"
23-
$ export PATH="$PATH:$GOPATH/bin"
24-
```
25-
26-
Next download the project and build the binary file.
27-
2819
```bash
29-
$ go get -u -f github.com/esimov/stackblur-go
30-
$ cd cmd && go build -o $GOPATH/bin/stackblur
20+
$ go install github.com/esimov/stackblur-go/cmd/stackblur@latest
3121
```
3222

3323
#### CLI example
@@ -55,10 +45,10 @@ The cli command supports a `-gif` flag, which if set as true it visualize the bl
5545

5646
## API
5747

58-
The usage of the API is very simple: you need to expose an image file and a blur radius to the `Process` function. This will return the blurred version of the original image.
48+
The usage of the API is very simple: it exposes a single public `Process` function which requires a destination and a source image together with a blur radius. The blured image will be encoded into the destination image.
5949

6050
```Go
61-
stackblur.Process(src, blurRadius)
51+
stackblur.Process(dst, src, blurRadius)
6252
```
6353

6454
## Results

cmd/main.go renamed to cmd/stackblur/main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ func main() {
6060

6161
for i := 0; i < *radius; i++ {
6262
go func(idx int) {
63-
img := image.NewNRGBA(src.Bounds())
64-
err := stackblur.Run(img, src, uint32(idx+1))
63+
dst := image.NewNRGBA(src.Bounds())
64+
err := stackblur.Process(dst, src, uint32(idx+1))
6565
if err != nil {
6666
log.Fatal(err)
6767
}
6868
fmt.Printf("frame %d/%d\n", idx, *radius)
69-
imgs[idx] = img
69+
imgs[idx] = dst
7070

7171
wg.Done()
7272
}(i)
@@ -82,12 +82,12 @@ func main() {
8282
log.Fatal(err)
8383
}
8484
} else {
85-
img := image.NewNRGBA(src.Bounds())
86-
err := stackblur.Run(img, src, uint32(*radius))
85+
dst := image.NewNRGBA(src.Bounds())
86+
err := stackblur.Process(dst, src, uint32(*radius))
8787
if err != nil {
8888
log.Fatal(err)
8989
}
90-
if err := generateImage(*destination, img); err != nil {
90+
if err := generateImage(*destination, dst); err != nil {
9191
log.Fatalf("error generating the blurred image: %v", err)
9292
}
9393
}

doc.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ stackblur-go is a Go port of the Stackblur algorithm.
33
44
Stackblur is a compromise between Gaussian blur and Box blur, but it creates much better looking blurs than Box blur and it is ~7x faster than Gaussian blur.
55
6-
The API is very simple and easy to integrate into any project. You only need to invoke the Process function which receive an image and a radius as parameters and returns the blurred version of the provided image.
6+
The usage of the API is very simple: it exposes a single public `Process` function which requires a destination and a source image together with a blur radius. The blured image will be encoded into the destination image.
77
8-
func Process(src image.Image, radius uint32) (*image.NRGBA, error)
8+
func Process(dst, src image.Image, radius uint32) error
99
1010
Below is a very simple example of how you can use this package.
1111
@@ -28,12 +28,13 @@ Below is a very simple example of how you can use this package.
2828
}
2929
defer f.Close()
3030
31-
img, _, err := image.Decode(f)
31+
src, _, err := image.Decode(f)
3232
if err != nil {
3333
log.Fatalf("could not decode source file: %v", err)
3434
}
3535
36-
src, err := stackblur.Process(img, radius)
36+
dst := image.NewNRGBA(src.Bounds())
37+
err = stackblur.Process(dst, src, radius)
3738
if err != nil {
3839
log.Fatal(err)
3940
}
@@ -44,7 +45,7 @@ Below is a very simple example of how you can use this package.
4445
}
4546
defer output.Close()
4647
47-
if err = jpeg.Encode(output, src, &jpeg.Options{Quality: 100}); err != nil {
48+
if err = jpeg.Encode(output, dst, &jpeg.Options{Quality: 100}); err != nil {
4849
log.Fatalf("could not encode destination image: %v", err)
4950
}
5051
}

go.mod

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
module github.com/esimov/stackblur-go
22

3-
go 1.16
3+
go 1.24
44

5-
// Provides an unstable API
6-
retract v1.0.0
7-
8-
// Introduces backwards incompatible changes
9-
retract v1.0.1
10-
11-
// Also makes a backwards incompatible change
12-
retract v1.0.2
5+
// Unstable API
6+
retract (
7+
[v1.0.0, v1.0.2]
8+
)

stackblur.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ var shgTable = []uint32{
5353
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
5454
}
5555

56-
// Run takes the source image and returns it's blurred version by applying the blur radius defined as parameter.
57-
func Run(dst, src image.Image, radius uint32) error {
56+
// Process takes the source image and returns it's blurred version by applying the blur radius defined as parameter.
57+
func Process(dst, src image.Image, radius uint32) error {
5858
// Limit the maximum blur radius to 255 to avoid overflowing the multable.
5959
if int(radius) >= len(mulTable) {
6060
radius = uint32(len(mulTable) - 1)

0 commit comments

Comments
 (0)