Skip to content

Commit

Permalink
Fix image rotation, fix Kuwahara filter
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdee committed Feb 10, 2023
1 parent 6f96e8e commit 6145748
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 29 deletions.
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 6145748

Please sign in to comment.