// FindColorCS findcolor by CaptureScreen
436432
func FindColorCS(color CHex, x, y, w, h int, args ...float64) (int, int) {
	var tolerance = 0.01

	if len(args) > 0 {
		tolerance = args[0]
	}

	bitmap := CaptureScreen(x, y, w, h)
	rx, ry := FindColor(color, bitmap, tolerance)
	FreeBitmap(bitmap)

	return rx, ry
}
797602
func FindCols(cols []*Column, names []string) ([]*Column, error) {
	var rcols []*Column
	for _, name := range names {
		col := FindCol(cols, name)
		if col != nil {
			rcols = append(rcols, col)
		} else {
			return nil, errUnknownColumn.Gen("unknown column %s", name)
		}
	}

	return rcols, nil
}
476336
func (builder *Builder) Color8BitF(c RGB8Bit) *Builder {
	return builder.With(Color8BitF(c))
}
1004543
func (s Style) GetStrokeColor(defaults ...drawing.Color) drawing.Color {
	if s.StrokeColor.IsZero() {
		if len(defaults) > 0 {
			return defaults[0]
		}
		return drawing.ColorTransparent
	}
	return s.StrokeColor
}
911336
func OptionDescriptionBGColor(x Color) Option {
	return func(p *Prompt) error {
		p.renderer.descriptionBGColor = x
		return nil
	}
}
20027
func (cf *ColorFinder) FindMainColor(img image.Image) (color.RGBA, error) {
	cf.img = img

	colorMap := cf.buildColorMap()

	sRGB := cf.findMainColor(colorMap, 6, nil)
	sRGB = cf.findMainColor(colorMap, 4, &sRGB)
	sRGB = cf.findMainColor(colorMap, 2, &sRGB)
	sRGB = cf.findMainColor(colorMap, 0, &sRGB)

	return sRGB.rgb, nil
}
918648
func FindColor(c Color, palette []Color) Color {
	match := ColorDefault
	dist := float64(0)
	r, g, b := c.RGB()
	c1 := colorful.Color{
		R: float64(r) / 255.0,
		G: float64(g) / 255.0,
		B: float64(b) / 255.0,
	}
	for _, d := range palette {
		r, g, b = d.RGB()
		c2 := colorful.Color{
			R: float64(r) / 255.0,
			G: float64(g) / 255.0,
			B: float64(b) / 255.0,
		}
		// CIE94 is more accurate, but really really expensive.
		nd := c1.DistanceCIE76(c2)
		if math.IsNaN(nd) {
			nd = math.Inf(1)
		}
		if match == ColorDefault || nd < dist {
			match = d
			dist = nd
		}
	}
	return match
}
144858
func GetScreenDimensions() (cols int, lines int, err error) {
	ws, err := unix.IoctlGetWinsize(0, unix.TIOCGWINSZ)
	if err != nil {
		return -1, -1, err
	}
	return int(ws.Col), int(ws.Row), nil
}
383969
func getPrintCol(c col) *color.Color {
	switch c {
	case colGrey:
		return color.New(color.FgWhite, color.Bold)
	case colRed:
		return color.New(color.FgRed, color.Bold)
	case colYellow:
		return color.New(color.FgYellow, color.Bold)
	case colGreen:
		return color.New(color.FgGreen, color.Bold)
	}
	return nil
}
547978
func (mp *MockPeerCCSupport) GetCCMirror(name string) *MockCCComm {
	s := mp.ccStream[name]
	if s == nil {
		return nil
	}

	return &MockCCComm{name: name, recvStream: s.sendStream, sendStream: s.recvStream, skipClose: true}
}
656396
func (cl *CoLog) colorSupported() bool {

	// ColorSupporters can decide themselves
	if ce, ok := cl.out.(ColorSupporter); ok {
		return ce.ColorSupported()
	}

	// Windows users need ColorSupporter outputs
	if runtime.GOOS == "windows" {
		return false
	}

	// Check for Fd() method
	output, ok := cl.out.(interface {
		Fd() uintptr
	})

	// If no file descriptor it's not a TTY
	if !ok {
		return false
	}

	return isTerminal(int(output.Fd()))
}
275673
func (d *clusterDiscoveryGCE) findGCEDisks() ([]*compute.Disk, error) {
	c := d.gceCloud

	clusterTag := gce.SafeClusterName(d.clusterName)

	var matches []*compute.Disk

	ctx := context.Background()

	// TODO: Push down tag filter?

	err := c.Compute().Disks.AggregatedList(c.Project()).Pages(ctx, func(page *compute.DiskAggregatedList) error {
		for _, list := range page.Items {
			for _, d := range list.Disks {
				match := false
				for k, v := range d.Labels {
					if k == gce.GceLabelNameKubernetesCluster {
						if v == clusterTag {
							match = true
						} else {
							match = false
							break
						}
					}
				}

				if !match {
					continue
				}

				matches = append(matches, d)
			}
		}

		return nil
	})
	if err != nil {
		return nil, fmt.Errorf("error listing disks: %v", err)
	}

	return matches, nil
}
171223
func (env *joyentEnviron) FindInstanceSpec(
	ic *instances.InstanceConstraint,
	imageMetadata []*imagemetadata.ImageMetadata,
) (*instances.InstanceSpec, error) {
	// Require at least one VCPU so we get KVM rather than smart package.
	if ic.Constraints.CpuCores == nil {
		ic.Constraints.CpuCores = &defaultCpuCores
	}
	allInstanceTypes, err := env.listInstanceTypes()
	if err != nil {
		return nil, err
	}
	images := instances.ImageMetadataToImages(imageMetadata)
	spec, err := instances.FindInstanceSpec(images, ic, allInstanceTypes)
	if err != nil {
		return nil, err
	}
	return spec, nil
}
602174
func (l *LabelResult) GetColor() string {
	if l == nil || l.Color == nil {
		return ""
	}
	return *l.Color
}
2555
func HasCorrectColors(c *chronograf.DashboardCell) error {
	for _, color := range c.CellColors {
		if !oneOf(color.Type, "max", "min", "threshold", "text", "background", "scale") {
			return chronograf.ErrInvalidColorType
		}
		if len(color.Hex) != 7 {
			return chronograf.ErrInvalidColor
		}
	}
	return nil
}
119840
func (g *Group) getColor(cached bool) (common.Color, error) {
	var err error

	g.RLock()
	lastColor := g.color
	g.RUnlock()

	lights := g.Lights()

	if len(lights) == 0 {
		return lastColor, nil
	}

	colors := make([]common.Color, len(lights))

	for i, light := range lights {
		var c common.Color
		if cached {
			c = light.CachedColor()
		} else {
			c, err = light.GetColor()
			if err != nil {
				return lastColor, err
			}
		}
		colors[i] = c
	}

	g.Lock()
	g.color = common.AverageColor(colors...)
	g.Unlock()
	g.RLock()
	defer g.RUnlock()
	if !common.ColorEqual(lastColor, g.color) {
		g.Notify(common.EventUpdateColor{Color: g.color})
	}

	return g.color, nil
}
310239
func colorCode(style string) *bytes.Buffer {
	buf := bytes.NewBufferString("")
	if plain || style == "" {
		return buf
	}
	if style == "reset" {
		buf.WriteString(Reset)
		return buf
	} else if style == "off" {
		return buf
	}

	foregroundBackground := strings.Split(style, ":")
	foreground := strings.Split(foregroundBackground[0], "+")
	fgKey := foreground[0]
	fg := Colors[fgKey]
	fgStyle := ""
	if len(foreground) > 1 {
		fgStyle = foreground[1]
	}

	bg, bgStyle := "", ""

	if len(foregroundBackground) > 1 {
		background := strings.Split(foregroundBackground[1], "+")
		bg = background[0]
		if len(background) > 1 {
			bgStyle = background[1]
		}
	}

	buf.WriteString(start)
	base := normalIntensityFG
	if len(fgStyle) > 0 {
		if strings.Contains(fgStyle, "b") {
			buf.WriteString(bold)
		}
		if strings.Contains(fgStyle, "B") {
			buf.WriteString(blink)
		}
		if strings.Contains(fgStyle, "u") {
			buf.WriteString(underline)
		}
		if strings.Contains(fgStyle, "i") {
			buf.WriteString(inverse)
		}
		if strings.Contains(fgStyle, "s") {
			buf.WriteString(strikethrough)
		}
		if strings.Contains(fgStyle, "h") {
			base = highIntensityFG
		}
	}

	// if 256-color
	n, err := strconv.Atoi(fgKey)
	if err == nil {
		fmt.Fprintf(buf, "38;5;%d;", n)
	} else {
		fmt.Fprintf(buf, "%d;", base+fg)
	}

	base = normalIntensityBG
	if len(bg) > 0 {
		if strings.Contains(bgStyle, "h") {
			base = highIntensityBG
		}
		// if 256-color
		n, err := strconv.Atoi(bg)
		if err == nil {
			fmt.Fprintf(buf, "48;5;%d;", n)
		} else {
			fmt.Fprintf(buf, "%d;", base+Colors[bg])
		}
	}

	// remove last ";"
	buf.Truncate(buf.Len() - 1)
	buf.WriteRune('m')
	return buf
}