1
0

sepia, general filter function

This commit is contained in:
2022-05-01 22:20:25 +02:00
parent 8d79ea8200
commit 3d7fc1b2d3
2 changed files with 39 additions and 4 deletions

View File

@ -159,6 +159,42 @@ func grayscale(pixel color.Color) color.Color {
}
}
// sepia toning filter
func sepia(pixel color.Color) color.Color {
c := color.RGBAModel.Convert(pixel).(color.RGBA)
var npr uint8
var npg uint8
var npb uint8
tr := float64(c.R)*0.393 + float64(c.G)*0.769 + float64(c.B)*0.189
tg := float64(c.R)*0.349 + float64(c.G)*0.686 + float64(c.B)*0.168
tb := float64(c.R)*0.272 + float64(c.G)*0.534 + float64(c.B)*0.131
npr = uint8(math.Min(255, tr))
npg = uint8(math.Min(255, tg))
npb = uint8(math.Min(255, tb))
return color.RGBA{
R: npr,
G: npg,
B: npb,
A: c.A,
}
}
// if a filter is specified, apply it to the pixel, if not returns it unchanged
func filter(pixel color.Color) color.Color {
if ConfigRegister.Grayscale {
return grayscale(pixel)
}
if ConfigRegister.Sepia {
return sepia(pixel)
}
return pixel
}
func darken(fc uint8, bc uint8, fa uint8) float64 {
return math.Min(float64(fc), float64(bc))
}
@ -199,10 +235,7 @@ func blendColor(color1 color.Color, color2 color.Color) color.Color {
new := color.RGBA{
R: r, G: g, B: b, A: a,
}
if ConfigRegister.Grayscale == true {
return grayscale(new)
}
return new
return filter(new)
}
// creates a new rectangle with the min height and width from both images