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


Golang RGBA.A方法代碼示例

本文整理匯總了Golang中image/color.RGBA.A方法的典型用法代碼示例。如果您正苦於以下問題:Golang RGBA.A方法的具體用法?Golang RGBA.A怎麽用?Golang RGBA.A使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在image/color.RGBA的用法示例。


在下文中一共展示了RGBA.A方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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))
		}
	}
}
開發者ID:akiross,項目名稱:gogp,代碼行數:36,代碼來源:imgops.go

示例2: 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
}
開發者ID:undernewmanagement,項目名稱:besticon,代碼行數:27,代碼來源:colorfinder.go

示例3: 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)
}
開發者ID:Esper0328,項目名稱:Go_training,代碼行數:25,代碼來源:main.go

示例4: mapToColor

func mapToColor(o map[string]interface{}) color.Color {
	var c color.RGBA

	// Because JavaScript
	switch x := o["r"].(type) {
	case int64:
		c.R = uint8(colorF(float64(x)))
	case float64:
		c.R = uint8(colorF(x))
	}
	switch x := o["g"].(type) {
	case int64:
		c.G = uint8(colorF(float64(x)))
	case float64:
		c.G = uint8(colorF(x))
	}
	switch x := o["b"].(type) {
	case int64:
		c.B = uint8(colorF(float64(x)))
	case float64:
		c.B = uint8(colorF(x))
	}
	c.A = 0xff
	return c
}
開發者ID:surma-dump,項目名稱:gophernamedray,代碼行數:25,代碼來源:compparser.go

示例5: 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
}
開發者ID:undernewmanagement,項目名稱:besticon,代碼行數:32,代碼來源:colorfinder.go

示例6: colorForPixel

func colorForPixel(isBlack bool) color.RGBA {
	col := color.RGBA{}
	if isBlack {
		col.A = 255
	}
	return col
}
開發者ID:paukul,項目名稱:visual_cryptography,代碼行數:7,代碼來源:foo.go

示例7: 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
}
開發者ID:thomas-miele,項目名稱:raygo,代碼行數:27,代碼來源:raytracer.go

示例8: 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}
}
開發者ID:internet-research-labs,項目名稱:go-color,代碼行數:9,代碼來源:ColorHarmony.go

示例9: 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)
		}
	}
}
開發者ID:jteeuwen,項目名稱:imgtools,代碼行數:58,代碼來源:apply.go

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

示例11: parseColors

func parseColors(args []*ast.BasicLit) (color.RGBA, error) {
	ints := make([]uint8, 4)
	var ret color.RGBA
	var u uint8
	for i := range args {
		v := args[i]
		switch v.Kind {
		case token.FLOAT:
			f, err := strconv.ParseFloat(args[i].Value, 8)
			if err != nil {
				return ret, err
			}
			// Has to be alpha, or bust
			u = uint8(f * 100)
		case token.INT:
			i, err := strconv.Atoi(v.Value)
			if err != nil {
				return ret, err
			}
			u = uint8(i)
		case token.COLOR:
			if i != 0 {
				return ret, fmt.Errorf("hex is only allowed as the first argumetn found: % #v", v)
			}
			var err error
			ret, err = ast.ColorFromHexString(v.Value)
			if err != nil {
				return ret, err
			}
			// This is only allowed as the first argument
			i = i + 2
		default:
			log.Fatalf("unsupported kind %s % #v\n", v.Kind, v)
		}
		ints[i] = u
	}
	if ints[0] > 0 {
		ret.R = ints[0]
	}
	if ints[1] > 0 {
		ret.G = ints[1]
	}
	if ints[2] > 0 {
		ret.B = ints[2]
	}
	if ints[3] > 0 {
		ret.A = ints[3]
	}
	return ret, nil
}
開發者ID:wellington,項目名稱:sass,代碼行數:50,代碼來源:rgb.go

示例12: blend

func blend(orig image.Image) (m image.Image) {
	// deviation range
	dev := uint16(50 << 8)

	c := new(color.RGBA)
	c.A = 255

	bounds := orig.Bounds()

	// iterations
	for i := 0; i < 10; i++ {
		newm := image.NewRGBA(bounds)

		for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
			for x := bounds.Min.X; x < bounds.Max.X; x++ {

				var r, g, b, ct uint32

				_r, _g, _b, _ := orig.At(x, y).RGBA()

				for i := -1; i < 2; i++ {
					for j := -1; j < 2; j++ {
						rt, gt, bt, _ := orig.At(x+i, y+j).RGBA()

						if uint16(rt-_r) > dev || uint16(gt-_g) > dev || uint16(bt-_b) > dev {
							continue
						}

						r += rt
						g += gt
						b += bt
						ct++
					}
				}
				c.R = uint8((r / ct) >> 8)
				c.G = uint8((g / ct) >> 8)
				c.B = uint8((b / ct) >> 8)

				newm.Set(x, y, c)

			}
		}

		m = newm
	}

	return
}
開發者ID:jasonmoo,項目名稱:imagine,代碼行數:48,代碼來源:imagine.go

示例13: DrawImage

func DrawImage(src image.Image, dest draw.Image, tr MatrixTransform, op draw.Op, filter ImageFilter) {
	bounds := src.Bounds()
	x0, y0, x1, y1 := float64(bounds.Min.X), float64(bounds.Min.Y), float64(bounds.Max.X), float64(bounds.Max.Y)
	tr.TransformRectangle(&x0, &y0, &x1, &y1)
	var x, y, u, v float64
	var c1, c2, cr color.Color
	var r, g, b, a, ia, r1, g1, b1, a1, r2, g2, b2, a2 uint32
	var color color.RGBA
	for x = x0; x < x1; x++ {
		for y = y0; y < y1; y++ {
			u = x
			v = y
			tr.InverseTransform(&u, &v)
			if bounds.Min.X <= int(u) && bounds.Max.X > int(u) && bounds.Min.Y <= int(v) && bounds.Max.Y > int(v) {
				c1 = dest.At(int(x), int(y))
				switch filter {
				case LinearFilter:
					c2 = src.At(int(u), int(v))
				case BilinearFilter:
					c2 = getColorBilinear(src, u, v)
				case BicubicFilter:
					c2 = getColorBicubic(src, u, v)
				}
				switch op {
				case draw.Over:
					r1, g1, b1, a1 = c1.RGBA()
					r2, g2, b2, a2 = c2.RGBA()
					ia = M - a2
					r = ((r1 * ia) / M) + r2
					g = ((g1 * ia) / M) + g2
					b = ((b1 * ia) / M) + b2
					a = ((a1 * ia) / M) + a2
					color.R = uint8(r >> 8)
					color.G = uint8(g >> 8)
					color.B = uint8(b >> 8)
					color.A = uint8(a >> 8)
					cr = color
				default:
					cr = c2
				}
				dest.Set(int(x), int(y), cr)
			}
		}
	}
}
開發者ID:nolenroyalty,項目名稱:bangarang,代碼行數:45,代碼來源:rgba_interpolation.go

示例14: linterp

// linterp performs linear interpolation between the first (p[0]) and
// the last (pal[len(p) - 1]) colors in palette "pal". It fills the
// remaining (pal[1:len(p) - 1]) palette slots with the intepolated
// colors. Colors in slots pal[0] and pal[len(p) - 1] MUST be of type
// color.RGBA. The remaining slots will also be filled with colors of
// type color.RGBA
func linterp(pal color.Palette) {
	n := len(pal)
	if n <= 2 {
		return
	}
	s, e := pal[0].(color.RGBA), pal[n-1].(color.RGBA)
	dr := int(e.R) - int(s.R)
	dg := int(e.G) - int(s.G)
	db := int(e.B) - int(s.B)
	da := int(e.A) - int(s.A)
	for i := 1; i < n-1; i++ {
		c := color.RGBA{}
		c.R = uint8(int(s.R) + i*dr/(n-1))
		c.G = uint8(int(s.G) + i*dg/(n-1))
		c.B = uint8(int(s.B) + i*db/(n-1))
		c.A = uint8(int(s.A) + i*da/(n-1))
		pal[i] = c
	}
}
開發者ID:npat-efault,項目名稱:mandel,代碼行數:25,代碼來源:palette.go

示例15: main

func main() {
	start := time.Now()

	const pictureSize = 5000
	img := image.NewRGBA(image.Rect(0, 0, pictureSize, pictureSize))

	f, err := os.OpenFile("mandel.png", os.O_WRONLY|os.O_CREATE, 0666)

	if err != nil {
		fmt.Printf("Can't create picture file\n")
	}

	deltaX := math.Abs(float64(-2.0-1.0)) / float64(pictureSize)

	deltaY := math.Abs(float64(-1.0-1.0)) / float64(pictureSize)

	cx := float64(-2.0)
	for x := 0; x < pictureSize; x++ {
		cx += deltaX
		cy := float64(-1.0)
		for y := 0; y < pictureSize; y++ {
			cy += deltaY
			iter := PointIteration(cx, cy, 255.0, 255)

			col := color.RGBA{255, iter, iter, iter}
			col.A = 255
			col.R = iter
			col.G = iter
			col.B = iter
			img.Set(x, y, col)
		}
	}

	w := bufio.NewWriter(f)
	png.Encode(w, img)
	w.Flush()

	fmt.Printf("Seconds needed %d\n", time.Now().Sub(start))
}
開發者ID:kstrempel,項目名稱:mandelgo,代碼行數:39,代碼來源:mandel.go


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