image

package
v0.0.0-...-f08a346 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Overview

Package image contains utility functions for reading, writing and converting images.

Image types:

  • Patch - replicates a patch of colors across the plane like Uniform does for a single color
  • Tile - replicates an image across the plane

Index

Constants

This section is empty.

Variables

View Source
var (
	Black   = &Uniform{color.RGBA{0x00, 0x00, 0x00, 0xff}}
	Red     = &Uniform{color.RGBA{0xff, 0x00, 0x00, 0xff}}
	Green   = &Uniform{color.RGBA{0x00, 0xff, 0x00, 0xff}}
	Blue    = &Uniform{color.RGBA{0x00, 0x00, 0xff, 0xff}}
	Yellow  = &Uniform{color.RGBA{0xff, 0xff, 0x00, 0xff}}
	Magenta = &Uniform{color.RGBA{0xff, 0x00, 0xff, 0xff}}
	Cyan    = &Uniform{color.RGBA{0x00, 0xff, 0xff, 0xff}}
	White   = &Uniform{color.RGBA{0xff, 0xff, 0xff, 0xff}}

	DarkGray  = &Uniform{color.RGBA{0x63, 0x66, 0x6a, 0xff}}
	MidGray   = &Uniform{color.RGBA{0x7f, 0x7f, 0x7f, 0xff}}
	LightGray = &Uniform{color.RGBA{0xd9, 0xd9, 0xd6, 0xff}}

	Brown  = &Uniform{color.RGBA{0xa4, 0x75, 0x51, 0xff}}
	Orange = &Uniform{color.RGBA{0xff, 0xa5, 0x00, 0xff}}
	Purple = &Uniform{color.RGBA{0x40, 0x00, 0x80, 0xff}}
)

Predefined uniform color images for use with RenderShape.

View Source
var NewUniform func(color.Color) *Uniform = image.NewUniform
View Source
var Opaque = image.Opaque
View Source
var Rect func(int, int, int, int) Rectangle = image.Rect
View Source
var Transparent = image.Transparent

Functions

func SaveImage

func SaveImage(img Image, name string) error

SaveImage is a utility function to save an image as a .png.

Types

type Alpha

type Alpha = image.Alpha

func CopyAlpha

func CopyAlpha(in *Alpha) *Alpha

CopyAlpha clones an Alpha image.

func GrayToAlpha

func GrayToAlpha(a *Gray) *Alpha

GrayToAlpha does a shallow copy (vs going through the ColorModel).

func GrayToAlphaDeep

func GrayToAlphaDeep(g *Gray) *Alpha

GrayToAlphaDeep does a deep copy (vs going through the ColorModel).

func NewAlpha

func NewAlpha(w, h int, col color.Color) *Alpha

NewAlpha is a wrapper for Alpha which returns a new image of the desired size filled with color.

type Alpha16

type Alpha16 = image.Alpha16

func CopyAlpha16

func CopyAlpha16(in *Alpha16) *Alpha16

CopyAlpha16 clones an Alpha16 image.

func Gray16ToAlpha16

func Gray16ToAlpha16(a *Gray16) *Alpha16

Gray16ToAlpha16 does a shallow copy (vs going through the ColorModel).

func Gray16ToAlpha16Deep

func Gray16ToAlpha16Deep(g *Gray16) *Alpha16

Gray16ToAlpha16Deep does a deep copy (vs going through the ColorModel).

func NewAlpha16

func NewAlpha16(w, h int, col color.Color) *Alpha16

NewAlpha16 is a wrapper for Alpha16 which returns a new image of the desired size filled with color.

type Colorizer

type Colorizer struct {
	Img  Image
	Rect Rectangle
	Lut  []color.RGBA
	G16  bool
}

Colorizer uses the gray or red channel of an image to create an image tinted with a lerp'd gradient between two or more colors.

func NewColorizer

func NewColorizer(img Image, c1, c2 color.Color, stops []int, colors []color.Color, post bool) *Colorizer

NewColorizer creates a new Colorizer and creates the internal lut. c1 and c2 are the colors at the start and end of the colorizer. The stops (in range [1,254] and colors values determine any intermediate points and can be nil. The post flag turns off the lerping between colors and yields a posterized image.

func (*Colorizer) At

func (c *Colorizer) At(x, y int) color.Color

At implements the At function in the Image interface.

func (*Colorizer) Bounds

func (c *Colorizer) Bounds() Rectangle

Bounds implements the Bounds function in the Image interface.

func (*Colorizer) ColorModel

func (c *Colorizer) ColorModel() color.Model

ColorModel implements the ColorModel function in the Image interface.

type Gray

type Gray = image.Gray

func AlphaToGray

func AlphaToGray(a *Alpha) *Gray

AlphaToGray does a shallow copy (vs going through the ColorModel).

func AlphaToGrayDeep

func AlphaToGrayDeep(a *Alpha) *Gray

AlphaToGrayDeep does a deep copy (vs going through the ColorModel).

func CopyGray

func CopyGray(in *Gray) *Gray

CopyGray clones a Gray image.

func NewGray

func NewGray(w, h int, col color.Color) *Gray

NewGray is a wrapper for Gray which returns a new image of the desired size filled with color.

func ToGray

func ToGray(img Image) *Gray

ToGray creates a grayscale copy of img

type Gray16

type Gray16 = image.Gray16

func Alpha16ToGray16

func Alpha16ToGray16(a *Alpha16) *Gray16

Alpha16ToGray16 does a shallow copy (vs going through the ColorModel).

func Alpha16ToGray16Deep

func Alpha16ToGray16Deep(a *Alpha16) *Gray16

Alpha16ToGray16Deep does a deep copy (vs going through the ColorModel).

func CopyGray16

func CopyGray16(in *Gray16) *Gray16

CopyGray16 clones a Gray16 image.

func NewGray16

func NewGray16(w, h int, col color.Color) *Gray16

NewGray16 is a wrapper for Gray16 which returns a new image of the desired size filled with color.

func ToGray16

func ToGray16(img Image) *Gray16

ToGray16 creates a grayscale copy of img

type Image

type Image = image.Image

func ReadImage

func ReadImage(name string) (Image, error)

ReadImage is a utility function to read an image from a file. The following formats are supported - bmp, jpeg, png, tiff, webp.

type NRGBA

type NRGBA = image.NRGBA

type NRGBA64

type NRGBA64 = image.NRGBA64

type Patch

type Patch struct {
	Colors [][]color.RGBA
	Width  int
	Height int
	OffsX  int
	OffsY  int
}

Patch is an infinite image covered with a patch of colors.

func NewPatch

func NewPatch(colors [][]color.Color) (*Patch, error)

NewPatch creates a new image with the supplied patch.

func (*Patch) At

func (p *Patch) At(x, y int) color.Color

At implements the At function in the Image interface.

func (*Patch) Bounds

func (p *Patch) Bounds() Rectangle

Bounds implements the Bounds function in the Image interface.

func (*Patch) ColorModel

func (p *Patch) ColorModel() color.Model

ColorModel implements the ColorModel function in the Image interface.

type Point

type Point = image.Point

type RGBA

type RGBA = image.RGBA

func CopyRGBA

func CopyRGBA(in *RGBA) *RGBA

CopyRGBA clones an RGBA image.

func NewRGBA

func NewRGBA(w, h int, col color.Color) *RGBA

NewRGBA is a wrapper for image.RGBA which returns a new image of the desired size filled with color.

type RGBA64

type RGBA64 = image.RGBA64

func CopyRGBA64

func CopyRGBA64(in *RGBA64) *RGBA64

CopyRGBA64 clones an RGBA64 image.

func NewRGBA64

func NewRGBA64(w, h int, col color.Color) *RGBA64

NewRGBA64 is a wrapper for RGBA64 which returns a new image of the desired size filled with color.

type Rectangle

type Rectangle = image.Rectangle

type Tile

type Tile struct {
	TileImg *RGBA
	Width   int
	Height  int
	OffsX   int
	OffsY   int
	StagX   int
	StagY   int
}

Tile is an infinite image covered with a tile.

func NewTile

func NewTile(img Image) *Tile

NewTile creates a new image with the supplied image tile.

func (*Tile) At

func (t *Tile) At(x, y int) color.Color

At implements the At function in the Image interface.

func (*Tile) Bounds

func (t *Tile) Bounds() Rectangle

Bounds implements the Bounds function in the Image interface.

func (*Tile) ColorModel

func (t *Tile) ColorModel() color.Model

ColorModel implements the ColorModel function in the Image interface.

type Uniform

type Uniform = image.Uniform

Jump to

Keyboard shortcuts

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