// Generates a color by using data given in CIE L*u*v* space, taking
// into account a given reference white. (i.e. the monitor's white)
// L* is in [0..1] and both u* and v* are in about [-1..1]
359904
func LuvWhiteRef(l, u, v float64, wref [3]float64) Color {
	return Xyz(LuvToXyzWhiteRef(l, u, v, wref))
}
295826
func (i *Image) Colourspace(c Interpretation) ([]byte, error) {
	options := Options{Interpretation: c}
	return i.Process(options)
}
940923
func ThickLineColor(renderer *sdl.Renderer, x1, y1, x2, y2, width int32, color sdl.Color) bool {
	_x1 := C.Sint16(x1)
	_y1 := C.Sint16(y1)
	_x2 := C.Sint16(x2)
	_y2 := C.Sint16(y2)
	_width := C.Uint8(width)
	_color := C.Uint32(gfxColor(color))
	return C.thickLineColor((*C.SDL_Renderer)(unsafe.Pointer(renderer)), _x1, _y1, _x2, _y2, _width, _color) == 0
}
1327767
func (c Colour) Distance(e2 Colour) float64 {
	ar, ag, ab := int64(c.Red()), int64(c.Green()), int64(c.Blue())
	br, bg, bb := int64(e2.Red()), int64(e2.Green()), int64(e2.Blue())
	rmean := (ar + br) / 2
	r := ar - br
	g := ag - bg
	b := ab - bb
	return math.Sqrt(float64((((512 + rmean) * r * r) >> 8) + 4*g*g + (((767 - rmean) * b * b) >> 8)))
}
536184
func HSLToRGB(h, s, l float64) color.RGBA {

	var r, g, b float64
	if s == 0 {
		r = l
		g = l
		b = l
	} else {
		var temp0, temp1 float64
		if l < 0.5 {
			temp0 = l * (1 + s)
		} else {
			temp0 = (l + s) - (s * l)
		}
		temp1 = 2*l - temp0

		h /= 360

		hueFn := func(v float64) float64 {
			if v < 0 {
				v++
			} else if v > 1 {
				v--
			}

			if v < 1.0/6.0 {
				return temp1 + (temp0-temp1)*6*v
			}
			if v < 1.0/2.0 {
				return temp0
			}
			if v < 2.0/3.0 {
				return temp1 + (temp0-temp1)*(2.0/3.0-v)*6
			}
			return temp1
		}

		r = hueFn(h + 1.0/3.0)
		g = hueFn(h)
		b = hueFn(h - 1.0/3.0)

	}

	outR := uint8(f64.Clamp(r*255+0.5, 0, 255))
	outG := uint8(f64.Clamp(g*255+0.5, 0, 255))
	outB := uint8(f64.Clamp(b*255+0.5, 0, 255))

	return color.RGBA{outR, outG, outB, 0xFF}
}
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
}
104001
func (c Colorize) Printf(format string, v ...interface{}) (int, error) {
	return Printf(c.Foreground, c.Background, format, v...)
}
350102
func normaliseColour(colour string) string {
	if ansi, ok := ANSI2RGB[colour]; ok {
		return ansi
	}
	if strings.HasPrefix(colour, "#") {
		colour = colour[1:]
		if len(colour) == 3 {
			return colour[0:1] + colour[0:1] + colour[1:2] + colour[1:2] + colour[2:3] + colour[2:3]
		}
	}
	return colour
}
965997
func (l *Slog) Colors(b bool) *Slog {
	l = l.copy()
	l.colors = b
	l.au = aurora.NewAurora(b)
	return l
}
1310146
func leadingWhitespaceLen(in string) (n int) {
	for _, ch := range in {
		if ch == ' ' || ch == '\t' {
			n++
		} else {
			break
		}
	}
	return
}
611167
func Xyy(x, y, Y float64) Color {
	return Xyz(XyyToXyz(x, y, Y))
}
313104
func CheckerColor(colorA color.Color, colorB color.Color, size uint) ColorFunc {
	return func(n int, x int, y int, maxN int, maxX int, maxY int) color.Color {
		if ((uint(x)/size)+(uint(y)/size))%2 == 0 {
			return colorA
		}

		return colorB
	}
}
430826
func HclWhiteRef(h, c, l float64, wref [3]float64) Color {
	L, a, b := HclToLab(h, c, l)
	return LabWhiteRef(L, a, b, wref)
}
1102631
func (p *Pattern) generateBackground() {
	var rgb, color colorful.Color

	if p.Color != "" {
		rgb, _ = colorful.Hex(p.Color)
	} else {
		hueOffset := utils.Map(utils.HexVal(p.Hash, 14, 3), 0, 4095, 0, 359)
		satOffset := utils.Map(utils.HexVal(p.Hash, 17, 1), 0, 15, -1, 1)

		if p.BaseColor == "" {
			color, _ = colorful.Hex(utils.BaseColor)
		} else {
			color, _ = colorful.Hex(p.BaseColor)
		}

		h, c, l := color.Hcl()

		h -= hueOffset
		if satOffset >= 0 {
			c += float64(satOffset)
		} else {
			c -= float64(satOffset)
		}

		rgb = colorful.Color{h, c, l}
	}

	r, g, b := int(rgb.R*105), int(rgb.G*105), int(rgb.B*150)

	args := make(map[string]interface{})
	args["fill"] = fmt.Sprintf("rgb(%v, %v, %v)", r, g, b)

	p.Svg.Rect(0, 0, "100%", "100%", args)
}
156749
func (col Color) Hsv() (h, s, v float64) {
	min := math.Min(math.Min(col.R, col.G), col.B)
	v = math.Max(math.Max(col.R, col.G), col.B)
	C := v - min

	s = 0.0
	if v != 0.0 {
		s = C / v
	}

	h = 0.0 // We use 0 instead of undefined as in wp.
	if min != v {
		if v == col.R {
			h = math.Mod((col.G-col.B)/C, 6.0)
		}
		if v == col.G {
			h = (col.B-col.R)/C + 2.0
		}
		if v == col.B {
			h = (col.R-col.G)/C + 4.0
		}
		h *= 60.0
		if h < 0.0 {
			h += 360.0
		}
	}
	return
}
695756
func (rr *rasterRenderer) Fill() {
	rr.gc.SetFillColor(rr.s.FillColor)
	rr.gc.Fill()
}
270715
func LabWhiteRef(l, a, b float64, wref [3]float64) Color {
	return Xyz(LabToXyzWhiteRef(l, a, b, wref))
}