本文整理匯總了Golang中image.RGBA類的典型用法代碼示例。如果您正苦於以下問題:Golang RGBA類的具體用法?Golang RGBA怎麽用?Golang RGBA使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了RGBA類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: FillColumn
func FillColumn(imagem *image.RGBA, x, y int) {
preto := color.RGBA{0, 0, 0, 255}
for h := y; h <= 513; h++ {
imagem.Set(x, h, preto)
}
}
示例2: connect
/*
draws pixels to connect a line
*/
func (line Line) connect(img *image.RGBA) {
points := line.generatePoints()
black := color.RGBA{0, 0, 0, 255}
for _, val := range points {
img.SetRGBA(val.X, val.Y, black)
}
}
示例3: CopyRGBA
func (buffer Image) CopyRGBA(src *image.RGBA, r image.Rectangle) {
// clip r against each image's bounds and move sp accordingly (see draw.clip())
sp := image.ZP
orig := r.Min
r = r.Intersect(buffer.Bounds())
r = r.Intersect(src.Bounds().Add(orig.Sub(sp)))
dx := r.Min.X - orig.X
dy := r.Min.Y - orig.Y
(sp).X += dx
(sp).Y += dy
i0 := (r.Min.X - buffer.Rect.Min.X) * 4
i1 := (r.Max.X - buffer.Rect.Min.X) * 4
si0 := (sp.X - src.Rect.Min.X) * 4
yMax := r.Max.Y - buffer.Rect.Min.Y
y := r.Min.Y - buffer.Rect.Min.Y
sy := sp.Y - src.Rect.Min.Y
for ; y != yMax; y, sy = y+1, sy+1 {
dpix := buffer.Pix[y*buffer.Stride:]
spix := src.Pix[sy*src.Stride:]
for i, si := i0, si0; i < i1; i, si = i+4, si+4 {
dpix[i+0] = spix[si+2]
dpix[i+1] = spix[si+1]
dpix[i+2] = spix[si+0]
dpix[i+3] = spix[si+3]
}
}
}
示例4: drawCopySrc
func drawCopySrc(dst *image.RGBA, r image.Rectangle, src *image.RGBA, sp image.Point) {
n, dy := 4*r.Dx(), r.Dy()
d0 := dst.PixOffset(r.Min.X, r.Min.Y)
s0 := src.PixOffset(sp.X, sp.Y)
var ddelta, sdelta int
if r.Min.Y <= sp.Y {
ddelta = dst.Stride
sdelta = src.Stride
} else {
// If the source start point is higher than the destination start
// point, then we compose the rows in bottom-up order instead of
// top-down. Unlike the drawCopyOver function, we don't have to check
// the x coordinates because the built-in copy function can handle
// overlapping slices.
d0 += (dy - 1) * dst.Stride
s0 += (dy - 1) * src.Stride
ddelta = -dst.Stride
sdelta = -src.Stride
}
for ; dy > 0; dy-- {
copy(dst.Pix[d0:d0+n], src.Pix[s0:s0+n])
d0 += ddelta
s0 += sdelta
}
}
示例5: cloneImage
func cloneImage(i *image.RGBA) *image.RGBA {
i2 := new(image.RGBA)
*i2 = *i
i2.Pix = make([]uint8, len(i.Pix))
copy(i2.Pix, i.Pix)
return i2
}
示例6: fillPixels
func fillPixels(avatar *image.RGBA, x, y int, pixelColor color.RGBA) {
for i := x; i < x+PixelSize; i++ {
for j := y; j < y+PixelSize; j++ {
avatar.SetRGBA(i, j, pixelColor)
}
}
}
示例7: NewTiledImage
func NewTiledImage(img *image.RGBA, tileSize image.Point) *TiledImage {
b := img.Bounds()
nx := b.Dx() / tileSize.X
ny := b.Dy() / tileSize.Y
tiles := make([]TileInfo, nx*ny)
for j := 0; j < ny; j++ {
y := b.Min.Y + j*tileSize.Y
for i := 0; i < nx; i++ {
x := b.Min.X + i*tileSize.X
rect := image.Rect(x, y, x+tileSize.X, y+tileSize.Y)
k := i + j*nx
tiles[k].subImage = img.SubImage(rect).(*image.RGBA)
tiles[k].dist2 = math.MaxFloat32
}
}
return &TiledImage{
data: tiles,
nx: nx,
ny: ny,
sx: tileSize.X,
sy: tileSize.Y,
}
}
示例8: fillRect
// Fills a rectangle in the specified rgba with the given color.
func fillRect(rgba *image.RGBA, rect image.Rectangle, color color.Color) {
for x := rect.Min.X; x <= rect.Max.X; x++ {
for y := rect.Min.Y; y <= rect.Max.Y; y++ {
rgba.Set(x, y, color)
}
}
}
示例9: constructPixelArray
func constructPixelArray(img *image.RGBA) []Rgb {
rgbaImg := image.NewRGBA(img.Bounds())
draw.Draw(rgbaImg, rgbaImg.Bounds(), img, image.ZP, draw.Src)
pixelArray := make([]Rgb, 0, 50)
var rgbVal = Rgb{}
for i, pix := range rgbaImg.Pix {
switch i % 4 {
case 0:
rgbVal.R = pix
case 1:
rgbVal.G = pix
case 2:
rgbVal.B = pix
case 3:
if pix >= minTransparency && isOpaque(rgbVal) {
pixelArray = append(pixelArray, rgbVal)
rgbVal = Rgb{}
}
}
}
return pixelArray
}
示例10: fillpoint
func fillpoint(c compl, img *image.RGBA, imagelength, imagewidth float64, fromc, toc compl) {
transformedxcoord := int((imagelength * (c.re - fromc.re) / (toc.re - fromc.re)))
transformedycoord := int(imagewidth - (imagewidth*(c.im-fromc.im))/(toc.im-fromc.im))
col := colorFromEscapeTime(getEscapeTime(c))
img.Set(transformedxcoord, transformedycoord, col)
}
示例11: Start
func Start(im *image.RGBA, num int, vpx, vpy, d float64, ch chan<- point) {
share := im.Height() / num
for i := 0; i < num; i += 1 {
go Mandelbrot(im, i*share, (i+1)*share, vpx, vpy, d, ch)
}
}
示例12: renderFloat
func renderFloat(img *image.RGBA) {
var yminF, ymaxMinF, heightF big.Float
yminF.SetInt64(ymin)
ymaxMinF.SetInt64(ymax - ymin)
heightF.SetInt64(height)
var xminF, xmaxMinF, widthF big.Float
xminF.SetInt64(xmin)
xmaxMinF.SetInt64(xmax - xmin)
widthF.SetInt64(width)
var y, x big.Float
for py := int64(0); py < height; py++ {
// y := float64(py)/height*(ymax-ymin) + ymin
y.SetInt64(py)
y.Quo(&y, &heightF)
y.Mul(&y, &ymaxMinF)
y.Add(&y, &yminF)
for px := int64(0); px < width; px++ {
// x := float64(px)/width*(xmax-xmin) + xmin
x.SetInt64(px)
x.Quo(&x, &widthF)
x.Mul(&x, &xmaxMinF)
x.Add(&x, &xminF)
c := mandelbrotFloat(&x, &y)
if c == nil {
c = color.Black
}
img.Set(int(px), int(py), c)
}
}
}
示例13: gaussianBlur
func gaussianBlur(dst, src *image.RGBA, radius int) {
boxes := determineBoxes(float64(radius), 3)
tmp := image.NewRGBA(dst.Bounds())
boxBlur3(dst, tmp, src, (boxes[0]-1)/2)
boxBlur3(dst, tmp, dst, (boxes[1]-1)/2)
boxBlur3(dst, tmp, dst, (boxes[2]-1)/2)
}
示例14: Image
// Image builds an image.RGBA type with 6 by 6 quadrants of alternate colors.
func Image(m *image.RGBA, key string, colors []color.RGBA) {
size := m.Bounds().Size()
squares := 6
quad := size.X / squares
middle := math.Ceil(float64(squares) / float64(2))
colorMap := make(map[int]color.RGBA)
var currentYQuadrand = 0
for y := 0; y < size.Y; y++ {
yQuadrant := y / quad
if yQuadrant != currentYQuadrand {
// when y quadrant changes, clear map
colorMap = make(map[int]color.RGBA)
currentYQuadrand = yQuadrant
}
for x := 0; x < size.X; x++ {
xQuadrant := x / quad
if _, ok := colorMap[xQuadrant]; !ok {
if float64(xQuadrant) < middle {
colorMap[xQuadrant] = draw.PickColor(key, colors, xQuadrant+3*yQuadrant)
} else if xQuadrant < squares {
colorMap[xQuadrant] = colorMap[squares-xQuadrant-1]
} else {
colorMap[xQuadrant] = colorMap[0]
}
}
m.Set(x, y, colorMap[xQuadrant])
}
}
}
示例15: loadFont
// loadFont loads the given font data. This does not deal with font scaling.
// Scaling should be handled by the independent Bitmap/Truetype loaders.
// We therefore expect the supplied image and charset to already be adjusted
// to the correct font scale.
//
// The image should hold a sprite sheet, defining the graphical layout for
// every glyph. The config describes font metadata.
func loadFont(img *image.RGBA, config *FontConfig) (f *Font, err error) {
f = new(Font)
f.Config = config
// Resize image to next power-of-two.
img = glh.Pow2Image(img).(*image.RGBA)
ib := img.Bounds()
f.Width = ib.Dx()
f.Height = ib.Dy()
// Create the texture itself. It will contain all glyphs.
// Individual glyph-quads display a subset of this texture.
f.Texture = gl.GenTexture()
f.Texture.Bind(gl.TEXTURE_2D)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, ib.Dx(), ib.Dy(), 0,
gl.RGBA, gl.UNSIGNED_BYTE, img.Pix)
// file, err := os.Create("font.png")
// if err != nil {
// log.Fatal(err)
// }
// err = png.Encode(file, img)
// if err != nil {
// log.Fatal(err)
// }
return
}