本文整理匯總了Golang中image/color.Color類的典型用法代碼示例。如果您正苦於以下問題:Golang Color類的具體用法?Golang Color怎麽用?Golang Color使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Color類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Add
func (c *RGBA128) Add(rhs color.Color) {
r, g, b, a := rhs.RGBA()
c.R += r
c.G += g
c.B += b
c.A += a
}
示例2: make_rgba
func make_rgba(c color.Color) rgba {
if c == nil {
return 0
}
r, g, b, a := c.RGBA()
return rgba(((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff))
}
示例3: opacityString
// opacityString returns the opacity value of the given color.
func opacityString(clr color.Color) string {
if clr == nil {
clr = color.Black
}
_, _, _, a := clr.RGBA()
return fmt.Sprintf("%.*g", pr, float64(a)/math.MaxUint16)
}
示例4: updateTexture
func (font *Font) updateTexture(texture uint32, text string, width int, height int, size float64, dpi float64, rgba color.Color) (int, int) {
context := freetype.NewContext()
context.SetFont(font.ttf)
img := image.NewRGBA(image.Rect(0, 0, width, height))
r, g, b, _ := rgba.RGBA()
draw.Draw(img, img.Bounds(), image.NewUniform(color.RGBA{uint8(r), uint8(g), uint8(b), 0}), image.ZP, draw.Src)
context.SetDst(img)
context.SetClip(img.Bounds())
context.SetSrc(image.NewUniform(rgba))
context.SetFontSize(size)
context.SetDPI(dpi)
pixelBounds, _ := context.DrawString(text, freetype.Pt(0, height/2))
gl.ActiveTexture(gl.TEXTURE0)
gl.BindTexture(gl.TEXTURE_2D, texture)
gl.TexSubImage2D(
gl.TEXTURE_2D,
0,
0,
0,
int32(img.Rect.Size().X),
int32(img.Rect.Size().Y),
gl.RGBA,
gl.UNSIGNED_BYTE,
gl.Ptr(img.Pix))
return int26_6Ceiling(pixelBounds.X + 0x3f), int26_6Ceiling(pixelBounds.Y + 0x3f)
}
示例5: ToGrayLightness
// ToGrayLightness converts color.Color c to grayscale using the lightness.
//
// The formula used for conversion is: Y = (max(r,g,b) + min(r,g,b)) / 2.
func ToGrayLightness(c color.Color) color.Gray {
r, g, b, _ := c.RGBA()
max := max(r, max(g, b))
min := min(r, min(g, b))
Y := (10*(min+max) + 5) / 20
return color.Gray{uint8(Y >> 8)}
}
示例6: colorcheck
func colorcheck(t *testing.T, current, target color.Color) {
r1, g1, b1, a1 := current.RGBA()
r2, g2, b2, a2 := target.RGBA()
if r1 != r2 || g1 != g2 || b1 != b2 || a1 != a2 {
t.Errorf("Got [%d %d %d %d], expected [%d %d %d %d]", r1>>8, g1>>8, b1>>8, a1>>8, r2>>8, g2>>8, b2>>8, a2>>8)
}
}
示例7: hexModel
// hexModel converts a Color to Hex.
func hexModel(c color.Color) color.Color {
if _, ok := c.(Hex); ok {
return c
}
r, g, b, _ := c.RGBA()
return RGBToHex(uint8(r>>8), uint8(g>>8), uint8(b>>8))
}
示例8: Distance
// calculates the Euclidean distance between two colors
func Distance(c1, c2 color.Color) float64 {
r1, g1, b1, a1 := c1.RGBA()
r2, g2, b2, a2 := c2.RGBA()
sum := float64(uint64((r1-r2)*(r1-r2)) + uint64((g1-g2)*(g1-g2)) +
uint64((b1-b2)*(b1-b2)) + uint64((a1-a2)*(a1-a2)))
return math.Sqrt(sum)
}
示例9: luma
func luma(pixel color.Color) float64 {
r, g, b, _ := pixel.RGBA()
return .2126*float64(r) +
.7152*float64(g) +
.0722*float64(b)
}
示例10: rgbModel
func rgbModel(c color.Color) color.Color {
if _, ok := c.(RGB); ok {
return c
}
r, g, b, _ := c.RGBA()
return RGB{uint8(r >> 8), uint8(g >> 8), uint8(b >> 8)}
}
示例11: average
// Returns an average of R,G,B from 0 to 1
func average(pixelColor color.Color) float64 {
r, g, b, _ := pixelColor.RGBA()
//fmt.Println("Sampling", r, g, b)
return (float64(r)/65535.0 + float64(g)/65535.0 + float64(b)/65535.0) / 3.0
}
示例12: ScaleCol
func ScaleCol(col color.Color, scale float64) (result color.Color) {
r, g, b, a := col.RGBA()
r8 := uint8(math.Min(float64(r)*scale, 0xffff) / 256)
g8 := uint8(math.Min(float64(g)*scale, 0xffff) / 256)
b8 := uint8(math.Min(float64(b)*scale, 0xffff) / 256)
return color.RGBA{r8, g8, b8, uint8(a >> 8)}
}
示例13: rgb48Model
func rgb48Model(c color.Color) color.Color {
if _, ok := c.(RGB48); ok {
return c
}
r, g, b, _ := c.RGBA()
return RGB48{uint16(r), uint16(g), uint16(b)}
}
示例14: SetBackground
func SetBackground(c color.Color) {
if !headless {
r, g, b, a := c.RGBA()
Gl.ClearColor(float32(r), float32(g), float32(b), float32(a))
}
}
示例15: ColorC
func ColorC(c color.Color) {
if c == nil {
panic("nil color passed to ColorC")
}
r, g, b, a := c.RGBA()
gl.Color4us(uint16(r), uint16(g), uint16(b), uint16(a))
}