(target image.Image, background Color, size, numWorkers int)
| 23 | } |
| 24 | |
| 25 | func NewModel(target image.Image, background Color, size, numWorkers int) *Model { |
| 26 | w := target.Bounds().Size().X |
| 27 | h := target.Bounds().Size().Y |
| 28 | aspect := float64(w) / float64(h) |
| 29 | var sw, sh int |
| 30 | var scale float64 |
| 31 | if aspect >= 1 { |
| 32 | sw = size |
| 33 | sh = int(float64(size) / aspect) |
| 34 | scale = float64(size) / float64(w) |
| 35 | } else { |
| 36 | sw = int(float64(size) * aspect) |
| 37 | sh = size |
| 38 | scale = float64(size) / float64(h) |
| 39 | } |
| 40 | |
| 41 | model := &Model{} |
| 42 | model.Sw = sw |
| 43 | model.Sh = sh |
| 44 | model.Scale = scale |
| 45 | model.Background = background |
| 46 | model.Target = imageToRGBA(target) |
| 47 | model.Current = uniformRGBA(target.Bounds(), background.NRGBA()) |
| 48 | model.Score = differenceFull(model.Target, model.Current) |
| 49 | model.Context = model.newContext() |
| 50 | for i := 0; i < numWorkers; i++ { |
| 51 | worker := NewWorker(model.Target) |
| 52 | model.Workers = append(model.Workers, worker) |
| 53 | } |
| 54 | return model |
| 55 | } |
| 56 | |
| 57 | func (model *Model) newContext() *gg.Context { |
| 58 | dc := gg.NewContext(model.Sw, model.Sh) |
nothing calls this directly
no test coverage detected
searching dependent graphs…