// BColor256 输出 256 色的背景颜色信息
354811
func (a *Writer) BColor256(color int) (int, error) {
	return a.WriteString(BColor256(color))
}
837099
func BgBrightYellow(arg interface{}) Value {
	if val, ok := arg.(Value); ok {
		return val.BgBrightYellow()
	}
	return value{value: arg, color: BrightBg | YellowBg}
}
946300
func AverageColor(colors ...Color) (color Color) {
	var (
		x, y               float64
		hue, sat, bri, kel int
	)

	// Sum sind/cosd for hues
	for _, c := range colors {
		// Convert hue to degrees
		h := float64(c.Hue) / float64(math.MaxUint16) * 360.0

		x += math.Cos(h / 180.0 * math.Pi)
		y += math.Sin(h / 180.0 * math.Pi)
		sat += int(c.Saturation)
		bri += int(c.Brightness)
		kel += int(c.Kelvin)
	}

	// Average sind/cosd
	x /= float64(len(colors))
	y /= float64(len(colors))

	// Take atan2 of averaged hue and convert to uint16 scale
	hue = int((math.Atan2(y, x) * 180.0 / math.Pi) / 360.0 * float64(math.MaxUint16))
	sat /= len(colors)
	bri /= len(colors)
	kel /= len(colors)

	color.Hue = uint16(hue)
	color.Saturation = uint16(sat)
	color.Brightness = uint16(bri)
	color.Kelvin = uint16(kel)

	return color
}
770941
func (be *BinaryEncoder) WriteBoolean(x bool) {
	if x {
		_, _ = be.buffer.Write([]byte{0x01})
	} else {
		_, _ = be.buffer.Write([]byte{0x00})
	}
}
500870
func BlendBgColor(dest *Image, c color.Color) {
	r := dest.Bounds()
	cr32, cg32, cb32, _ := c.RGBA()
	cr, cg, cb := uint8(cr32), uint8(cg32), uint8(cb32)

	var bgra BGRA
	var alpha float64
	for x := r.Min.X; x < r.Max.X; x++ {
		for y := r.Min.Y; y < r.Max.Y; y++ {
			bgra = dest.At(x, y).(BGRA)
			alpha = float64(bgra.A) / 255.0
			dest.SetBGRA(x, y, BGRA{
				B: blend(cb, bgra.B, alpha),
				G: blend(cg, bgra.G, alpha),
				R: blend(cr, bgra.R, alpha),
				A: 0xff,
			})
		}
	}
}
447317
func NewLolWriter() io.Writer {
	colorMode := ColorMode256
	if noColor {
		colorMode = ColorMode0
	}
	return &Writer{
		Output:    stdout,
		ColorMode: colorMode,
	}
}
1173621
func (builder *Builder) RGB8BitF(r, g, b uint8) *Builder {
	return builder.Color8BitF(NewRGB8Bit(r, g, b))
}
6587
func (w *Waveform) SetBGColorFunction(function ColorFunc) error {
	return w.SetOptions(BGColorFunction(function))
}
449380
func Sha256(b []byte) string {
	h := sha256.New()
	h.Write(b)
	return base64.StdEncoding.EncodeToString(h.Sum(nil))
}
462640
func (p *TCompactProtocol) isBoolType(b byte) bool {
	return (b&0x0f) == COMPACT_BOOLEAN_TRUE || (b&0x0f) == COMPACT_BOOLEAN_FALSE
}
974030
func (color TrueColor) Rgb() (byte, byte, byte) {
	return byte((color >> 16) & 0xFF), byte((color >> 8) & 0xFF), byte(color & 0xFF)
}
949015
func (col Color) RGBA() (r, g, b, a uint32) {
	r = uint32(col.R*65535.0 + 0.5)
	g = uint32(col.G*65535.0 + 0.5)
	b = uint32(col.B*65535.0 + 0.5)
	a = 0xFFFF
	return
}
1170321
func (col Color) RGB255() (r, g, b uint8) {
	r = uint8(col.R*255.0 + 0.5)
	g = uint8(col.G*255.0 + 0.5)
	b = uint8(col.B*255.0 + 0.5)
	return
}
695973
func (c *Frame) SetActiveFgColor(fg termbox.Attribute) {
	c.activeFg = fg
	for _, v := range c.controls {
		v.SetActiveFgColor(fg)
	}
}
1287542
func (renderer *Renderer) SetDrawColorArray(bs ...uint8) error {
	_bs := []C.Uint8{0, 0, 0, 255}
	for i := 0; i < len(_bs) && i < len(bs); i++ {
		_bs[i] = C.Uint8(bs[i])
	}
	return errorFromInt(int(
		C.SDL_SetRenderDrawColor(
			renderer.cptr(),
			_bs[0],
			_bs[1],
			_bs[2],
			_bs[3])))
}
830398
func (builder *Builder) RGB8BitB(r, g, b uint8) *Builder {
	return builder.Color8BitB(NewRGB8Bit(r, g, b))
}
199444
func b16(img *image.Paletted, x, y, size float64, angle int) {
	points := pool.Get().([]float64)[:0]
	m := size / 2
	drawBlock(img, x, y, size, angle, append(points,
		x+m, y,
		x+size, y+m,
		x, y+m,
		x+m, y,
	))

	drawBlock(img, x, y, size, angle, append(points[:0],
		x+m, y+m,
		x+size, y+size,
		x, y+size,
		x+m, y+m,
	))

	pool.Put(points)
}