Skip to content

image #

image

image provides basic in-memory 2D image types and geometry helpers, translated from Go's image package into V-style APIs.

The module currently includes:

  • Point and Rectangle geometry helpers.
  • Packed pixel buffers: RGBA, RGBA64, NRGBA, NRGBA64, Alpha, Alpha16, Gray, Gray16, CMYK, and Paletted.
  • Y'CbCr buffers with common chroma subsampling ratios.
  • Uniform images for a single color.
  • image.color, with standard color types, color model conversion, palettes, Y'CbCr conversion, and CMYK conversion.
  • Format registration hooks with register_format, decode, and decode_config.
import image
import image.color

mut img := image.new_rgba(image.rect(0, 0, 2, 2))
img.set_rgba(0, 0, color.RGBA{
    r: 255
    g: 0
    b: 0
    a: 255
})

assert img.bounds().dx() == 2
assert img.rgba_at(0, 0).r == 255

The codec packages from Go's image tree, such as PNG, JPEG, and GIF, are not part of this module yet. They can be added later by registering decode callbacks with this module.

Constants #

const err_format = 'image: unknown format'

err_format indicates that decoding encountered an unknown format.

const black = Uniform{
	c: color.black
}
const white = Uniform{
	c: color.white
}
const transparent = Uniform{
	c: color.transparent
}
const opaque = Uniform{
	c: color.opaque
}

fn decode #

fn decode(reader io.Reader) !(Image, string)

decode decodes an image from a registered format.

fn decode_config #

fn decode_config(reader io.Reader) !(Config, string)

decode_config decodes the color model and dimensions of a registered format.

fn new_alpha #

fn new_alpha(r Rectangle) Alpha

new_alpha returns a new Alpha image with bounds r.

fn new_alpha16 #

fn new_alpha16(r Rectangle) Alpha16

new_alpha16 returns a new Alpha16 image with bounds r.

fn new_cmyk #

fn new_cmyk(r Rectangle) CMYK

new_cmyk returns a new CMYK image with bounds r.

fn new_gray #

fn new_gray(r Rectangle) Gray

new_gray returns a new Gray image with bounds r.

fn new_gray16 #

fn new_gray16(r Rectangle) Gray16

new_gray16 returns a new Gray16 image with bounds r.

fn new_nrgba #

fn new_nrgba(r Rectangle) NRGBA

new_nrgba returns a new NRGBA image with bounds r.

fn new_nrgba64 #

fn new_nrgba64(r Rectangle) NRGBA64

new_nrgba64 returns a new NRGBA64 image with bounds r.

fn new_nycbcra #

fn new_nycbcra(r Rectangle, subsample_ratio YCbCrSubsampleRatio) NYCbCrA

new_nycbcra returns a new NYCbCrA image with bounds r and subsample_ratio.

fn new_paletted #

fn new_paletted(r Rectangle, p color.Palette) Paletted

new_paletted returns a new Paletted image with bounds r and palette p.

fn new_rgba #

fn new_rgba(r Rectangle) RGBA

new_rgba returns a new RGBA image with bounds r.

fn new_rgba64 #

fn new_rgba64(r Rectangle) RGBA64

new_rgba64 returns a new RGBA64 image with bounds r.

fn new_uniform #

fn new_uniform(c color.Color) Uniform

new_uniform returns a new Uniform image of c.

fn new_ycbcr #

fn new_ycbcr(r Rectangle, subsample_ratio YCbCrSubsampleRatio) YCbCr

new_ycbcr returns a new YCbCr image with bounds r and subsample_ratio.

fn pt #

fn pt(x int, y int) Point

pt returns a Point from x and y.

fn rect #

fn rect(x0 int, y0 int, x1 int, y1 int) Rectangle

rect returns a well-formed rectangle with the given coordinates.

fn register_format #

fn register_format(name string, magic string, decode DecodeFn, decode_config DecodeConfigFn)

register_format registers an image format for use by decode and decode_config.

fn YCbCrSubsampleRatio.from #

fn YCbCrSubsampleRatio.from[W](input W) !YCbCrSubsampleRatio

interface Image #

interface Image {
	color_model() color.Model
	bounds() Rectangle
	at(x int, y int) color.Color
}

Image is a finite rectangular grid of color values.

interface PalettedImage #

interface PalettedImage {
	color_model() color.Model
	bounds() Rectangle
	at(x int, y int) color.Color
	color_index_at(x int, y int) u8
}

PalettedImage is an image whose pixels are palette indices.

interface PeekReader #

interface PeekReader {
mut:
	read(mut buf []u8) !int
	peek(n int) ![]u8
}

PeekReader is an io.Reader that can also peek ahead without consuming bytes.

interface RGBA64Image #

interface RGBA64Image {
	color_model() color.Model
	bounds() Rectangle
	at(x int, y int) color.Color
	rgba64_at(x int, y int) color.RGBA64
}

RGBA64Image is an image that can return pixels as RGBA64 directly.

fn (BufferedPeekReader) read #

fn (mut r BufferedPeekReader) read(mut buf []u8) !int

read implements io.Reader for BufferedPeekReader.

fn (BufferedPeekReader) peek #

fn (mut r BufferedPeekReader) peek(n int) ![]u8

peek returns the next n bytes without consuming them.

type DecodeConfigFn #

type DecodeConfigFn = fn (mut PeekReader) !Config

DecodeConfigFn decodes an image configuration from a registered format.

type DecodeFn #

type DecodeFn = fn (mut PeekReader) !Image

DecodeFn decodes an image from a registered format.

enum YCbCrSubsampleRatio #

enum YCbCrSubsampleRatio {
	ratio_444
	ratio_422
	ratio_420
	ratio_440
	ratio_411
	ratio_410
}

YCbCrSubsampleRatio is the chroma subsample ratio used by a YCbCr image.

fn (YCbCrSubsampleRatio) str #

fn (s YCbCrSubsampleRatio) str() string

str returns the Go-compatible name of the subsample ratio.

struct Alpha #

struct Alpha {
pub mut:
	pix    []u8
	stride int
	rect   Rectangle
}

Alpha is an in-memory image of alpha samples.

fn (Alpha) color_model #

fn (p Alpha) color_model() color.Model

color_model returns the Alpha color model.

fn (Alpha) bounds #

fn (p Alpha) bounds() Rectangle

bounds returns the image bounds.

fn (Alpha) at #

fn (p Alpha) at(x int, y int) color.Color

at returns the pixel at x, y as a color.

fn (Alpha) rgba64_at #

fn (p Alpha) rgba64_at(x int, y int) color.RGBA64

rgba64_at returns the pixel at x, y as RGBA64.

fn (Alpha) alpha_at #

fn (p Alpha) alpha_at(x int, y int) color.Alpha

alpha_at returns the pixel at x, y as Alpha.

fn (Alpha) pix_offset #

fn (p Alpha) pix_offset(x int, y int) int

pix_offset returns the first pix index for x, y.

fn (Alpha) set #

fn (mut p Alpha) set(x int, y int, c color.Color)

set stores c at x, y.

fn (Alpha) set_rgba64 #

fn (mut p Alpha) set_rgba64(x int, y int, c color.RGBA64)

set_rgba64 stores c at x, y.

fn (Alpha) set_alpha #

fn (mut p Alpha) set_alpha(x int, y int, c color.Alpha)

set_alpha stores c at x, y.

fn (Alpha) sub_image #

fn (p Alpha) sub_image(r Rectangle) Alpha

sub_image returns the portion of p visible through r.

fn (Alpha) opaque #

fn (p Alpha) opaque() bool

opaque reports whether every pixel is fully opaque.

struct Alpha16 #

struct Alpha16 {
pub mut:
	pix    []u8
	stride int
	rect   Rectangle
}

Alpha16 is an in-memory image of big-endian 16-bit alpha samples.

fn (Alpha16) color_model #

fn (p Alpha16) color_model() color.Model

color_model returns the Alpha16 color model.

fn (Alpha16) bounds #

fn (p Alpha16) bounds() Rectangle

bounds returns the image bounds.

fn (Alpha16) at #

fn (p Alpha16) at(x int, y int) color.Color

at returns the pixel at x, y as a color.

fn (Alpha16) rgba64_at #

fn (p Alpha16) rgba64_at(x int, y int) color.RGBA64

rgba64_at returns the pixel at x, y as RGBA64.

fn (Alpha16) alpha16_at #

fn (p Alpha16) alpha16_at(x int, y int) color.Alpha16

alpha16_at returns the pixel at x, y as Alpha16.

fn (Alpha16) pix_offset #

fn (p Alpha16) pix_offset(x int, y int) int

pix_offset returns the first pix index for x, y.

fn (Alpha16) set #

fn (mut p Alpha16) set(x int, y int, c color.Color)

set stores c at x, y.

fn (Alpha16) set_rgba64 #

fn (mut p Alpha16) set_rgba64(x int, y int, c color.RGBA64)

set_rgba64 stores c at x, y.

fn (Alpha16) set_alpha16 #

fn (mut p Alpha16) set_alpha16(x int, y int, c color.Alpha16)

set_alpha16 stores c at x, y.

fn (Alpha16) sub_image #

fn (p Alpha16) sub_image(r Rectangle) Alpha16

sub_image returns the portion of p visible through r.

fn (Alpha16) opaque #

fn (p Alpha16) opaque() bool

opaque reports whether every pixel is fully opaque.

struct CMYK #

struct CMYK {
pub mut:
	pix    []u8
	stride int
	rect   Rectangle
}

CMYK is an in-memory image with C, M, Y, K byte order.

fn (CMYK) color_model #

fn (p CMYK) color_model() color.Model

color_model returns the CMYK color model.

fn (CMYK) bounds #

fn (p CMYK) bounds() Rectangle

bounds returns the image bounds.

fn (CMYK) at #

fn (p CMYK) at(x int, y int) color.Color

at returns the pixel at x, y as a color.

fn (CMYK) rgba64_at #

fn (p CMYK) rgba64_at(x int, y int) color.RGBA64

rgba64_at returns the pixel at x, y as RGBA64.

fn (CMYK) cmyk_at #

fn (p CMYK) cmyk_at(x int, y int) color.CMYK

cmyk_at returns the pixel at x, y as CMYK.

fn (CMYK) pix_offset #

fn (p CMYK) pix_offset(x int, y int) int

pix_offset returns the first pix index for x, y.

fn (CMYK) set #

fn (mut p CMYK) set(x int, y int, c color.Color)

set stores c at x, y.

fn (CMYK) set_rgba64 #

fn (mut p CMYK) set_rgba64(x int, y int, c color.RGBA64)

set_rgba64 stores c at x, y.

fn (CMYK) set_cmyk #

fn (mut p CMYK) set_cmyk(x int, y int, c color.CMYK)

set_cmyk stores c at x, y.

fn (CMYK) sub_image #

fn (p CMYK) sub_image(r Rectangle) CMYK

sub_image returns the portion of p visible through r.

fn (CMYK) opaque #

fn (p CMYK) opaque() bool

opaque reports whether every pixel is fully opaque.

struct Config #

struct Config {
pub mut:
	color_model color.Model
	width       int
	height      int
}

Config holds an image's color model and dimensions.

struct Gray #

struct Gray {
pub mut:
	pix    []u8
	stride int
	rect   Rectangle
}

Gray is an in-memory image of 8-bit grayscale samples.

fn (Gray) color_model #

fn (p Gray) color_model() color.Model

color_model returns the Gray color model.

fn (Gray) bounds #

fn (p Gray) bounds() Rectangle

bounds returns the image bounds.

fn (Gray) at #

fn (p Gray) at(x int, y int) color.Color

at returns the pixel at x, y as a color.

fn (Gray) rgba64_at #

fn (p Gray) rgba64_at(x int, y int) color.RGBA64

rgba64_at returns the pixel at x, y as RGBA64.

fn (Gray) gray_at #

fn (p Gray) gray_at(x int, y int) color.Gray

gray_at returns the pixel at x, y as Gray.

fn (Gray) pix_offset #

fn (p Gray) pix_offset(x int, y int) int

pix_offset returns the first pix index for x, y.

fn (Gray) set #

fn (mut p Gray) set(x int, y int, c color.Color)

set stores c at x, y.

fn (Gray) set_rgba64 #

fn (mut p Gray) set_rgba64(x int, y int, c color.RGBA64)

set_rgba64 stores c at x, y.

fn (Gray) set_gray #

fn (mut p Gray) set_gray(x int, y int, c color.Gray)

set_gray stores c at x, y.

fn (Gray) sub_image #

fn (p Gray) sub_image(r Rectangle) Gray

sub_image returns the portion of p visible through r.

fn (Gray) opaque #

fn (p Gray) opaque() bool

opaque reports whether every pixel is fully opaque.

struct Gray16 #

struct Gray16 {
pub mut:
	pix    []u8
	stride int
	rect   Rectangle
}

Gray16 is an in-memory image of big-endian 16-bit grayscale samples.

fn (Gray16) color_model #

fn (p Gray16) color_model() color.Model

color_model returns the Gray16 color model.

fn (Gray16) bounds #

fn (p Gray16) bounds() Rectangle

bounds returns the image bounds.

fn (Gray16) at #

fn (p Gray16) at(x int, y int) color.Color

at returns the pixel at x, y as a color.

fn (Gray16) rgba64_at #

fn (p Gray16) rgba64_at(x int, y int) color.RGBA64

rgba64_at returns the pixel at x, y as RGBA64.

fn (Gray16) gray16_at #

fn (p Gray16) gray16_at(x int, y int) color.Gray16

gray16_at returns the pixel at x, y as Gray16.

fn (Gray16) pix_offset #

fn (p Gray16) pix_offset(x int, y int) int

pix_offset returns the first pix index for x, y.

fn (Gray16) set #

fn (mut p Gray16) set(x int, y int, c color.Color)

set stores c at x, y.

fn (Gray16) set_rgba64 #

fn (mut p Gray16) set_rgba64(x int, y int, c color.RGBA64)

set_rgba64 stores c at x, y.

fn (Gray16) set_gray16 #

fn (mut p Gray16) set_gray16(x int, y int, c color.Gray16)

set_gray16 stores c at x, y.

fn (Gray16) sub_image #

fn (p Gray16) sub_image(r Rectangle) Gray16

sub_image returns the portion of p visible through r.

fn (Gray16) opaque #

fn (p Gray16) opaque() bool

opaque reports whether every pixel is fully opaque.

struct NRGBA #

struct NRGBA {
pub mut:
	pix    []u8
	stride int
	rect   Rectangle
}

NRGBA is an in-memory image with non-alpha-premultiplied R, G, B, A bytes.

fn (NRGBA) color_model #

fn (p NRGBA) color_model() color.Model

color_model returns the NRGBA color model.

fn (NRGBA) bounds #

fn (p NRGBA) bounds() Rectangle

bounds returns the image bounds.

fn (NRGBA) at #

fn (p NRGBA) at(x int, y int) color.Color

at returns the pixel at x, y as a color.

fn (NRGBA) rgba64_at #

fn (p NRGBA) rgba64_at(x int, y int) color.RGBA64

rgba64_at returns the pixel at x, y as RGBA64.

fn (NRGBA) nrgba_at #

fn (p NRGBA) nrgba_at(x int, y int) color.NRGBA

nrgba_at returns the pixel at x, y as NRGBA.

fn (NRGBA) pix_offset #

fn (p NRGBA) pix_offset(x int, y int) int

pix_offset returns the first pix index for x, y.

fn (NRGBA) set #

fn (mut p NRGBA) set(x int, y int, c color.Color)

set stores c at x, y.

fn (NRGBA) set_rgba64 #

fn (mut p NRGBA) set_rgba64(x int, y int, c color.RGBA64)

set_rgba64 stores c at x, y after converting to non-premultiplied RGBA.

fn (NRGBA) set_nrgba #

fn (mut p NRGBA) set_nrgba(x int, y int, c color.NRGBA)

set_nrgba stores c at x, y.

fn (NRGBA) sub_image #

fn (p NRGBA) sub_image(r Rectangle) NRGBA

sub_image returns the portion of p visible through r.

fn (NRGBA) opaque #

fn (p NRGBA) opaque() bool

opaque reports whether every pixel is fully opaque.

struct NRGBA64 #

struct NRGBA64 {
pub mut:
	pix    []u8
	stride int
	rect   Rectangle
}

NRGBA64 is an in-memory image with non-premultiplied big-endian 16-bit channels.

fn (NRGBA64) color_model #

fn (p NRGBA64) color_model() color.Model

color_model returns the NRGBA64 color model.

fn (NRGBA64) bounds #

fn (p NRGBA64) bounds() Rectangle

bounds returns the image bounds.

fn (NRGBA64) at #

fn (p NRGBA64) at(x int, y int) color.Color

at returns the pixel at x, y as a color.

fn (NRGBA64) rgba64_at #

fn (p NRGBA64) rgba64_at(x int, y int) color.RGBA64

rgba64_at returns the pixel at x, y as RGBA64.

fn (NRGBA64) nrgba64_at #

fn (p NRGBA64) nrgba64_at(x int, y int) color.NRGBA64

nrgba64_at returns the pixel at x, y as NRGBA64.

fn (NRGBA64) pix_offset #

fn (p NRGBA64) pix_offset(x int, y int) int

pix_offset returns the first pix index for x, y.

fn (NRGBA64) set #

fn (mut p NRGBA64) set(x int, y int, c color.Color)

set stores c at x, y.

fn (NRGBA64) set_rgba64 #

fn (mut p NRGBA64) set_rgba64(x int, y int, c color.RGBA64)

set_rgba64 stores c at x, y after converting to non-premultiplied RGBA.

fn (NRGBA64) set_nrgba64 #

fn (mut p NRGBA64) set_nrgba64(x int, y int, c color.NRGBA64)

set_nrgba64 stores c at x, y.

fn (NRGBA64) sub_image #

fn (p NRGBA64) sub_image(r Rectangle) NRGBA64

sub_image returns the portion of p visible through r.

fn (NRGBA64) opaque #

fn (p NRGBA64) opaque() bool

opaque reports whether every pixel is fully opaque.

struct NYCbCrA #

struct NYCbCrA {
pub mut:
	ycbcr    YCbCr
	a        []u8
	a_stride int
}

NYCbCrA is an in-memory image of non-alpha-premultiplied Y'CbCr with alpha.

fn (NYCbCrA) color_model #

fn (p NYCbCrA) color_model() color.Model

color_model returns the NYCbCrA color model.

fn (NYCbCrA) bounds #

fn (p NYCbCrA) bounds() Rectangle

bounds returns the image bounds.

fn (NYCbCrA) at #

fn (p NYCbCrA) at(x int, y int) color.Color

at returns the pixel at x, y as a color.

fn (NYCbCrA) rgba64_at #

fn (p NYCbCrA) rgba64_at(x int, y int) color.RGBA64

rgba64_at returns the pixel at x, y as RGBA64.

fn (NYCbCrA) nycbcra_at #

fn (p NYCbCrA) nycbcra_at(x int, y int) color.NYCbCrA

nycbcra_at returns the pixel at x, y as NYCbCrA.

fn (NYCbCrA) a_offset #

fn (p NYCbCrA) a_offset(x int, y int) int

a_offset returns the first alpha index for x, y.

fn (NYCbCrA) sub_image #

fn (p NYCbCrA) sub_image(r Rectangle) NYCbCrA

sub_image returns the portion of p visible through r.

fn (NYCbCrA) opaque #

fn (p NYCbCrA) opaque() bool

opaque reports whether every pixel is fully opaque.

struct Paletted #

struct Paletted {
pub mut:
	pix     []u8
	stride  int
	rect    Rectangle
	palette color.Palette
}

Paletted is an in-memory image of palette indices.

fn (Paletted) color_model #

fn (p Paletted) color_model() color.Model

color_model returns the image palette.

fn (Paletted) bounds #

fn (p Paletted) bounds() Rectangle

bounds returns the image bounds.

fn (Paletted) at #

fn (p Paletted) at(x int, y int) color.Color

at returns the color at x, y.

fn (Paletted) rgba64_at #

fn (p Paletted) rgba64_at(x int, y int) color.RGBA64

rgba64_at returns the color at x, y as RGBA64.

fn (Paletted) pix_offset #

fn (p Paletted) pix_offset(x int, y int) int

pix_offset returns the first pix index for x, y.

fn (Paletted) set #

fn (mut p Paletted) set(x int, y int, c color.Color)

set stores c's nearest palette index at x, y.

fn (Paletted) set_rgba64 #

fn (mut p Paletted) set_rgba64(x int, y int, c color.RGBA64)

set_rgba64 stores c's nearest palette index at x, y.

fn (Paletted) color_index_at #

fn (p Paletted) color_index_at(x int, y int) u8

color_index_at returns the palette index at x, y.

fn (Paletted) set_color_index #

fn (mut p Paletted) set_color_index(x int, y int, index u8)

set_color_index stores index at x, y.

fn (Paletted) sub_image #

fn (p Paletted) sub_image(r Rectangle) Paletted

sub_image returns the portion of p visible through r.

fn (Paletted) opaque #

fn (p Paletted) opaque() bool

opaque reports whether every referenced palette color is fully opaque.

struct Point #

struct Point {
pub mut:
	x int
	y int
}

Point is an x, y coordinate pair. Axes increase right and down.

fn (Point) str #

fn (p Point) str() string

str returns a string representation like (3,4).

fn (Point) add #

fn (p Point) add(q Point) Point

add returns the vector p + q.

fn (Point) sub #

fn (p Point) sub(q Point) Point

sub returns the vector p - q.

fn (Point) mul #

fn (p Point) mul(k int) Point

mul returns the vector p * k.

fn (Point) div #

fn (p Point) div(k int) Point

div returns the vector p / k.

fn (Point) in_rect #

fn (p Point) in_rect(r Rectangle) bool

in_rect reports whether p is inside r.

fn (Point) mod #

fn (p Point) mod(r Rectangle) Point

mod returns the point q in r where p - q is a multiple of r's size.

fn (Point) eq #

fn (p Point) eq(q Point) bool

eq reports whether p and q are equal.

struct RGBA #

struct RGBA {
pub mut:
	pix    []u8
	stride int
	rect   Rectangle
}

RGBA is an in-memory image with pixels in R, G, B, A byte order.

fn (RGBA) color_model #

fn (p RGBA) color_model() color.Model

color_model returns the RGBA color model.

fn (RGBA) bounds #

fn (p RGBA) bounds() Rectangle

bounds returns the image bounds.

fn (RGBA) at #

fn (p RGBA) at(x int, y int) color.Color

at returns the pixel at x, y as a color.

fn (RGBA) rgba64_at #

fn (p RGBA) rgba64_at(x int, y int) color.RGBA64

rgba64_at returns the pixel at x, y as RGBA64.

fn (RGBA) rgba_at #

fn (p RGBA) rgba_at(x int, y int) color.RGBA

rgba_at returns the pixel at x, y as RGBA.

fn (RGBA) pix_offset #

fn (p RGBA) pix_offset(x int, y int) int

pix_offset returns the first pix index for x, y.

fn (RGBA) set #

fn (mut p RGBA) set(x int, y int, c color.Color)

set stores c at x, y.

fn (RGBA) set_rgba64 #

fn (mut p RGBA) set_rgba64(x int, y int, c color.RGBA64)

set_rgba64 stores c at x, y.

fn (RGBA) set_rgba #

fn (mut p RGBA) set_rgba(x int, y int, c color.RGBA)

set_rgba stores c at x, y.

fn (RGBA) sub_image #

fn (p RGBA) sub_image(r Rectangle) RGBA

sub_image returns the portion of p visible through r.

fn (RGBA) opaque #

fn (p RGBA) opaque() bool

opaque reports whether every pixel is fully opaque.

struct RGBA64 #

struct RGBA64 {
pub mut:
	pix    []u8
	stride int
	rect   Rectangle
}

RGBA64 is an in-memory image with big-endian 16-bit RGBA channels.

fn (RGBA64) color_model #

fn (p RGBA64) color_model() color.Model

color_model returns the RGBA64 color model.

fn (RGBA64) bounds #

fn (p RGBA64) bounds() Rectangle

bounds returns the image bounds.

fn (RGBA64) at #

fn (p RGBA64) at(x int, y int) color.Color

at returns the pixel at x, y as a color.

fn (RGBA64) rgba64_at #

fn (p RGBA64) rgba64_at(x int, y int) color.RGBA64

rgba64_at returns the pixel at x, y as RGBA64.

fn (RGBA64) pix_offset #

fn (p RGBA64) pix_offset(x int, y int) int

pix_offset returns the first pix index for x, y.

fn (RGBA64) set #

fn (mut p RGBA64) set(x int, y int, c color.Color)

set stores c at x, y.

fn (RGBA64) set_rgba64 #

fn (mut p RGBA64) set_rgba64(x int, y int, c color.RGBA64)

set_rgba64 stores c at x, y.

fn (RGBA64) sub_image #

fn (p RGBA64) sub_image(r Rectangle) RGBA64

sub_image returns the portion of p visible through r.

fn (RGBA64) opaque #

fn (p RGBA64) opaque() bool

opaque reports whether every pixel is fully opaque.

struct Rectangle #

struct Rectangle {
pub mut:
	min Point
	max Point
}

Rectangle contains points where min.x <= x < max.x and min.y <= y < max.y.

fn (Rectangle) str #

fn (r Rectangle) str() string

str returns a string representation like (3,4)-(6,5).

fn (Rectangle) dx #

fn (r Rectangle) dx() int

dx returns r's width.

fn (Rectangle) dy #

fn (r Rectangle) dy() int

dy returns r's height.

fn (Rectangle) size #

fn (r Rectangle) size() Point

size returns r's width and height as a Point.

fn (Rectangle) add #

fn (r Rectangle) add(p Point) Rectangle

add returns r translated by p.

fn (Rectangle) sub #

fn (r Rectangle) sub(p Point) Rectangle

sub returns r translated by -p.

fn (Rectangle) inset #

fn (r Rectangle) inset(n int) Rectangle

inset returns r inset by n. A negative n expands the rectangle.

fn (Rectangle) intersect #

fn (r Rectangle) intersect(s Rectangle) Rectangle

intersect returns the largest rectangle contained by r and s.

fn (Rectangle) union #

fn (r Rectangle) union(s Rectangle) Rectangle

union returns the smallest rectangle containing r and s.

fn (Rectangle) empty #

fn (r Rectangle) empty() bool

empty reports whether r contains no points.

fn (Rectangle) eq #

fn (r Rectangle) eq(s Rectangle) bool

eq reports whether r and s contain the same set of points.

fn (Rectangle) overlaps #

fn (r Rectangle) overlaps(s Rectangle) bool

overlaps reports whether r and s have a non-empty intersection.

fn (Rectangle) inside #

fn (r Rectangle) inside(s Rectangle) bool

inside reports whether every point in r is inside s.

fn (Rectangle) canon #

fn (r Rectangle) canon() Rectangle

canon returns r with min and max swapped if needed.

fn (Rectangle) at #

fn (r Rectangle) at(x int, y int) color.Color

at returns opaque white for points inside r and transparent otherwise.

fn (Rectangle) rgba64_at #

fn (r Rectangle) rgba64_at(x int, y int) color.RGBA64

rgba64_at returns opaque white for points inside r and transparent otherwise.

fn (Rectangle) bounds #

fn (r Rectangle) bounds() Rectangle

bounds returns r.

fn (Rectangle) color_model #

fn (r Rectangle) color_model() color.Model

color_model returns the color model for rectangles.

struct Uniform #

struct Uniform {
pub mut:
	c color.Color
}

Uniform is an infinite image of a single color.

fn (Uniform) rgba #

fn (u Uniform) rgba() (u32, u32, u32, u32)

rgba returns the uniform color as alpha-premultiplied 16-bit channels.

fn (Uniform) color_model #

fn (u Uniform) color_model() color.Model

color_model returns a model that converts every color to u.c.

fn (Uniform) convert #

fn (u Uniform) convert(c color.Color) color.Color

convert converts any color to the uniform color.

fn (Uniform) bounds #

fn (u Uniform) bounds() Rectangle

bounds returns a large rectangle for the infinite uniform image.

fn (Uniform) at #

fn (u Uniform) at(x int, y int) color.Color

at returns the uniform image color.

fn (Uniform) rgba64_at #

fn (u Uniform) rgba64_at(x int, y int) color.RGBA64

rgba64_at returns the uniform image color as RGBA64.

fn (Uniform) opaque #

fn (u Uniform) opaque() bool

opaque reports whether the uniform image is fully opaque.

struct YCbCr #

struct YCbCr {
pub mut:
	y               []u8
	cb              []u8
	cr              []u8
	y_stride        int
	c_stride        int
	subsample_ratio YCbCrSubsampleRatio
	rect            Rectangle
}

YCbCr is an in-memory image of Y'CbCr colors.

fn (YCbCr) color_model #

fn (p YCbCr) color_model() color.Model

color_model returns the YCbCr color model.

fn (YCbCr) bounds #

fn (p YCbCr) bounds() Rectangle

bounds returns the image bounds.

fn (YCbCr) at #

fn (p YCbCr) at(x int, y int) color.Color

at returns the pixel at x, y as a color.

fn (YCbCr) rgba64_at #

fn (p YCbCr) rgba64_at(x int, y int) color.RGBA64

rgba64_at returns the pixel at x, y as RGBA64.

fn (YCbCr) ycbcr_at #

fn (p YCbCr) ycbcr_at(x int, y int) color.YCbCr

ycbcr_at returns the pixel at x, y as YCbCr.

fn (YCbCr) y_offset #

fn (p YCbCr) y_offset(x int, y int) int

y_offset returns the first Y index for x, y.

fn (YCbCr) c_offset #

fn (p YCbCr) c_offset(x int, y int) int

c_offset returns the first Cb or Cr index for x, y.

fn (YCbCr) sub_image #

fn (p YCbCr) sub_image(r Rectangle) YCbCr

sub_image returns the portion of p visible through r.

fn (YCbCr) opaque #

fn (p YCbCr) opaque() bool

opaque reports whether every pixel is fully opaque.