pixmap

package
v0.0.0-...-155abb7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func BGRA32

func BGRA32(c color.Color) uint32

func Blend

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

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

func NewColor

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

func NewColorHex

func NewColorHex(hex uint32) color.NRGBA

func NewColorRGB

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

func RGB565

func RGB565(c color.Color) uint16

func RGBA32

func RGBA32(c color.Color) uint32

func RectCenter

func RectCenter(r image.Rectangle) image.Point

func RectContainsPoint

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

func RectContainsXY

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

func RectInsetAll

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

func RectInsetLTRB

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

func RectIntersects

func RectIntersects(a, b image.Rectangle) bool

func RectXYWH

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

func ToNRGBA

func ToNRGBA(c color.Color) color.NRGBA

Types

type 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.

func BufferFromImage

func BufferFromImage(img image.Image) *Buffer

BufferFromImage copies any image.Image into a buffer.

func New

func New(width, height int) *Buffer

New creates a software canvas with the given dimensions.

func NewBuffer

func NewBuffer(width, height int) *Buffer

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

func Wrap

func Wrap(buf *Buffer) *Buffer

Wrap treats an existing buffer as a software canvas.

func (*Buffer) At

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

At returns the pixel color at x,y.

func (*Buffer) Blit

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

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

func (*Buffer) BlitOpaque

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

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

func (*Buffer) 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.

func (*Buffer) 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.

func (*Buffer) BlitScaled

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

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

func (*Buffer) Bounds

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

Bounds returns buffer bounds for image/draw interoperability.

func (*Buffer) Buffer

func (b *Buffer) Buffer() *Buffer

Buffer returns the backing buffer.

func (*Buffer) Clear

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

Clear fills entire buffer.

func (*Buffer) ClearClip

func (b *Buffer) ClearClip()

ClearClip removes any active drawing clip.

func (*Buffer) Clip

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

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

func (*Buffer) ColorModel

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

ColorModel returns NRGBA model for image/draw interoperability.

func (*Buffer) DrawBuffer

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

DrawBuffer scales and draws a source buffer into dst.

func (*Buffer) DrawImage

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

DrawImage scales and draws any image.Image into dst.

func (*Buffer) DrawLine

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

DrawLine draws a line using Bresenham algorithm.

func (*Buffer) DrawRect

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

DrawRect draws a rectangle outline.

func (*Buffer) DrawRoundedRect

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

DrawRoundedRect draws rounded rectangle outline.

func (*Buffer) FillRect

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

FillRect fills r with c.

func (*Buffer) FillRoundedRect

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

FillRoundedRect fills r with rounded corners.

func (*Buffer) GetPixel

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

GetPixel returns pixel color at x,y.

func (*Buffer) Image

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

Image returns the backing draw.Image.

func (*Buffer) Resize

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

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

func (*Buffer) Set

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

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

func (*Buffer) SetClip

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

SetClip restricts subsequent drawing operations to r intersected with bounds.

func (*Buffer) SetPixel

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

SetPixel sets a pixel at x,y.

func (*Buffer) Size

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

Size returns canvas dimensions.

func (*Buffer) SubBuffer

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

SubBuffer copies r region into a new buffer.

type PixelFormat

type PixelFormat int

PixelFormat represents the pixel format of a buffer.

const (
	PixelFormatBGRA PixelFormat = iota
	PixelFormatRGBA
	PixelFormatRGB565
)