grayscale option
This commit is contained in:
parent
bffd1d542b
commit
bd7c32b526
10
blend.go
10
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
|
||||
|
@ -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
|
||||
|
1
main.go
1
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. <width>x<height>")
|
||||
flag.BoolVar(&ConfigRegister.Grayscale, "grayscale", false, "Output image in shade of gray (around 50)")
|
||||
flag.Parse()
|
||||
|
||||
// set output's width and height
|
||||
|
Loading…
Reference in New Issue
Block a user