avyos.dev/pkg/graphics/pixmap

package pixmap

Overview

No package-level documentation is provided.

Export GroupCount
Constants0
Variables1
Functions15
Types2

Variables

ColorBlack, ColorWhite, ColorRed, ColorGreen, ColorBlue, ColorGray, ColorLightGray, ColorDarkGray, ColorTransparent

var (
	ColorBlack       = color.NRGBA{R: 0, G: 0, B: 0, A: 255}
	ColorWhite       = color.NRGBA{R: 255, G: 255, B: 255, A: 255}
	ColorRed         = color.NRGBA{R: 255, G: 0, B: 0, A: 255}
	ColorGreen       = color.NRGBA{R: 0, G: 255, B: 0, A: 255}
	ColorBlue        = color.NRGBA{R: 0, G: 0, B: 255, A: 255}
	ColorGray        = color.NRGBA{R: 128, G: 128, B: 128, A: 255}
	ColorLightGray   = color.NRGBA{R: 200, G: 200, B: 200, A: 255}
	ColorDarkGray    = color.NRGBA{R: 64, G: 64, B: 64, A: 255}
	ColorTransparent = color.NRGBA{}
)

Functions

BGRA32

func BGRA32(c color.Color) uint32

Blend

func Blend(fg, bg color.NRGBA) color.NRGBA

Blend composites fg over bg in non-premultiplied NRGBA space.

NewColor

func NewColor(r, g, b, a uint8) color.NRGBA

NewColorHex

func NewColorHex(hex uint32) color.NRGBA

NewColorRGB

func NewColorRGB(r, g, b uint8) color.NRGBA

RGB565

func RGB565(c color.Color) uint16

RGBA32

func RGBA32(c color.Color) uint32

RectCenter

func RectCenter(r image.Rectangle) image.Point

RectContainsPoint

func RectContainsPoint(r image.Rectangle, p image.Point) bool

RectContainsXY

func RectContainsXY(r image.Rectangle, x, y int) bool

RectInsetAll

func RectInsetAll(r image.Rectangle, amount int) image.Rectangle

RectInsetLTRB

func RectInsetLTRB(r image.Rectangle, top, right, bottom, left int) image.Rectangle

RectIntersects

func RectIntersects(a, b image.Rectangle) bool

RectXYWH

func RectXYWH(x, y, w, h int) image.Rectangle

ToNRGBA

func ToNRGBA(c color.Color) color.NRGBA

Types

Buffer

type Buffer struct {
	Width  int
	Height int
	Stride int
	Format PixelFormat
	Data   []byte
	// contains filtered or unexported fields
}

Buffer represents a pixel buffer for drawing. It implements draw.Image with Bounds/At/Set methods.

Functions

BufferFromImage

func BufferFromImage(img image.Image) *Buffer

BufferFromImage copies any image.Image into a buffer.

New

func New(width, height int) *Buffer

New creates a software canvas with the given dimensions.

NewBuffer

func NewBuffer(width, height int) *Buffer

NewBuffer creates a new buffer with the given dimensions (BGRA format).

Wrap

func Wrap(buf *Buffer) *Buffer

Wrap treats an existing buffer as a software canvas.

Methods

At

func (b *Buffer) At(x, y int) color.Color

At returns the pixel color at x,y.

Blit

func (b *Buffer) Blit(src *Buffer, x, y int)

Blit copies src onto b at x,y with alpha blending.

BlitOpaque

func (b *Buffer) BlitOpaque(src *Buffer, x, y int)

BlitOpaque copies src onto b and forces source alpha to 255.

BlitOpaqueRect

func (b *Buffer) BlitOpaqueRect(src *Buffer, srcRect image.Rectangle, x, y int)

BlitOpaqueRect copies srcRect from src onto b at x,y and forces alpha to 255.

BlitRect

func (b *Buffer) BlitRect(src *Buffer, srcRect image.Rectangle, x, y int)

BlitRect copies srcRect from src onto b at x,y with alpha blending.

BlitScaled

func (b *Buffer) BlitScaled(src *Buffer, srcRect, dstRect image.Rectangle)

BlitScaled copies srcRect from src to dstRect on b using bilinear sampling.

Bounds

func (b *Buffer) Bounds() image.Rectangle

Bounds returns buffer bounds for image/draw interoperability.

Buffer

func (b *Buffer) Buffer() *Buffer

Buffer returns the backing buffer.

Clear

func (b *Buffer) Clear(c color.Color)

Clear fills entire buffer.

ClearClip

func (b *Buffer) ClearClip()

ClearClip removes any active drawing clip.

Clip

func (b *Buffer) Clip() (image.Rectangle, bool)

Clip returns the active clip rectangle and whether clipping is enabled.

ColorModel

func (b *Buffer) ColorModel() color.Model

ColorModel returns NRGBA model for image/draw interoperability.

DrawBuffer

func (b *Buffer) DrawBuffer(src *Buffer, dst image.Rectangle)

DrawBuffer scales and draws a source buffer into dst.

DrawImage

func (b *Buffer) DrawImage(src image.Image, dst image.Rectangle)

DrawImage scales and draws any image.Image into dst.

DrawLine

func (b *Buffer) DrawLine(x0, y0, x1, y1 int, c color.Color)

DrawLine draws a line using Bresenham algorithm.

DrawRect

func (b *Buffer) DrawRect(r image.Rectangle, c color.Color)

DrawRect draws a rectangle outline.

DrawRoundedRect

func (b *Buffer) DrawRoundedRect(r image.Rectangle, radius int, c color.Color)

DrawRoundedRect draws rounded rectangle outline.

FillRect

func (b *Buffer) FillRect(r image.Rectangle, c color.Color)

FillRect fills r with c.

FillRoundedRect

func (b *Buffer) FillRoundedRect(r image.Rectangle, radius int, c color.Color)

FillRoundedRect fills r with rounded corners.

GetPixel

func (b *Buffer) GetPixel(x, y int) color.NRGBA

GetPixel returns pixel color at x,y.

Image

func (b *Buffer) Image() draw.Image

Image returns the backing draw.Image.

Resize

func (b *Buffer) Resize(width, height int)

Resize resizes the buffer, reusing backing memory when capacity allows.

Set

func (b *Buffer) Set(x, y int, c color.Color)

Set writes a pixel using color.Color for image/draw interoperability.

SetClip

func (b *Buffer) SetClip(r image.Rectangle)

SetClip restricts subsequent drawing operations to r intersected with bounds.

SetPixel

func (b *Buffer) SetPixel(x, y int, c color.Color)

SetPixel sets a pixel at x,y.

Size

func (b *Buffer) Size() (width, height int)

Size returns canvas dimensions.

SubBuffer

func (b *Buffer) SubBuffer(r image.Rectangle) *Buffer

SubBuffer copies r region into a new buffer.

PixelFormat

type PixelFormat int

PixelFormat represents the pixel format of a buffer.

Constants

PixelFormatBGRA, PixelFormatRGBA, PixelFormatRGB565

const (
	PixelFormatBGRA PixelFormat = iota
	PixelFormatRGBA
	PixelFormatRGB565
)