// NewPainter returns a new instance of Painter.
559526
func NewPainter(s Surface, p *Theme) *Painter {
	return &Painter{
		theme:   p,
		surface: s,
		style:   p.Style("normal"),
		mask: image.Rectangle{
			Min: image.ZP,
			Max: s.Size(),
		},
	}
}
456154
func (r *patternPainter) Paint(ss []raster.Span, done bool) {
	b := r.im.Bounds()
	for _, s := range ss {
		if s.Y < b.Min.Y {
			continue
		}
		if s.Y >= b.Max.Y {
			return
		}
		if s.X0 < b.Min.X {
			s.X0 = b.Min.X
		}
		if s.X1 > b.Max.X {
			s.X1 = b.Max.X
		}
		if s.X0 >= s.X1 {
			continue
		}
		const m = 1<<16 - 1
		y := s.Y - r.im.Rect.Min.Y
		x0 := s.X0 - r.im.Rect.Min.X
		// RGBAPainter.Paint() in $GOPATH/src/github.com/golang/freetype/raster/paint.go
		i0 := (s.Y-r.im.Rect.Min.Y)*r.im.Stride + (s.X0-r.im.Rect.Min.X)*4
		i1 := i0 + (s.X1-s.X0)*4
		for i, x := i0, x0; i < i1; i, x = i+4, x+1 {
			ma := s.Alpha
			if r.mask != nil {
				ma = ma * uint32(r.mask.AlphaAt(x, y).A) / 255
				if ma == 0 {
					continue
				}
			}
			c := r.p.ColorAt(x, y)
			cr, cg, cb, ca := c.RGBA()
			dr := uint32(r.im.Pix[i+0])
			dg := uint32(r.im.Pix[i+1])
			db := uint32(r.im.Pix[i+2])
			da := uint32(r.im.Pix[i+3])
			a := (m - (ca * ma / m)) * 0x101
			r.im.Pix[i+0] = uint8((dr*a + cr*ma) / m >> 8)
			r.im.Pix[i+1] = uint8((dg*a + cg*ma) / m >> 8)
			r.im.Pix[i+2] = uint8((db*a + cb*ma) / m >> 8)
			r.im.Pix[i+3] = uint8((da*a + ca*ma) / m >> 8)
		}
	}
}
978005
func NewEncoder(w io.Writer) *Encoder {
	if w, ok := w.(FlushWriter); ok {
		return &Encoder{w}
	}

	return &Encoder{noopFlusher{w}}
}
597953
func New(width, height int, fillColor color.Color) *image.NRGBA {
	if width <= 0 || height <= 0 {
		return &image.NRGBA{}
	}

	c := color.NRGBAModel.Convert(fillColor).(color.NRGBA)
	if (c == color.NRGBA{0, 0, 0, 0}) {
		return image.NewNRGBA(image.Rect(0, 0, width, height))
	}

	return &image.NRGBA{
		Pix:    bytes.Repeat([]byte{c.R, c.G, c.B, c.A}, width*height),
		Stride: 4 * width,
		Rect:   image.Rect(0, 0, width, height),
	}
}
460436
func NewPrinter(w io.Writer, c *Config) *Printer {
	return &Printer{
		w: w,
		c: mergeConfig(c),
	}
}
1299000
func NewWorker(opt WorkerOpt) (*Worker, error) {
	imageRefChecker := imagerefchecker.New(imagerefchecker.Opt{
		ImageStore:   opt.ImageStore,
		Snapshotter:  opt.Snapshotter,
		ContentStore: opt.ContentStore,
	})

	cm, err := cache.NewManager(cache.ManagerOpt{
		Snapshotter:     opt.Snapshotter,
		MetadataStore:   opt.MetadataStore,
		PruneRefChecker: imageRefChecker,
	})
	if err != nil {
		return nil, err
	}

	sm, err := source.NewManager()
	if err != nil {
		return nil, err
	}

	is, err := containerimage.NewSource(containerimage.SourceOpt{
		Snapshotter:   opt.Snapshotter,
		ContentStore:  opt.ContentStore,
		Applier:       opt.Applier,
		ImageStore:    opt.ImageStore,
		CacheAccessor: cm,
		ResolverOpt:   opt.ResolveOptionsFunc,
	})
	if err != nil {
		return nil, err
	}

	sm.Register(is)

	if err := git.Supported(); err == nil {
		gs, err := git.NewSource(git.Opt{
			CacheAccessor: cm,
			MetadataStore: opt.MetadataStore,
		})
		if err != nil {
			return nil, err
		}
		sm.Register(gs)
	} else {
		logrus.Warnf("git source cannot be enabled: %v", err)
	}

	hs, err := http.NewSource(http.Opt{
		CacheAccessor: cm,
		MetadataStore: opt.MetadataStore,
	})
	if err != nil {
		return nil, err
	}

	sm.Register(hs)

	ss, err := local.NewSource(local.Opt{
		CacheAccessor: cm,
		MetadataStore: opt.MetadataStore,
	})
	if err != nil {
		return nil, err
	}
	sm.Register(ss)

	iw, err := imageexporter.NewImageWriter(imageexporter.WriterOpt{
		Snapshotter:  opt.Snapshotter,
		ContentStore: opt.ContentStore,
		Applier:      opt.Applier,
		Differ:       opt.Differ,
	})
	if err != nil {
		return nil, err
	}

	return &Worker{
		WorkerOpt:     opt,
		CacheManager:  cm,
		SourceManager: sm,
		imageWriter:   iw,
		ImageSource:   is,
	}, nil
}
683074
func New(fs http.FileSystem, opts ...Option) (*Renderer, error) {
	r := &Renderer{
		assets:    fs,
		bufpool:   bpool.NewBufferPool(64),
		templates: make(map[string]*template.Template),
	}

	for i, o := range opts {
		if err := o(r); err != nil {
			return nil, errors.Wrapf(err, "render: option %d failed.", i)
		}
	}

	// todo defaults
	if r.log == nil {
		r.log = logging.Logger("render")
	}

	if len(r.baseTemplates) == 0 {
		r.baseTemplates = []string{"base.tmpl"}
	}
	return r, r.parseHTMLTemplates()
}
1009227
func New(opts render.Options, manifest map[string]string) Renderer {
	return &Render{
		Render:         render.New(opts),
		assetsManifest: manifest,
	}
}
667445
func NewWriter(w io.Writer) *Writer {
	return &Writer{
		w:   w,
		ctx: context.Background(),
	}
}
54249
func NewExporter(opts ...Option) (*Exporter, error) {
	c := defaultConfig()
	for _, opt := range opts {
		opt(c)
	}

	tracer := lightstep.NewTracer(c.tracerOptions)
	if tracer == nil {
		if err := c.tracerOptions.Validate(); err != nil {
			return nil, err
		}
		return nil, ErrFailedToCreateExporter
	}

	return &Exporter{
		tracer: tracer,
	}, nil
}
431551
func NewColour(r, g, b uint8) Colour {
	return ParseColour(fmt.Sprintf("%02x%02x%02x", r, g, b))
}
393873
func NewEncoder(w io.Writer) *Encoder {
	return &Encoder{w, make([]byte, minEncode)}
}
1364426
func New(opt Opt) (exporter.Exporter, error) {
	im := &imageExporter{opt: opt}
	return im, nil
}
77094
func NewEncoder(r io.Writer) Encoder {
	enc := gob.NewEncoder(r)
	return func(r *Result) error { return enc.Encode(r) }
}
1079281
func NewEncoder() *Encoder {
	return &Encoder{cache: newCache(), regenc: make(map[reflect.Type]encoderFunc)}
}
44461
func newImageResolutionCache(imageClient imageinternalclient.ImageInterface, integratedRegistry rules.RegistryMatcher) (*imageResolutionCache, error) {
	imageCache, err := lru.New(128)
	if err != nil {
		return nil, err
	}
	return &imageResolutionCache{
		imageClient: imageClient,
		integrated:  integratedRegistry,
		cache:       imageCache,
		expiration:  time.Minute,
	}, nil
}
567280
func (t *Config) NewRenderer(manager ...driver.Manager) driver.Driver {
	tmplDir := t.TmplDir
	if len(t.Theme) > 0 {
		tmplDir = filepath.Join(tmplDir, t.Theme)
	}
	renderer := New(t.Engine, tmplDir)
	renderer.Init()
	if len(manager) > 0 {
		renderer.SetManager(manager[0])
	}
	renderer.SetContentProcessor(t.Parser())
	if t.StaticOptions != nil {
		st := t.NewStatic()
		renderer.SetFuncMap(func() map[string]interface{} {
			return st.Register(nil)
		})
		absTmplPath, err := filepath.Abs(tmplDir)
		var absFilePath string
		if err == nil {
			absFilePath, err = filepath.Abs(t.StaticOptions.Root)
		}
		if err == nil {
			if strings.HasPrefix(absFilePath, absTmplPath) {
				//如果静态文件在模板的子文件夹时，监控模板时判断静态文件更改
				renderer.MonitorEvent(st.OnUpdate())
			}
		}
	}
	return renderer
}