diff --git a/blend.go b/blend.go index 647d7d8..4c55e39 100644 --- a/blend.go +++ b/blend.go @@ -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 diff --git a/config.go b/config.go index 8b54a6a..52e3a49 100644 --- a/config.go +++ b/config.go @@ -16,6 +16,7 @@ type Config struct { Dimensions string `json:dimensions` OutputWidth int `json:output_width` OutputHeight int `json:output_height` + Grayscale bool } // loads configuration values from json file diff --git a/main.go b/main.go index fca0755..742050c 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,7 @@ func main() { flag.StringVar(&ConfigRegister.InputDir, "input", "/home/gator/Photos", "Input directory. Where to look the images from") flag.StringVar(&ConfigRegister.BaseImage, "base-img", "", "Path to the base image to work with. Random image if not set") flag.StringVar(&ConfigRegister.Dimensions, "dimensions", "800x600", "Out image dimensions. x") + flag.BoolVar(&ConfigRegister.Grayscale, "grayscale", false, "Output image in shade of gray (around 50)") flag.Parse() // set output's width and height