Example #1
0
func (b *bufferImpl) upload(u screen.Uploader, xd xproto.Drawable, xg xproto.Gcontext, depth uint8,
	dp image.Point, sr image.Rectangle, sender screen.Sender) {

	b.preUpload(sender != nil)

	// TODO: adjust if dp is outside dst bounds, or sr is outside src bounds.
	dr := sr.Sub(sr.Min).Add(dp)

	b.s.mu.Lock()
	b.s.nPendingUploads++
	b.s.mu.Unlock()

	cookie := shm.PutImage(
		b.s.xc, xd, xg,
		uint16(b.size.X), uint16(b.size.Y), // TotalWidth, TotalHeight,
		uint16(sr.Min.X), uint16(sr.Min.Y), // SrcX, SrcY,
		uint16(dr.Dx()), uint16(dr.Dy()), // SrcWidth, SrcHeight,
		int16(dr.Min.X), int16(dr.Min.Y), // DstX, DstY,
		depth, xproto.ImageFormatZPixmap,
		1, b.xs, 0, // 1 means send a completion event, 0 means a zero offset.
	)

	b.s.mu.Lock()
	b.s.uploads[cookie.Sequence] = completion{
		sender: sender,
		event: screen.UploadedEvent{
			Buffer:   b,
			Uploader: u,
		},
	}
	b.s.nPendingUploads--
	b.s.handleCompletions()
	b.s.mu.Unlock()
}
Example #2
0
func (h *HostWindow) OnHostPaint(ctxt NativeContext, dirty_rect image.Rectangle) {
	var canvas = NewNativeCanvas(dirty_rect)
	defer canvas.Release()

	var canvas_rect = dirty_rect.Sub(dirty_rect.Min)

	canvas.DrawCanvas(canvas_rect.Min.X, canvas_rect.Min.Y,
		h.root_view.Canvas(), &dirty_rect)
	canvas.BlitToContext(ctxt, dirty_rect.Min.X, dirty_rect.Min.Y, &canvas_rect)
}
Example #3
0
// ChartArea returns the smallest rectangle containing all chart positions
// that can get drawn in the given screen rectangle, if chart position (0, 0)
// is at the center of the screen rectangle.
func ChartArea(screenArea image.Rectangle) image.Rectangle {
	scrOrigin := CenterOrigin(screenArea)
	minX, minY := math.MaxInt32, math.MaxInt32
	maxX, maxY := math.MinInt32, math.MinInt32
	for _, pt := range Corners(screenArea.Sub(scrOrigin)) {
		chartPos := ScreenToChart(pt)
		minX = int(math.Min(float64(chartPos.X), float64(minX)))
		minY = int(math.Min(float64(chartPos.Y), float64(minY)))
		maxX = int(math.Max(float64(chartPos.X), float64(maxX)))
		maxY = int(math.Max(float64(chartPos.Y), float64(maxY)))
	}

	return image.Rect(minX, minY, maxX+1, maxY+1)
}
Example #4
0
// Draw creates an image of the function in the domain.
func Draw(fnc ColorMap, size image.Rectangle, domain *ComplexRect) image.Image {
	size = size.Canon()
	// Clever vector hack to move the Min corner to 0,0
	size = size.Sub(size.Min)
	// For now, use RGBA as image type
	img := image.NewRGBA(size)
	// max x and y guaranteed to be size of rectangle
	x := size.Dx()
	y := size.Dy()
	dx := domain.dx() / float64(x)
	dy := domain.dy() / float64(y)
	// Get the initial x vals
	base_x := domain.left()
	base_y := domain.bottom()
	for i := 0; i <= x; i++ {
		for j := 0; j <= y; j++ {
			point := complex(base_x+float64(i)*dx, base_y+float64(j)*dy)
			img.Set(i, j, fnc(point))
		}
	}
	return img
}
Example #5
0
// Crop cuts out a rectangular region with the specified bounds
// from the image and returns the cropped image.
func Crop(img image.Image, rect image.Rectangle) *image.NRGBA {
	src := toNRGBA(img)
	srcRect := rect.Sub(img.Bounds().Min)
	sub := src.SubImage(srcRect)
	return Clone(sub) // New image Bounds().Min point will be (0, 0)
}
Example #6
0
// CropTo returns a copy of this image that has been cropped
// to the given dimensions
func (self Image) CropTo(bounds image.Rectangle) Image {
	dst := image.NewRGBA(bounds.Sub(bounds.Min))
	r := image.Rectangle{dst.Rect.Min, dst.Rect.Min.Add(bounds.Size())}
	draw.Draw(dst, r, self.Img, bounds.Min, draw.Src)
	return Image{Img: dst, Format: self.Format}
}
Example #7
0
func Crop(context *common.AppContext, img image.Image, rect image.Rectangle) *image.NRGBA {
	src := ToNRGBA(img)
	srcRect := rect.Sub(img.Bounds().Min)
	sub := src.SubImage(srcRect)
	return CloneImage(sub)
}