Skip to content

Commit

Permalink
fix: SemVer and API design issues #5
Browse files Browse the repository at this point in the history
  • Loading branch information
esimov committed Feb 28, 2022
1 parent 4c3d543 commit 94f9b01
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
14 changes: 9 additions & 5 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import (
"image/draw"
"image/gif"
"image/jpeg"
_ "image/jpeg"
"image/png"
_ "image/png"
"log"
"os"
"path"
Expand All @@ -37,6 +35,9 @@ func main() {
}

img, err := os.Open(*source)
if err != nil {
log.Fatal("could not open source image:", err)
}
defer img.Close()

src, _, err := image.Decode(img)
Expand All @@ -46,7 +47,7 @@ func main() {
start := time.Now()
if *outputGif {
for i := 1; i <= *radius; i++ {
img, err := stackblur.Run(src, uint32(i))
img, err := stackblur.Process(src, uint32(i))
if err != nil {
log.Fatal(err)
}
Expand All @@ -67,7 +68,7 @@ func main() {
log.Fatal(err)
}
} else {
img, err := stackblur.Run(src, uint32(*radius))
img, err := stackblur.Process(src, uint32(*radius))
if err != nil {
log.Fatal(err)
}
Expand All @@ -76,7 +77,7 @@ func main() {
}
}
end := time.Since(start)
fmt.Printf("\nGenerated in: %.2fs\n", end.Seconds())
fmt.Printf("Generated in: %.2fs\n", end.Seconds())
}

// encodeGIF encodes the generated output into a gif file
Expand All @@ -100,6 +101,9 @@ func encodeGIF(imgs []image.Image, path string) error {
// generateImage generates the image type depending on the provided extension
func generateImage(dst string, img image.Image) error {
output, err := os.OpenFile(dst, os.O_CREATE|os.O_RDWR, 0755)
if err != nil {
return err
}
defer output.Close()

if err != nil {
Expand Down
11 changes: 10 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
module github.com/esimov/stackblur-go

go 1.13
go 1.16

// Provides an unstable API
retract v1.0.0

// Introduces backwards incompatible changes
retract v1.0.1

// Also makes a backwards incompatible change
retract v1.0.2
22 changes: 4 additions & 18 deletions stackblur.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"errors"
"image"
"image/color"
"io"
"os"
)

// blurStack is a linked list containing the color value and a pointer to the next struct.
Expand Down Expand Up @@ -55,27 +53,15 @@ var shgTable = []uint32{
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
}

// Run takes an image or pixel data as input and returns
// it's blurred version by applying the blur radius defined as parameter.
func Run(input interface{}, radius uint32) (image.Image, error) {
// Process takes the source image and returns it's blurred version by applying the blur radius defined as parameter.
func Process(src image.Image, radius uint32) (*image.NRGBA, error) {
var (
stackEnd *blurStack
stackIn *blurStack
stackOut *blurStack
src interface{}
err error
)
switch input.(type) {
case *os.File:
src, _, err = image.Decode(input.(io.Reader))
if err != nil {
return nil, err
}
default:
src = input
}

var width, height = uint32(src.(image.Image).Bounds().Dx()), uint32(src.(image.Image).Bounds().Dy())
var width, height = uint32(src.Bounds().Dx()), uint32(src.Bounds().Dy())
var (
div, widthMinus1, heightMinus1, radiusPlus1, sumFactor uint32
x, y, i, p, yp, yi, yw,
Expand All @@ -94,7 +80,7 @@ func Run(input interface{}, radius uint32) (image.Image, error) {
return nil, errors.New("blur radius must be greater than 0")
}

img := toNRGBA(src.(image.Image))
img := toNRGBA(src)

div = radius + radius + 1
widthMinus1 = width - 1
Expand Down

0 comments on commit 94f9b01

Please sign in to comment.