From f9ca045e9efce83ff25859914e3f67bba8944541 Mon Sep 17 00:00:00 2001 From: damir Date: Thu, 28 Sep 2017 11:19:28 +0300 Subject: [PATCH 1/6] Adds support for -bloor flag. Adds bloor filter for SVG output. Default: 0 (disabled). --- main.go | 6 ++++-- primitive/model.go | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 75d776c2..1bde9da0 100644 --- a/main.go +++ b/main.go @@ -12,13 +12,14 @@ import ( "strings" "time" - "github.com/fogleman/primitive/primitive" "github.com/nfnt/resize" + "github.com/ramainen/primitive/primitive" ) var ( Input string Outputs flagArray + BlurFilter int Background string Configs shapeConfigArray Alpha int @@ -65,6 +66,7 @@ func init() { flag.StringVar(&Input, "i", "", "input image path") flag.Var(&Outputs, "o", "output image path") flag.Var(&Configs, "n", "number of primitives") + flag.IntVar(&BlurFilter, "blur", 0, "make N bloor (for svg, 0 - disabled)") flag.StringVar(&Background, "bg", "", "background color (hex)") flag.IntVar(&Alpha, "a", 128, "alpha value") flag.IntVar(&InputSize, "r", 256, "resize large input images to this size") @@ -153,7 +155,7 @@ func main() { } // run algorithm - model := primitive.NewModel(input, bg, OutputSize, Workers) + model := primitive.NewModel(input, bg, OutputSize, Workers, BlurFilter) primitive.Log(1, "%d: t=%.3f, score=%.6f\n", 0, 0.0, model.Score) start := time.Now() frame := 0 diff --git a/primitive/model.go b/primitive/model.go index 80f49ae8..b078e627 100644 --- a/primitive/model.go +++ b/primitive/model.go @@ -12,6 +12,7 @@ type Model struct { Sw, Sh int Scale float64 Background Color + BlurFilter int Target *image.RGBA Current *image.RGBA Context *gg.Context @@ -22,7 +23,7 @@ type Model struct { Workers []*Worker } -func NewModel(target image.Image, background Color, size, numWorkers int) *Model { +func NewModel(target image.Image, background Color, size, numWorkers int, blurFilter int) *Model { w := target.Bounds().Size().X h := target.Bounds().Size().Y aspect := float64(w) / float64(h) @@ -43,6 +44,7 @@ func NewModel(target image.Image, background Color, size, numWorkers int) *Model model.Sh = sh model.Scale = scale model.Background = background + model.BlurFilter = blurFilter model.Target = imageToRGBA(target) model.Current = uniformRGBA(target.Bounds(), background.NRGBA()) model.Score = differenceFull(model.Target, model.Current) @@ -87,8 +89,16 @@ func (model *Model) SVG() string { bg := model.Background var lines []string lines = append(lines, fmt.Sprintf("", model.Sw, model.Sh)) + if model.BlurFilter != 0 { + lines = append(lines, fmt.Sprintf("", model.BlurFilter)) + } lines = append(lines, fmt.Sprintf("", model.Sw, model.Sh, bg.R, bg.G, bg.B)) - lines = append(lines, fmt.Sprintf("", model.Scale)) + if model.BlurFilter != 0 { + lines = append(lines, fmt.Sprintf("", model.Scale)) + } else { + lines = append(lines, fmt.Sprintf("", model.Scale)) + } + for i, shape := range model.Shapes { c := model.Colors[i] attrs := "fill=\"#%02x%02x%02x\" fill-opacity=\"%f\"" From 53a6c4a4b13f37edd29f02074ec8e4566ac03dde Mon Sep 17 00:00:00 2001 From: damir Date: Thu, 28 Sep 2017 11:24:22 +0300 Subject: [PATCH 2/6] Add README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ebe8af4b..47a2f0f0 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ Small input images should be used (like 256x256px). You don't need the detail an | `s` | 1024 | output image size | | `a` | 128 | color alpha (use `0` to let the algorithm choose alpha for each shape) | | `bg` | avg | starting background color (hex) | +| `blur` | 0 | making SVG blured, adds blur filter witn N deviation. 0 - disabled. | | `j` | 0 | number of parallel workers (default uses all cores) | | `v` | off | verbose output | | `vv` | off | very verbose output | From 1de17f9e76aa20d897c12f772f929bfd516832b1 Mon Sep 17 00:00:00 2001 From: damir Date: Thu, 28 Sep 2017 11:25:14 +0300 Subject: [PATCH 3/6] Change path to "fogleman" --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 1bde9da0..b025c70d 100644 --- a/main.go +++ b/main.go @@ -13,7 +13,7 @@ import ( "time" "github.com/nfnt/resize" - "github.com/ramainen/primitive/primitive" + "github.com/fogleman/primitive/primitive" ) var ( From 5e233c652ca310bde0aadcdbdc69f9e021afb9b4 Mon Sep 17 00:00:00 2001 From: damir Date: Thu, 28 Sep 2017 11:28:30 +0300 Subject: [PATCH 4/6] Change import list for clean Pull request --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index b025c70d..674504f0 100644 --- a/main.go +++ b/main.go @@ -12,8 +12,8 @@ import ( "strings" "time" - "github.com/nfnt/resize" "github.com/fogleman/primitive/primitive" + "github.com/nfnt/resize" ) var ( From 138a5b32467ac4ba975812008b43aadda0082f42 Mon Sep 17 00:00:00 2001 From: damir Date: Thu, 28 Sep 2017 11:32:40 +0300 Subject: [PATCH 5/6] Fixing typo in description. --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 674504f0..552c6e55 100644 --- a/main.go +++ b/main.go @@ -66,7 +66,7 @@ func init() { flag.StringVar(&Input, "i", "", "input image path") flag.Var(&Outputs, "o", "output image path") flag.Var(&Configs, "n", "number of primitives") - flag.IntVar(&BlurFilter, "blur", 0, "make N bloor (for svg, 0 - disabled)") + flag.IntVar(&BlurFilter, "blur", 0, "make N blur (for svg, 0 - disabled)") flag.StringVar(&Background, "bg", "", "background color (hex)") flag.IntVar(&Alpha, "a", 128, "alpha value") flag.IntVar(&InputSize, "r", 256, "resize large input images to this size") From fc92c395daaa670da3886227b86e0ccd3f407ffb Mon Sep 17 00:00:00 2001 From: damir Date: Thu, 28 Sep 2017 11:42:39 +0300 Subject: [PATCH 6/6] back to dev path --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 552c6e55..57fae4cf 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,7 @@ import ( "strings" "time" - "github.com/fogleman/primitive/primitive" + "github.com/ramainen/primitive/primitive" "github.com/nfnt/resize" )