mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
op/paint: add support for efficient ImageOp subimages
The new field ImageOp.Rect is initialized to cover the entire source image, but can be modified to draw only a section of it. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
||||
|
||||
// ImageOp sets the material to an image.
|
||||
type ImageOp struct {
|
||||
Rect image.Rectangle
|
||||
uniform bool
|
||||
color color.RGBA
|
||||
src *image.RGBA
|
||||
@@ -48,6 +49,7 @@ func NewImageOp(src image.Image) ImageOp {
|
||||
bounds := src.Bounds()
|
||||
if bounds.Min == (image.Point{}) && src.Stride == bounds.Dx()*4 {
|
||||
return ImageOp{
|
||||
Rect: src.Bounds(),
|
||||
src: src,
|
||||
handle: new(int),
|
||||
}
|
||||
@@ -82,6 +84,11 @@ func (i ImageOp) Add(o *op.Ops) {
|
||||
}
|
||||
data := o.Write(opconst.TypeImageLen, i.src, i.handle)
|
||||
data[0] = byte(opconst.TypeImage)
|
||||
bo := binary.LittleEndian
|
||||
bo.PutUint32(data[1:], uint32(i.Rect.Min.X))
|
||||
bo.PutUint32(data[5:], uint32(i.Rect.Min.Y))
|
||||
bo.PutUint32(data[9:], uint32(i.Rect.Max.X))
|
||||
bo.PutUint32(data[13:], uint32(i.Rect.Max.Y))
|
||||
}
|
||||
|
||||
func (c ColorOp) Add(o *op.Ops) {
|
||||
|
||||
Reference in New Issue
Block a user