Skip to content

Commit

Permalink
Merge pull request #1 from julyskies/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
peterdee authored Jan 14, 2023
2 parents a37b39f + 1771718 commit a866638
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ func controller(context *fiber.Ctx) error {
)
```

- **Hue rotation**: rotate image hue to change the colors. Requires an angle to be provided. Angle represents degree of a hue rotation, can be any `int` number:

```golang
rotated, format, processingError := brille.HueRotate(file, 278)
```

- **Laplasian filter**: a static edge detection filter that uses a 3x3 kernel. It can be used to outline edges on an image:

```golang
Expand Down
17 changes: 17 additions & 0 deletions index.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,23 @@ func Grayscale(file io.Reader, grayscaleType string) (io.Reader, string, error)
return encoded, format, nil
}

// angle: any int value
func HueRotate(file io.Reader, angle int) (io.Reader, string, error) {
if file == nil {
return nil, "", errors.New(constants.ERROR_NO_FILE_PROVIDED)
}
source, format, preparationError := utilities.PrepareSource(file)
if preparationError != nil {
return nil, "", preparationError
}
rotated := processing.HueRotate(source, angle)
encoded, encodingError := utilities.PrepareResult(rotated, format)
if encodingError != nil {
return nil, "", encodingError
}
return encoded, format, nil
}

func LaplasianFilter(file io.Reader) (io.Reader, string, error) {
if file == nil {
return nil, "", errors.New(constants.ERROR_NO_FILE_PROVIDED)
Expand Down
6 changes: 5 additions & 1 deletion processing/flip-horizontal.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import (
func FlipHorizontal(source [][]color.Color) [][]color.Color {
width, height := len(source), len(source[0])
destination := utilities.CreateGrid(width, height)
for x := 0; x < width/2; x += 1 {
correction := 0
if width%2 != 0 {
correction = 1
}
for x := 0; x < width/2+correction; x += 1 {
for y := 0; y < height; y += 1 {
z := width - x - 1
destination[x][y], destination[z][y] = source[z][y], source[x][y]
Expand Down
6 changes: 5 additions & 1 deletion processing/flip-vertical.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ import (
func FlipVertical(source [][]color.Color) [][]color.Color {
width, height := len(source), len(source[0])
destination := utilities.CreateGrid(width, height)
correction := 0
if height%2 != 0 {
correction = 1
}
for x := 0; x < width; x += 1 {
for y := 0; y < height/2; y += 1 {
for y := 0; y < height/2+correction; y += 1 {
z := height - y - 1
destination[x][y], destination[x][z] = source[x][z], source[x][y]
}
Expand Down
49 changes: 49 additions & 0 deletions processing/hue-rotate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package processing

import (
"image/color"
"math"

"github.com/julyskies/brille/utilities"
)

const DEG float64 = math.Pi / 180

func HueRotate(source [][]color.Color, angle int) [][]color.Color {
width, height := len(source), len(source[0])
destination := utilities.CreateGrid(width, height)
cos := math.Cos(float64(angle) * DEG)
sin := math.Sin(float64(angle) * DEG)
matrix := [3]float64{
cos + (1-cos)/3,
(1-cos)/3 - math.Sqrt(float64(1)/3)*sin,
(1-cos)/3 + math.Sqrt(float64(1)/3)*sin,
}
for x := 0; x < width; x += 1 {
for y := 0; y < height; y += 1 {
r, g, b, alpha := utilities.RGBA(source[x][y])
rr := utilities.MaxMin(
float64(r)*matrix[0]+float64(g)*matrix[1]+float64(b)*matrix[2],
255,
0,
)
rg := utilities.MaxMin(
float64(r)*matrix[2]+float64(g)*matrix[0]+float64(b)*matrix[1],
255,
0,
)
rb := utilities.MaxMin(
float64(r)*matrix[1]+float64(g)*matrix[2]+float64(b)*matrix[0],
255,
0,
)
destination[x][y] = color.RGBA{
uint8(rr),
uint8(rg),
uint8(rb),
alpha,
}
}
}
return destination
}

0 comments on commit a866638

Please sign in to comment.