Skip to content

Commit

Permalink
Merge pull request #6 from julyskies/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
peterdee authored Feb 10, 2023
2 parents 148d4fb + 6145748 commit d6bcf5d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 32 deletions.
11 changes: 8 additions & 3 deletions filters/flip.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,20 @@ func Flip(file io.Reader, direction string) (io.Reader, string, error) {
for i := 0; i < len(img.Pix); i += 4 {
x, y := utilities.GetCoordinates(i/4, width)
var j int
skip := true
if direction == constants.FLIP_DIRECTION_HORIZONTAL && x < width/2+widthCorrection {
j = utilities.GetPixel(width-x-1, y, width)
skip = false
}
if direction == constants.FLIP_DIRECTION_VERTICAL && y < height/2+heightCorrection {
j = utilities.GetPixel(x, height-y-1, width)
skip = false
}
if !skip {
r, g, b := img.Pix[i], img.Pix[i+1], img.Pix[i+2]
img.Pix[i], img.Pix[i+1], img.Pix[i+2] = img.Pix[j], img.Pix[j+1], img.Pix[j+2]
img.Pix[j], img.Pix[j+1], img.Pix[j+2] = r, g, b
}
r, g, b := img.Pix[i], img.Pix[i+1], img.Pix[i+2]
img.Pix[i], img.Pix[i+1], img.Pix[i+2] = img.Pix[j], img.Pix[j+1], img.Pix[j+2]
img.Pix[j], img.Pix[j+1], img.Pix[j+2] = r, g, b
}
return utilities.EncodeResult(img, format)
}
1 change: 1 addition & 0 deletions filters/kuwahara.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func Kuwahara(file io.Reader, radius uint) (io.Reader, string, error) {
destination[i] = uint8(rValues[j] / pixelsCount[j])
destination[i+1] = uint8(gValues[j] / pixelsCount[j])
destination[i+2] = uint8(bValues[j] / pixelsCount[j])
destination[i+3] = img.Pix[i+3]
}
img.Pix = destination
return utilities.EncodeResult(img, format)
Expand Down
45 changes: 16 additions & 29 deletions filters/rotate-fixed.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,31 @@ func RotateFixed(file io.Reader, angle uint) (io.Reader, string, error) {
angle = constants.ROTATE_FIXED_90
}
width, height := img.Rect.Max.X, img.Rect.Max.Y
heightCorrection := 0
if height%2 != 0 {
heightCorrection = 1
}
gridWidth, gridHeight := width, height
if angle == constants.ROTATE_FIXED_180 {
for i := 0; i < len(img.Pix); i += 4 {
x, y := utilities.GetCoordinates(i/4, width)
r, g, b := img.Pix[i], img.Pix[i+1], img.Pix[i+2]
var j int
if y < height/2+heightCorrection {
j = utilities.GetPixel(width-x-1, height-y-1, width)
}
img.Pix[i], img.Pix[i+1], img.Pix[i+2] = img.Pix[j], img.Pix[j+1], img.Pix[j+2]
img.Pix[j], img.Pix[j+1], img.Pix[j+2] = r, g, b
}
return utilities.EncodeResult(img, format)
gridWidth, gridHeight = height, width
}
destination := make([][]color.Color, width)
destination := make([][]color.Color, gridWidth)
for i := range destination {
destination[i] = make([]color.Color, height)
destination[i] = make([]color.Color, gridHeight)
}
for i := 0; i < len(img.Pix); i += 4 {
x, y := utilities.GetCoordinates(i/4, width)
dx, dy := y, x
if angle == constants.ROTATE_FIXED_90 {
destination[height-y-1][x] = color.RGBA{
img.Pix[i],
img.Pix[i+1],
img.Pix[i+2],
img.Pix[i+3],
}
dx = height - y - 1
}
if angle == constants.ROTATE_FIXED_180 {
dx, dy = width-x-1, height-y-1
}
if angle == constants.ROTATE_FIXED_270 {
destination[y][width-x-1] = color.RGBA{
img.Pix[i],
img.Pix[i+1],
img.Pix[i+2],
img.Pix[i+3],
}
dy = width - x - 1
}
destination[dx][dy] = color.RGBA{
img.Pix[i],
img.Pix[i+1],
img.Pix[i+2],
img.Pix[i+3],
}
}
return utilities.EncodeGridResult(destination, format)
Expand Down

0 comments on commit d6bcf5d

Please sign in to comment.