Skip to content

Commit 64e380b

Browse files
committed
Merge branch 'release' of https://github.com/julyskies/brille into release
2 parents 808f1cf + a866638 commit 64e380b

File tree

5 files changed

+82
-2
lines changed

5 files changed

+82
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ Full Fiber example is available at https://github.com/peterdee/filtering-backend
183183
)
184184
```
185185

186+
- **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:
187+
188+
```golang
189+
rotated, format, processingError := brille.HueRotate(file, 278)
190+
```
191+
186192
- **Laplasian filter**: a static edge detection filter that uses a 3x3 kernel. It can be used to outline edges on an image:
187193

188194
```golang

index.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,23 @@ func Grayscale(file io.Reader, grayscaleType string) (io.Reader, string, error)
203203
return encoded, format, nil
204204
}
205205

206+
// angle: any int value
207+
func HueRotate(file io.Reader, angle int) (io.Reader, string, error) {
208+
if file == nil {
209+
return nil, "", errors.New(constants.ERROR_NO_FILE_PROVIDED)
210+
}
211+
source, format, preparationError := utilities.PrepareSource(file)
212+
if preparationError != nil {
213+
return nil, "", preparationError
214+
}
215+
rotated := processing.HueRotate(source, angle)
216+
encoded, encodingError := utilities.PrepareResult(rotated, format)
217+
if encodingError != nil {
218+
return nil, "", encodingError
219+
}
220+
return encoded, format, nil
221+
}
222+
206223
func LaplasianFilter(file io.Reader) (io.Reader, string, error) {
207224
if file == nil {
208225
return nil, "", errors.New(constants.ERROR_NO_FILE_PROVIDED)

processing/flip-horizontal.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import (
99
func FlipHorizontal(source [][]color.Color) [][]color.Color {
1010
width, height := len(source), len(source[0])
1111
destination := utilities.CreateGrid(width, height)
12-
for x := 0; x < width/2; x += 1 {
12+
correction := 0
13+
if width%2 != 0 {
14+
correction = 1
15+
}
16+
for x := 0; x < width/2+correction; x += 1 {
1317
for y := 0; y < height; y += 1 {
1418
z := width - x - 1
1519
destination[x][y], destination[z][y] = source[z][y], source[x][y]

processing/flip-vertical.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ import (
99
func FlipVertical(source [][]color.Color) [][]color.Color {
1010
width, height := len(source), len(source[0])
1111
destination := utilities.CreateGrid(width, height)
12+
correction := 0
13+
if height%2 != 0 {
14+
correction = 1
15+
}
1216
for x := 0; x < width; x += 1 {
13-
for y := 0; y < height/2; y += 1 {
17+
for y := 0; y < height/2+correction; y += 1 {
1418
z := height - y - 1
1519
destination[x][y], destination[x][z] = source[x][z], source[x][y]
1620
}

processing/hue-rotate.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package processing
2+
3+
import (
4+
"image/color"
5+
"math"
6+
7+
"github.com/julyskies/brille/utilities"
8+
)
9+
10+
const DEG float64 = math.Pi / 180
11+
12+
func HueRotate(source [][]color.Color, angle int) [][]color.Color {
13+
width, height := len(source), len(source[0])
14+
destination := utilities.CreateGrid(width, height)
15+
cos := math.Cos(float64(angle) * DEG)
16+
sin := math.Sin(float64(angle) * DEG)
17+
matrix := [3]float64{
18+
cos + (1-cos)/3,
19+
(1-cos)/3 - math.Sqrt(float64(1)/3)*sin,
20+
(1-cos)/3 + math.Sqrt(float64(1)/3)*sin,
21+
}
22+
for x := 0; x < width; x += 1 {
23+
for y := 0; y < height; y += 1 {
24+
r, g, b, alpha := utilities.RGBA(source[x][y])
25+
rr := utilities.MaxMin(
26+
float64(r)*matrix[0]+float64(g)*matrix[1]+float64(b)*matrix[2],
27+
255,
28+
0,
29+
)
30+
rg := utilities.MaxMin(
31+
float64(r)*matrix[2]+float64(g)*matrix[0]+float64(b)*matrix[1],
32+
255,
33+
0,
34+
)
35+
rb := utilities.MaxMin(
36+
float64(r)*matrix[1]+float64(g)*matrix[2]+float64(b)*matrix[0],
37+
255,
38+
0,
39+
)
40+
destination[x][y] = color.RGBA{
41+
uint8(rr),
42+
uint8(rg),
43+
uint8(rb),
44+
alpha,
45+
}
46+
}
47+
}
48+
return destination
49+
}

0 commit comments

Comments
 (0)