1
0

grayscale option

This commit is contained in:
2022-05-01 17:49:51 +02:00
parent 1138d11923
commit a0fbe438d4
3 changed files with 9 additions and 3 deletions

View File

@ -118,10 +118,10 @@ func encodeImage(imgData *image.RGBA) {
log.Println("Done.")
}
// convert RGBA pixel to grayscale
// convert RGBA pixel to grayscale. BT.709 luminosity formula
func grayscale(pixel color.Color) color.Color {
c := color.RGBAModel.Convert(pixel).(color.RGBA)
gray := uint8((c.R + c.G + c.B) / 3)
gray := uint8(0.2126*float64(c.R) + 0.7152*float64(c.G) + 0.0722*float64(c.B))
return color.RGBA{
R: gray,
G: gray,
@ -167,9 +167,13 @@ func blendColor(color1 color.Color, color2 color.Color) color.Color {
g := uint8(blend(oc1.G, oc2.G, oc1.A, oc2.A))
b := uint8(blend(oc1.B, oc2.B, oc1.A, oc2.A))
a := oc1.A + (1-oc1.A)*oc2.A
return color.RGBA{
new := color.RGBA{
R: r, G: g, B: b, A: a,
}
if ConfigRegister.Grayscale == true {
return grayscale(new)
}
return new
}
// creates a new rectangle with the min height and width from both images