-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from julyskies/develop
v2.0.0
- Loading branch information
Showing
50 changed files
with
879 additions
and
1,120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
package constants | ||
|
||
const ERROR_INVALID_GRAYSCALE_TYPE string = "invalid grayscale type" | ||
|
||
const ERROR_NO_FILE_PROVIDED string = "no file provided" | ||
|
||
const GRAYSCALE_AVERAGE string = "average" | ||
const FLIP_DIRECTION_HORIZONTAL string = "horizontal" | ||
|
||
const FLIP_DIRECTION_VERTICAL string = "vertical" | ||
|
||
const GRAYSCALE_TYPE_AVERAGE string = "average" | ||
|
||
const GRAYSCALE_TYPE_LUMINANCE string = "luminance" | ||
|
||
const ROTATE_FIXED_90 uint = 90 | ||
|
||
const ROTATE_FIXED_180 uint = 180 | ||
|
||
const GRAYSCALE_LUMINOCITY string = "luminocity" | ||
const ROTATE_FIXED_270 uint = 270 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package filters | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/julyskies/brille/utilities" | ||
) | ||
|
||
func Binary(file io.Reader, threshold uint8) (io.Reader, string, error) { | ||
img, format, convertationError := utilities.DecodeSource(file) | ||
if convertationError != nil { | ||
return nil, "", convertationError | ||
} | ||
for i := 0; i < len(img.Pix); i += 4 { | ||
average := uint8((int(img.Pix[i]) + int(img.Pix[i+1]) + int(img.Pix[i+2])) / 3) | ||
channel := uint8(255) | ||
if average < threshold { | ||
channel = 0 | ||
} | ||
img.Pix[i], img.Pix[i+1], img.Pix[i+2] = channel, channel, channel | ||
} | ||
return utilities.EncodeResult(img, format) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package filters | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/julyskies/brille/utilities" | ||
) | ||
|
||
func BoxBlur(file io.Reader, radius uint) (io.Reader, string, error) { | ||
img, format, convertationError := utilities.DecodeSource(file) | ||
if convertationError != nil { | ||
return nil, "", convertationError | ||
} | ||
radiusInt := int(radius) | ||
width, height := img.Rect.Max.X, img.Rect.Max.Y | ||
for i := 0; i < len(img.Pix); i += 4 { | ||
x, y := utilities.GetCoordinates(i/4, width) | ||
sumR, sumG, sumB, pixelCount := 0, 0, 0, 0 | ||
x2s, x2e := utilities.GetAperture(x, width, -radiusInt, radiusInt) | ||
y2s, y2e := utilities.GetAperture(y, height, -radiusInt, radiusInt) | ||
for x2 := x2s; x2 < x2e; x2 += 1 { | ||
for y2 := y2s; y2 < y2e; y2 += 1 { | ||
px := utilities.GetPixel(x2, y2, width) | ||
sumR += int(img.Pix[px]) | ||
sumG += int(img.Pix[px+1]) | ||
sumB += int(img.Pix[px+2]) | ||
pixelCount += 1 | ||
} | ||
} | ||
img.Pix[i] = uint8(sumR / pixelCount) | ||
img.Pix[i+1] = uint8(sumG / pixelCount) | ||
img.Pix[i+2] = uint8(sumB / pixelCount) | ||
} | ||
return utilities.EncodeResult(img, format) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package filters | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/julyskies/brille/utilities" | ||
) | ||
|
||
func Brightness(file io.Reader, amount int) (io.Reader, string, error) { | ||
img, format, convertationError := utilities.DecodeSource(file) | ||
if convertationError != nil { | ||
return nil, "", convertationError | ||
} | ||
amount = utilities.MaxMin(amount, 255, -255) | ||
for i := 0; i < len(img.Pix); i += 4 { | ||
img.Pix[i] = uint8(utilities.MaxMin(int(img.Pix[i])+amount, 255, 0)) | ||
img.Pix[i+1] = uint8(utilities.MaxMin(int(img.Pix[i+1])+amount, 255, 0)) | ||
img.Pix[i+2] = uint8(utilities.MaxMin(int(img.Pix[i+2])+amount, 255, 0)) | ||
} | ||
return utilities.EncodeResult(img, format) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package filters | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/julyskies/brille/utilities" | ||
) | ||
|
||
func ColorInversion(file io.Reader) (io.Reader, string, error) { | ||
img, format, convertationError := utilities.DecodeSource(file) | ||
if convertationError != nil { | ||
return nil, "", convertationError | ||
} | ||
for i := 0; i < len(img.Pix); i += 4 { | ||
img.Pix[i] = 255 - img.Pix[i] | ||
img.Pix[i+1] = 255 - img.Pix[i+1] | ||
img.Pix[i+2] = 255 - img.Pix[i+2] | ||
} | ||
return utilities.EncodeResult(img, format) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package filters | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/julyskies/brille/utilities" | ||
) | ||
|
||
func Contrast(file io.Reader, amount int) (io.Reader, string, error) { | ||
img, format, convertationError := utilities.DecodeSource(file) | ||
if convertationError != nil { | ||
return nil, "", convertationError | ||
} | ||
amount = utilities.MaxMin(amount, 255, -255) | ||
factor := float64(259*(amount+255)) / float64(255*(259-amount)) | ||
for i := 0; i < len(img.Pix); i += 4 { | ||
img.Pix[i] = uint8(utilities.MaxMin(factor*(float64(img.Pix[i])-128)+128, 255, 0)) | ||
img.Pix[i+1] = uint8(utilities.MaxMin(factor*(float64(img.Pix[i+1])-128)+128, 255, 0)) | ||
img.Pix[i+2] = uint8(utilities.MaxMin(factor*(float64(img.Pix[i+2])-128)+128, 255, 0)) | ||
} | ||
return utilities.EncodeResult(img, format) | ||
} |
Oops, something went wrong.