This repository has been archived on 2023-08-08. You can view files and clone it, but cannot push or open issues or pull requests.
tomo-old/artist/rectangle.go

53 lines
1.3 KiB
Go
Raw Normal View History

2023-01-09 06:03:19 +00:00
package artist
import "image"
import "git.tebibyte.media/sashakoshka/tomo"
// Paste transfers one canvas onto another, offset by the specified point.
2023-01-09 06:03:19 +00:00
func Paste (
destination tomo.Canvas,
source tomo.Canvas,
2023-01-09 06:03:19 +00:00
offset image.Point,
) (
updatedRegion image.Rectangle,
) {
dstData, dstStride := destination.Buffer()
srcData, srcStride := source.Buffer()
sourceBounds :=
source.Bounds().Canon().
Intersect(destination.Bounds().Sub(offset))
if sourceBounds.Empty() { return }
2023-01-09 06:03:19 +00:00
updatedRegion = sourceBounds.Add(offset)
for y := sourceBounds.Min.Y; y < sourceBounds.Max.Y; y ++ {
for x := sourceBounds.Min.X; x < sourceBounds.Max.X; x ++ {
dstData[x + offset.X + (y + offset.Y) * dstStride] =
srcData[x + y * srcStride]
2023-01-09 06:03:19 +00:00
}}
return
}
2023-01-14 17:41:51 +00:00
// FillRectangle draws a filled rectangle with the specified pattern.
func FillRectangle (
2023-01-09 06:03:19 +00:00
destination tomo.Canvas,
source Pattern,
2023-01-09 06:03:19 +00:00
bounds image.Rectangle,
) (
updatedRegion image.Rectangle,
) {
data, stride := destination.Buffer()
bounds = bounds.Canon().Intersect(destination.Bounds()).Canon()
if bounds.Empty() { return }
2023-01-09 06:03:19 +00:00
updatedRegion = bounds
width, height := bounds.Dx(), bounds.Dy()
for y := 0; y < height; y ++ {
for x := 0; x < width; x ++ {
data[x + bounds.Min.X + (y + bounds.Min.Y) * stride] =
source.AtWhen(x, y, width, height)
2023-01-09 06:03:19 +00:00
}}
return
}