MCPcopy
hub / github.com/fogleman/primitive / NewModel

Function NewModel

primitive/model.go:25–55  ·  view source on GitHub ↗
(target image.Image, background Color, size, numWorkers int)

Source from the content-addressed store, hash-verified

23}
24
25func 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
57func (model *Model) newContext() *gg.Context {
58 dc := gg.NewContext(model.Sw, model.Sh)

Callers

nothing calls this directly

Calls 6

newContextMethod · 0.95
imageToRGBAFunction · 0.85
uniformRGBAFunction · 0.85
differenceFullFunction · 0.85
NewWorkerFunction · 0.85
NRGBAMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…