oklab

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// A color model for converting arbitrary colors to OKLab.
	//
	// Wraps the [FromColor] function, returning a [color.Color] interface rather than the [Color] type.
	Model = color.ModelFunc(okLabModel)
)

Functions

func Distance

func Distance(a, b Color) float64

Distance returns the perceptual distance between two colors.

This controls for possible transparency. Two different but otherwise fully transparent colors would have a distance of zero.

Types

type Color

type Color struct {
	Lightness, ChromaA, ChromaB, A float64
}

func FromColor

func FromColor(c color.Color) Color

FromColor converts an arbitrary color type to an OKLab Color, with special handling for color.NRGBA, color.NRGBA64, and anything implementing the NRGBAColor interface to preserve transparent colors.

func FromNRGBA

func FromNRGBA(r, g, b, a uint32) Color

FromNRGBA create an OkLab color from non-pre-multiplied RGBA.

func FromRGBA

func FromRGBA(r, g, b, a uint32) Color

FromRGBA create an OkLab color from pre-multiplied RGBA.

func (Color) NRGBA

func (c Color) NRGBA() (r, g, b, a uint32)

NRGBA converts to non-premultiplied RGBA.

func (Color) RGBA

func (c Color) RGBA() (r, g, b, a uint32)

RGBA converts to premultiplied RGBA.

type Image added in v0.1.1

type Image struct {
	Pix    []uint8
	Stride int
	Rect   image.Rectangle
}

Image represents an image that encodes its pixels using OKLab color.

Each pixel is 32 bytes in size, encoding the Lightness, ChromaA, ChromaB, and Alpha components of each pixel in that order as big-endian float64 values.

func NewImage added in v0.1.1

func NewImage(r image.Rectangle) *Image

NewImage returns a new Image of the specified size.

func (*Image) At added in v0.1.1

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

At implements the image.Image interface.

func (*Image) Bounds added in v0.1.1

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

Bounds implements the image.Image interface.

func (*Image) ColorModel added in v0.1.1

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

ColorModel implements the image.Image interface.

func (*Image) OkLabAt added in v0.1.1

func (p *Image) OkLabAt(x, y int) Color

OkLabAt decodes the pixel at the given coordinates into an OkLab color.

The zero value is returned for coordinates outside of the image.

func (*Image) Opaque added in v0.1.1

func (p *Image) Opaque() bool

Opaque returns true if every pixel in the image would have an alpha value of 0xffff when converted to color.RGBA64.

func (*Image) PixOffset added in v0.1.1

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

PixOffset returns the offset into the [Pix] slice a pixel begins.

The given coordinates must be inside the image.

func (*Image) RGBA64At added in v0.1.1

func (p *Image) RGBA64At(x, y int) color.RGBA64

RGBA64At implements the image.RGBA64Image interface.

func (*Image) Set added in v0.1.1

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

Set implements the draw.Image interface.

func (*Image) SetOkLab added in v0.1.1

func (p *Image) SetOkLab(x, y int, c Color)

SetOkLab encodes the given color into the pixel at the given coordinates.

Does nothing if the coordinates are outside the image.

func (*Image) SetRGBA64 added in v0.1.1

func (p *Image) SetRGBA64(x, y int, c color.RGBA64)

Set implements the draw.RGBA64Image interface.

func (*Image) SubImage added in v0.1.1

func (p *Image) SubImage(r image.Rectangle) *Image

SubImage returns a new Image that shares the same underlying pixel data.

type NRGBAColor

type NRGBAColor interface {
	color.Color
	NRGBA() (r, g, b, a uint32)
}

NRGBAColor represent a color that can give us non pre-multiplied RGBA components.

This isn't a standard interface, but we implement it and check for it regardless.

Source Files

  • image.go
  • oklab.go

Jump to

Keyboard shortcuts

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