From 603871d556a276371e2cadcd4b1d35e5de0bdd61 Mon Sep 17 00:00:00 2001 From: Gator Date: Mon, 2 May 2022 13:25:50 +0200 Subject: [PATCH] average blend method --- README.md | 18 ++++++++++++++++++ blend.go | 6 ++++++ config.go | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..51d1c22 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# Requirements +- go >= 1.16.2 + +# Install + +Just `git clone`, `cd pixelweaver` and `go build` bro + +# Usage + +See `pixelweaver -help` for all available options + +Example : Blends three random pictures stored in specified folder, using averaging, with a sepia filter +`pixelweaver -amount 3 -input ~/Photos -blending average -sepia` + +# Resources +- [image package documentation on pkg.go.dev](https://pkg.go.dev/image) +- [Sighack - Averaging RGB Colors the Right Way](https://sighack.com/post/averaging-rgb-colors-the-right-way) +- [Sau Sheong - Image processing with Go](https://go-recipes.dev/more-working-with-images-in-go-30b11ab2a9f0?gi=3bb0ce492e2e) diff --git a/blend.go b/blend.go index 723b80b..8791741 100644 --- a/blend.go +++ b/blend.go @@ -195,6 +195,10 @@ func filter(pixel color.Color) color.Color { return pixel } +func average(fc uint8, bc uint8, fa uint8) float64 { + return (float64(fc)/2 + float64(bc)/2) +} + func darken(fc uint8, bc uint8, fa uint8) float64 { return math.Min(float64(fc), float64(bc)) } @@ -214,6 +218,8 @@ func blend(fc uint8, bc uint8, fa uint8, ba uint8) float64 { switch ConfigRegister.Method { case "darken": newValue = darken(fc, bc, fa) + case "average": + newValue = average(fc, bc, fa) case "ligten": newValue = lighten(fc, bc, fa) case "fuckyfun": diff --git a/config.go b/config.go index 895870c..0501a2c 100644 --- a/config.go +++ b/config.go @@ -48,7 +48,7 @@ func (c *Config) SetOutputDimensions() { func initConfigRegister() { // command line arguments - flag.StringVar(&ConfigRegister.Method, "blending", "darken", "Blending methods : darken, lighten, fuckyfun") + flag.StringVar(&ConfigRegister.Method, "blending", "darken", "Blending methods : darken, lighten, average, fuckyfun") flag.StringVar(&ConfigRegister.OutputDir, "output", "./", "Output directory") 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")