Exemple #1
0
// blendCheckered is basically a copy of xgraphics.Blend with no interfaces.
// (It's faster.) Also, it is hardcoded to blend into a checkered background.
func blendCheckered(dest *xgraphics.Image) {
	dsrc := dest.Bounds()
	dmnx, dmxx, dmny, dmxy := dsrc.Min.X, dsrc.Max.X, dsrc.Min.Y, dsrc.Max.Y

	clr1 := xgraphics.BGRA{B: 0xff, G: 0xff, R: 0xff, A: 0xff}
	clr2 := xgraphics.BGRA{B: 0xde, G: 0xdc, R: 0xdf, A: 0xff}

	var dx, dy int
	var bgra, clr xgraphics.BGRA
	for dx = dmnx; dx < dmxx; dx++ {
		for dy = dmny; dy < dmxy; dy++ {
			if dx%30 >= 15 {
				if dy%30 >= 15 {
					clr = clr1
				} else {
					clr = clr2
				}
			} else {
				if dy%30 >= 15 {
					clr = clr2
				} else {
					clr = clr1
				}
			}

			bgra = dest.At(dx, dy).(xgraphics.BGRA)
			dest.SetBGRA(dx, dy, xgraphics.BlendBGRA(clr, bgra))
		}
	}
}
Exemple #2
0
// vpCenter inspects the canvas and image geometry, and determines where the
// origin of the image should be painted into the canvas.
// If the image is bigger than the canvas, this is always (0, 0).
// If the image is the same size, then it is also (0, 0).
// If a dimension of the image is smaller than the canvas, then:
// x = (canvas_width - image_width) / 2 and
// y = (canvas_height - image_height) / 2
func vpCenter(ximg *xgraphics.Image, canWidth, canHeight int) image.Point {
	xmargin, ymargin := 0, 0
	if ximg.Bounds().Dx() < canWidth {
		xmargin = (canWidth - ximg.Bounds().Dx()) / 2
	}
	if ximg.Bounds().Dy() < canHeight {
		ymargin = (canHeight - ximg.Bounds().Dy()) / 2
	}
	return image.Point{xmargin, ymargin}
}
Exemple #3
0
func copyToXGraphicsImage(xs *xgraphics.Image, buffer *image.RGBA) {
	//Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*4]
	xdata := xs.Pix
	bdata := buffer.Pix
	if xs.Bounds() == buffer.Bounds() {
		copy(xdata, bdata)
	} else {

		xb := xs.Bounds()
		bb := buffer.Bounds()

		miny := xb.Min.Y
		if miny < bb.Min.Y {
			miny = bb.Min.Y
		}
		maxy := xb.Max.Y
		if maxy > bb.Max.Y {
			maxy = bb.Max.Y
		}

		xRowLen := (xb.Max.X - xb.Min.X)
		bRowLen := (bb.Max.X - bb.Min.X)
		rowLen := xRowLen
		if bRowLen < rowLen {
			rowLen = bRowLen
		}

		for y := miny; y < maxy; y++ {
			xstart := (y-xb.Min.Y)*xs.Stride - xb.Min.X*4
			bstart := (y-bb.Min.Y)*buffer.Stride - bb.Min.X*4
			xrow := xdata[xstart : xstart+rowLen*4]
			brow := bdata[bstart : bstart+rowLen*4]
			copy(xrow, brow)
		}
	}
	// xgraphics.Image is BGRA, not RGBA, so swap some bits
	for i := 0; i < len(xdata)/4; i++ {
		index := i * 4
		xdata[index], xdata[index+2] = xdata[index+2], xdata[index]
	}
}
Exemple #4
0
// paint uses the xgbutil/xgraphics package to copy the area corresponding
// to ximg in its pixmap to the window. It will also issue a clear request
// before hand to try and avoid artifacts.
func (w *Window) paint(ximg *xgraphics.Image) {

	// If the image is bigger than the canvas, this is always (0, 0).
	// If the image is the same size, then it is also (0, 0).
	// If a dimension of the image is smaller than the canvas, then:
	// x = (canvas_width - image_width) / 2 and
	// y = (canvas_height - image_height) / 2
	xmargin, ymargin := 0, 0
	if ximg.Bounds().Dx() < w.Geom.Width() {
		xmargin = (w.Geom.Width() - ximg.Bounds().Dx()) / 2
	}
	if ximg.Bounds().Dy() < w.Geom.Height() {
		ymargin = (w.Geom.Height() - ximg.Bounds().Dy()) / 2
	}

	ximg.XExpPaint(w.Id, xmargin, ymargin)
}