本文整理匯總了Golang中image/color.RGBA類的典型用法代碼示例。如果您正苦於以下問題:Golang RGBA類的具體用法?Golang RGBA怎麽用?Golang RGBA使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了RGBA類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: superSampling
func superSampling(inputImage image.Image) image.Image {
rect := inputImage.Bounds()
width := rect.Size().X
height := rect.Size().Y
rect2 := image.Rect(rect.Min.X, rect.Min.Y, rect.Max.X-1, rect.Max.Y-1)
rgba := image.NewRGBA(rect2)
for x := 0; x < width-1; x++ {
for y := 0; y < height-1; y++ {
var col color.RGBA
// 座標(x,y)のR, G, B, α の値を取得
r00, g00, b00, a00 := inputImage.At(x, y).RGBA()
r01, g01, b01, a01 := inputImage.At(x, y+1).RGBA()
r10, g10, b10, a10 := inputImage.At(x+1, y).RGBA()
r11, g11, b11, a11 := inputImage.At(x+1, y+1).RGBA()
col.R = uint8((uint(uint8(r00)) + uint(uint8(r01)) + uint(uint8(r10)) + uint(uint8(r11))) / 4)
col.G = uint8((uint(uint8(g00)) + uint(uint8(g01)) + uint(uint8(g10)) + uint(uint8(g11))) / 4)
col.B = uint8((uint(uint8(b00)) + uint(uint8(b01)) + uint(uint8(b10)) + uint(uint8(b11))) / 4)
col.A = uint8((uint(uint8(a00)) + uint(uint8(a01)) + uint(uint8(a10)) + uint(uint8(a11))) / 4)
rgba.Set(x, y, col)
}
}
return rgba.SubImage(rect)
}
示例2: init_calc
func init_calc(x, y int) color.RGBA {
//t_ray ray
var x1, y1, z1 float32
var pixel color.RGBA
pixel.R = 255
pixel.A = 255
x1 = float32(D)
y1 = float32((WinX / 2) - x)
z1 = float32((WinY / 2) - y)
/*
ray.Vx = x1 - eye->pos.X;
ray.Vy = y1 - eye->pos.Y;
ray.Vz = z1 - eye->pos.Z;
ray.top_mesh = llist;
ray.top_spot = spot;
ray.bool = 1;
rotate_x(&ray.Vx, &ray.Vy, &ray.Vz, -eye->rot.X);
rotate_y(&ray.Vx, &ray.Vy, &ray.Vz, -eye->rot.Y);
rotate_z(&ray.Vx, &ray.Vy, &ray.Vz, -eye->rot.Z);
color = calc(eye, llist, spot, &ray);
*/
return pixel
}
示例3: findMainColor
func (cf *ColorFinder) findMainColor(colorMap *map[color.RGBA]colorStats, shift uint, targetColor *shiftedRGBA) shiftedRGBA {
colorWeights := make(map[shiftedRGBA]float64)
bounds := cf.img.Bounds()
stepLength := stepLength(bounds)
for y := bounds.Min.Y; y < bounds.Max.Y; y += stepLength {
for x := bounds.Min.X; x < bounds.Max.X; x += stepLength {
r, g, b, a := cf.img.At(x, y).RGBA()
color := color.RGBA{}
color.R = uint8(r >> shiftRGB)
color.G = uint8(g >> shiftRGB)
color.B = uint8(b >> shiftRGB)
color.A = uint8(a >> shiftRGB)
if rgbMatchesTargetColor(targetColor, &color) {
increaseColorWeight(&colorWeights, colorMap, &color, shift)
}
}
}
maxColor := shiftedRGBA{}
maxWeight := 0.0
for sRGB, weight := range colorWeights {
if weight > maxWeight {
maxColor = sRGB
maxWeight = weight
}
}
return maxColor
}
示例4: colorForPixel
func colorForPixel(isBlack bool) color.RGBA {
col := color.RGBA{}
if isBlack {
col.A = 255
}
return col
}
示例5: buildColorMap
func (cf *ColorFinder) buildColorMap() *map[color.RGBA]colorStats {
colorMap := make(map[color.RGBA]colorStats)
bounds := cf.img.Bounds()
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
for x := bounds.Min.X; x < bounds.Max.X; x++ {
r, g, b, a := cf.img.At(x, y).RGBA()
rgb := color.RGBA{}
rgb.R = uint8(r >> shiftRGB)
rgb.G = uint8(g >> shiftRGB)
rgb.B = uint8(b >> shiftRGB)
rgb.A = uint8(a >> shiftRGB)
colrStats, exist := colorMap[rgb]
if exist {
colrStats.count++
} else {
colrStats := colorStats{count: 1, weight: weight(&rgb)}
if colrStats.weight <= 0 {
colrStats.weight = 1e-10
}
colorMap[rgb] = colrStats
}
}
}
return &colorMap
}
示例6: TestColor
func (s *S) TestColor(c *check.C) {
for r := 0; r < 256; r += 5 {
for g := 0; g < 256; g += 5 {
for b := 0; b < 256; b += 5 {
col := color.RGBA{uint8(r), uint8(g), uint8(b), 0}
cDirectR, cDirectG, cDirectB, cDirectA := col.RGBA()
hsva := RGBAtoHSVA(col.RGBA())
c.Check(hsva.H, floatWithinRange, float64(0), float64(360))
c.Check(hsva.S, floatWithinRange, float64(0), float64(1))
c.Check(hsva.V, floatWithinRange, float64(0), float64(1))
cFromHSVR, cFromHSVG, cFromHSVB, cFromHSVA := hsva.RGBA()
c.Check(cFromHSVR, uintWithinRange, uint32(0), uint32(0xFFFF))
c.Check(cFromHSVG, uintWithinRange, uint32(0), uint32(0xFFFF))
c.Check(cFromHSVB, uintWithinRange, uint32(0), uint32(0xFFFF))
back := RGBAtoHSVA(color.RGBA{uint8(cFromHSVR >> 8), uint8(cFromHSVG >> 8), uint8(cFromHSVB >> 8), uint8(cFromHSVA)}.RGBA())
c.Check(hsva, check.Equals, back)
c.Check(cFromHSVR, withinEpsilon, cDirectR, e)
c.Check(cFromHSVG, withinEpsilon, cDirectG, e)
c.Check(cFromHSVB, withinEpsilon, cDirectB, e)
c.Check(cFromHSVA, check.Equals, cDirectA)
if c.Failed() {
return
}
}
}
}
}
示例7: main
func main() {
img := shapes.FilledImage(500, 300, image.White)
fill := color.RGBA{200, 200, 200, 255}
for i := 0; i < 10; i++ {
width, height := 50+(20*i), 30+(10*i)
rect, err := shapes.New("rectangle", shapes.Option{Fill: fill, Rect: image.Rect(0, 0, width, height), Filled: true})
if err != nil {
log.Fatal(err)
}
x := 10 + (20 * i)
for j := i / 2; j >= 0; j-- {
rect.Draw(img, x+j, (x/2)+j)
}
fill.R -= uint8(i * 5)
fill.G = fill.R
fill.B = fill.R
}
shapes.SaveImage(img, "rectangle.png")
}
示例8: RGBA
func (c attrColor) RGBA() (r, g, b, a uint32) {
switch termbox.Attribute(c) {
case termbox.ColorBlack:
return 0, 0, 0, math.MaxUint16
case termbox.ColorRed:
return math.MaxUint16, 0, 0, math.MaxUint16
case termbox.ColorGreen:
return 0, math.MaxUint16, 0, math.MaxUint16
case termbox.ColorYellow:
return math.MaxUint16, math.MaxUint16, 0, math.MaxUint16
case termbox.ColorBlue:
return 0, 0, math.MaxUint16, math.MaxUint16
case termbox.ColorMagenta:
return math.MaxUint16, 0, math.MaxUint16, math.MaxUint16
case termbox.ColorCyan:
return 0, math.MaxUint16, math.MaxUint16, math.MaxUint16
case termbox.ColorWhite:
return math.MaxUint16, math.MaxUint16, math.MaxUint16, math.MaxUint16
}
switch {
case c >= 16 && c <= 231:
c -= 16
rgba := color.RGBA{R: base[(c/36)%6], G: base[(c/6)%6], B: base[c%6], A: 0xff}
return rgba.RGBA()
case c >= 232 && c <= 255:
x := uint8(0x08 + 0xa*(c-232))
rgba := color.RGBA{R: x, G: x, B: x, A: 0xff}
return rgba.RGBA()
}
panic("not found")
}
示例9: FromSliceChans
// Convert a []float64 to an image, reading data with the format specified in
// chans (e.g. RGBA, BGRA, BRG, RRR). If a component is not specified in the
func FromSliceChans(img *Image, chans string, fill float64, data []float64) {
surf := img.Surf
cm := surf.ColorModel()
b := surf.Bounds()
minX, maxX := b.Min.X, b.Max.X
minY, maxY := b.Min.Y, b.Max.Y
k := 0
nc := len(chans)
const mk = 0xff
dfill := clamp8(fill) & mk
for i := minY; i < maxY; i++ {
for j := minX; j < maxX; j++ {
outCol := color.RGBA{dfill, dfill, dfill, dfill}
for c := 0; c < nc; c++ {
switch chans[c] {
case 'r', 'R':
outCol.R = clamp8(data[k+c]) & mk
case 'g', 'G':
outCol.G = clamp8(data[k+c]) & mk
case 'b', 'B':
outCol.B = clamp8(data[k+c]) & mk
case 'a', 'A':
outCol.A = clamp8(data[k+c]) & mk
default:
// Just skip the channel
}
}
k += nc
img.Surf.Set(j, i, cm.Convert(outCol))
}
}
}
示例10: Complementary
// Return the complementary color
func Complementary(v color.RGBA) [2]color.RGBA {
var result color.RGBA
result.R = 255 - v.R
result.G = 255 - v.G
result.B = 255 - v.B
result.A = v.A
return [2]color.RGBA{v, result}
}
示例11: Apply
// Apply the given color mapping to the specified image buffers.
func Apply(from, to *Rule, src, dst draw.Image) {
var x, y int
var r, g, b, a uint32
var sc color.Color
var dc color.RGBA
var pix pixel
rect := src.Bounds()
for y = 0; y < rect.Dy(); y++ {
for x = 0; x < rect.Dx(); x++ {
sc = src.At(x, y)
r, g, b, a = sc.RGBA()
pix.r = uint8(r >> 8)
pix.g = uint8(g >> 8)
pix.b = uint8(b >> 8)
pix.a = uint8(a >> 8)
// Check if the pixel matches the filter rule.
if !(match(pix.r, from.R) && match(pix.g, from.G) && match(pix.b, from.B) && match(pix.a, from.A)) {
dst.Set(x, y, sc)
continue
}
// Compute three different types of grayscale conversion.
// These can be applied by named references.
pix.average = uint8(((r + g + b) / 3) >> 8)
pix.lightness = uint8(((min(min(r, g), b) + max(max(r, g), b)) / 2) >> 8)
// For luminosity it is necessary to apply an inverse of the gamma
// function for the color space before calculating the inner product.
// Then you apply the gamma function to the reduced value. Failure to
// incorporate the gamma function can result in errors of up to 20%.
//
// For typical computer stuff, the color space is sRGB. The right
// numbers for sRGB are approx. 0.21, 0.72, 0.07. Gamma for sRGB
// is a composite function that approximates exponentiation by 1/2.2
//
// This is a rather expensive operation, but gives a much more accurate
// and satisfactory result than the average and lightness versions.
pix.luminosity = gammaSRGB(
0.212655*invGammaSRGB(pix.r) +
0.715158*invGammaSRGB(pix.g) +
0.072187*invGammaSRGB(pix.b))
// Transform color.
dc.R = transform(&pix, pix.r, to.R)
dc.G = transform(&pix, pix.g, to.G)
dc.B = transform(&pix, pix.b, to.B)
dc.A = transform(&pix, pix.a, to.A)
// Set new pixel.
dst.Set(x, y, dc)
}
}
}
示例12: setAlpha
func setAlpha(c color.RGBA, a uint8) color.RGBA {
if c.A == 0 {
return c
}
c.R = mult(c.R, a, c.A)
c.G = mult(c.G, a, c.A)
c.B = mult(c.B, a, c.A)
c.A = a
return c
}
示例13: TestColor
func TestColor(t *testing.T) {
for r := 0; r < 256; r += 5 {
for g := 0; g < 256; g += 5 {
for b := 0; b < 256; b += 5 {
col := color.RGBA{uint8(r), uint8(g), uint8(b), 0}
cDirectR, cDirectG, cDirectB, cDirectA := col.RGBA()
hsva := rgbaToHsva(col.RGBA())
if hsva.H < 0 || hsva.H > 1 {
t.Errorf("unexpected values for H: want [0, 1] got:%f", hsva.H)
}
if hsva.S < 0 || hsva.S > 1 {
t.Errorf("unexpected values for S: want [0, 1] got:%f", hsva.S)
}
if hsva.V < 0 || hsva.V > 1 {
t.Errorf("unexpected values for V: want [0, 1] got:%f", hsva.V)
}
cFromHSVR, cFromHSVG, cFromHSVB, cFromHSVA := hsva.RGBA()
if cFromHSVR < 0 || cFromHSVR > 0xFFFF {
t.Errorf("unexpected values for H: want [0x0, 0xFFFF] got:%f", hsva.H)
}
if cFromHSVG < 0 || cFromHSVG > 0xFFFF {
t.Errorf("unexpected values for S: want [0x0, 0xFFFF] got:%f", hsva.S)
}
if cFromHSVB < 0 || cFromHSVB > 0xFFFF {
t.Errorf("unexpected values for V: want [0x0, 0xFFFF] got:%f", hsva.V)
}
if cFromHSVA < 0 || cFromHSVA > 0xFFFF {
t.Errorf("unexpected values for V: want [0x0, 0xFFFF] got:%f", hsva.V)
}
back := rgbaToHsva(color.RGBA{uint8(cFromHSVR >> 8), uint8(cFromHSVG >> 8), uint8(cFromHSVB >> 8), uint8(cFromHSVA)}.RGBA())
if hsva != back {
t.Errorf("roundtrip error: got:%#v want:%#v", back, hsva)
}
const epsilon = 1
if !withinEpsilon(cFromHSVR, cDirectR, epsilon) {
t.Errorf("roundtrip error for R: got:%d want:%d", cFromHSVR, cDirectR)
}
if !withinEpsilon(cFromHSVG, cDirectG, epsilon) {
t.Errorf("roundtrip error for G: got:%d want:%d %d", cFromHSVG, cDirectG, cFromHSVG-cDirectG)
}
if !withinEpsilon(cFromHSVB, cDirectB, epsilon) {
t.Errorf("roundtrip error for B: got:%d want:%d", cFromHSVB, cDirectB)
}
if cFromHSVA != cDirectA {
t.Errorf("roundtrip error for A: got:%d want:%d", cFromHSVA, cDirectA)
}
if t.Failed() {
return
}
}
}
}
}
示例14: DistanceBetweenColors
func DistanceBetweenColors(color1, color2 color.RGBA) float64 {
r1, g1, b1, _ := color1.RGBA()
r2, g2, b2, _ := color2.RGBA()
rDiff := math.Pow(lolDiff(r1, r2), 2.0)
gDiff := math.Pow(lolDiff(g1, g2), 2.0)
bDiff := math.Pow(lolDiff(b1, b2), 2.0)
sum := rDiff + gDiff + bDiff
return math.Sqrt(sum)
}
示例15: SetAll
// SetAll sets the given values for the channels
func (d *Dioder) SetAll(colorSet color.RGBA) {
d.ColorConfiguration = colorSet
//Red
colorSet.R = calculateOpacity(colorSet.R, colorSet.A)
d.SetChannelInteger(colorSet.R, d.PinConfiguration.Red)
//Green
colorSet.G = calculateOpacity(colorSet.G, colorSet.A)
d.SetChannelInteger(colorSet.G, d.PinConfiguration.Green)
//Blue
colorSet.B = calculateOpacity(colorSet.B, colorSet.A)
d.SetChannelInteger(colorSet.B, d.PinConfiguration.Blue)
}