33 lines
830 B
Go
33 lines
830 B
Go
package ggfx
|
|
|
|
import "image"
|
|
|
|
type Image[T any] struct {
|
|
// Pix is the actual pixel array of the image.
|
|
Pix []T
|
|
|
|
// Stride represents the distance in slice elements between two pixels
|
|
// that are vertically adjacent.
|
|
Stride int
|
|
|
|
// Width specifies how many slice elements make up a single pixel.
|
|
Width int
|
|
|
|
// Rect specifies a rectangle that all drawing operations will be
|
|
// clipped to. It must not reside outside of Data. It is measured in
|
|
// pixels and not slice elements.
|
|
Rect image.Rectangle
|
|
}
|
|
|
|
func (this Image[T]) Bounds () image.Rectangle {
|
|
return this.Rect
|
|
}
|
|
|
|
func (this Image[T]) PixOffset (x, y int) int {
|
|
return (y - this.Rect.Min.Y) * this.Stride + (x - this.Rect.Min.X) * this.Width
|
|
}
|
|
|
|
func (this Image[T]) assertWidth (pixel []T) {
|
|
if len(pixel) != this.Width { panic("invalid fill pixel width") }
|
|
}
|