當前位置: 首頁>>代碼示例>>Golang>>正文


Golang color.Color類代碼示例

本文整理匯總了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
}
開發者ID:billyboar,項目名稱:GCSolutions,代碼行數:7,代碼來源:image.go

示例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))
}
開發者ID:quarnster,項目名稱:go-qt5,代碼行數:7,代碼來源:cdrv.go

示例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)
}
開發者ID:nolenroyalty,項目名稱:bangarang,代碼行數:8,代碼來源:vgsvg.go

示例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)
}
開發者ID:anthonyrego,項目名稱:gosmf,代碼行數:31,代碼來源:font.go

示例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)}
}
開發者ID:gaspiman,項目名稱:go,代碼行數:10,代碼來源:convert.go

示例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)
	}
}
開發者ID:errnoh,項目名稱:wde.buffer,代碼行數:7,代碼來源:buffer_test.go

示例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))
}
開發者ID:drewp,項目名稱:homeauto,代碼行數:8,代碼來源:colorhex.go

示例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)
}
開發者ID:jbrukh,項目名稱:decrazifier,代碼行數:8,代碼來源:algo.go

示例9: luma

func luma(pixel color.Color) float64 {
	r, g, b, _ := pixel.RGBA()

	return .2126*float64(r) +
		.7152*float64(g) +
		.0722*float64(b)
}
開發者ID:awans,項目名稱:pixelsort,代碼行數:7,代碼來源:pixelsort.go

示例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)}
}
開發者ID:edvakf,項目名稱:go-libjpeg,代碼行數:7,代碼來源:rgb.go

示例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
}
開發者ID:kvanbiesen,項目名稱:gocupi,代碼行數:8,代碼來源:image.go

示例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)}
}
開發者ID:rsaarelm,項目名稱:teratogen,代碼行數:7,代碼來源:color.go

示例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)}
}
開發者ID:kodabb,項目名稱:image2,代碼行數:7,代碼來源:rgb.go

示例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))
	}
}
開發者ID:matiwinnetou,項目名稱:engi,代碼行數:7,代碼來源:engo.go

示例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))
}
開發者ID:jasonrpowers,項目名稱:glh,代碼行數:7,代碼來源:util.go


注:本文中的image/color.Color類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。