raster

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package raster is the shared pixel-buffer substrate of go-gfx: a densely packed 8-bit RGBA image the higher layers (resample, color, and the fleet's image-processing and rendering libraries) read and write.

Image.Pix is row-major, four bytes (R, G, B, A) per pixel, with NO row padding — stride is always 4*W. The bytes are STRAIGHT (non-premultiplied): a pixel's colour is stored as-is, independent of its alpha, which is the representation image processing wants. This differs from the standard library's image.RGBA, whose bytes are premultiplied; FromImage and ToRGBA convert across that boundary correctly rather than copying bytes blindly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Image

type Image struct {
	Pix  []uint8
	W, H int
}

Image is a densely packed, straight-alpha 8-bit RGBA pixel buffer of W by H pixels. Pix has length 4*W*H.

func FromImage

func FromImage(src image.Image) *Image

FromImage converts any image.Image into a straight-alpha Image. An *image.NRGBA (already straight) is copied directly; anything else is converted pixel by pixel through the non-premultiplied colour model, so a premultiplied *image.RGBA source is un-premultiplied rather than mis-read.

func New

func New(w, h int) *Image

New returns a zeroed Image of w by h pixels (fully transparent black). w and h must be non-negative.

func (*Image) At

func (p *Image) At(x, y int) color.RGBA

At returns the straight-alpha colour of the pixel at (x, y).

func (*Image) Bounds

func (p *Image) Bounds() image.Rectangle

Bounds returns the image's rectangle, anchored at the origin.

func (*Image) PixOffset

func (p *Image) PixOffset(x, y int) int

PixOffset returns the index into Pix of the pixel at (x, y).

func (*Image) Set

func (p *Image) Set(x, y int, c color.RGBA)

Set writes the straight-alpha colour c to the pixel at (x, y).

func (*Image) ToNRGBA

func (p *Image) ToNRGBA() *image.NRGBA

ToNRGBA returns the buffer as a standard-library *image.NRGBA, whose bytes are also straight, so this is a direct copy and the round trip through the standard image package is lossless.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL