Go Home Page
The Go Programming Language

Package image

import "image"

The image package implements a basic 2-D image library.

Package files

color.go image.go names.go

Variables

Colors from the HTML 4.01 specification: http://www.w3.org/TR/REC-html40/types.html#h-6.5 These names do not necessarily match those from other lists, such as the X11 color names.

var (
    Aqua    = ColorImage{RGBAColor{0x00, 0xff, 0xff, 0xff}}
    Black   = ColorImage{RGBAColor{0x00, 0x00, 0x00, 0xff}}
    Blue    = ColorImage{RGBAColor{0x00, 0x00, 0xff, 0xff}}
    Fuchsia = ColorImage{RGBAColor{0xff, 0x00, 0xff, 0xff}}
    Gray    = ColorImage{RGBAColor{0x80, 0x80, 0x80, 0xff}}
    Green   = ColorImage{RGBAColor{0x00, 0x80, 0x00, 0xff}}
    Lime    = ColorImage{RGBAColor{0x00, 0xff, 0x00, 0xff}}
    Maroon  = ColorImage{RGBAColor{0x80, 0x00, 0x00, 0xff}}
    Navy    = ColorImage{RGBAColor{0x00, 0x00, 0x80, 0xff}}
    Olive   = ColorImage{RGBAColor{0x80, 0x80, 0x00, 0xff}}
    Red     = ColorImage{RGBAColor{0xff, 0x00, 0x00, 0xff}}
    Purple  = ColorImage{RGBAColor{0x80, 0x00, 0x80, 0xff}}
    Silver  = ColorImage{RGBAColor{0xc0, 0xc0, 0xc0, 0xff}}
    Teal    = ColorImage{RGBAColor{0x00, 0x80, 0x80, 0xff}}
    White   = ColorImage{RGBAColor{0xff, 0xff, 0xff, 0xff}}
    Yellow  = ColorImage{RGBAColor{0xff, 0xff, 0x00, 0xff}}

    // These synonyms are not in HTML 4.01.
    Cyan    = Aqua
    Magenta = Fuchsia
)

type Alpha

An Alpha is an in-memory image backed by a 2-D slice of AlphaColor values.

type Alpha struct {
    // The Pixel field's indices are y first, then x, so that At(x, y) == Pixel[y][x].
    Pixel [][]AlphaColor
}

func NewAlpha

func NewAlpha(w, h int) *Alpha

NewAlpha returns a new Alpha with the given width and height.

func (*Alpha) At

func (p *Alpha) At(x, y int) Color

func (*Alpha) ColorModel

func (p *Alpha) ColorModel() ColorModel

func (*Alpha) Height

func (p *Alpha) Height() int

func (*Alpha) Set

func (p *Alpha) Set(x, y int, c Color)

func (*Alpha) Width

func (p *Alpha) Width() int

type AlphaColor

An AlphaColor represents an 8-bit alpha.

type AlphaColor struct {
    A uint8
}

func (AlphaColor) RGBA

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

type Color

All Colors can convert themselves, with a possible loss of precision, to 128-bit alpha-premultiplied RGBA.

type Color interface {
    RGBA() (r, g, b, a uint32)
}

type ColorImage

A ColorImage is a practically infinite-sized Image of uniform Color. It implements both the Color and Image interfaces.

type ColorImage struct {
    C Color
}

func (ColorImage) At

func (c ColorImage) At(x, y int) Color

func (ColorImage) ColorModel

func (c ColorImage) ColorModel() ColorModel

func (ColorImage) Height

func (c ColorImage) Height() int

func (ColorImage) RGBA

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

func (ColorImage) Width

func (c ColorImage) Width() int

type ColorModel

A ColorModel can convert foreign Colors, with a possible loss of precision, to a Color from its own color model.

type ColorModel interface {
    Convert(c Color) Color
}

The ColorModel associated with AlphaColor.

var AlphaColorModel ColorModel = ColorModelFunc(toAlphaColor)

The ColorModel associated with NRGBA64Color.

var NRGBA64ColorModel ColorModel = ColorModelFunc(toNRGBA64Color)

The ColorModel associated with NRGBAColor.

var NRGBAColorModel ColorModel = ColorModelFunc(toNRGBAColor)

The ColorModel associated with RGBA64Color.

var RGBA64ColorModel ColorModel = ColorModelFunc(toRGBA64Color)

The ColorModel associated with RGBAColor.

var RGBAColorModel ColorModel = ColorModelFunc(toRGBAColor)

type ColorModelFunc

The ColorModelFunc type is an adapter to allow the use of an ordinary color conversion function as a ColorModel. If f is such a function, ColorModelFunc(f) is a ColorModel object that invokes f to implement the conversion.

type ColorModelFunc func(Color) Color

func (ColorModelFunc) Convert

func (f ColorModelFunc) Convert(c Color) Color

type Image

An Image is a rectangular grid of Colors drawn from a ColorModel.

type Image interface {
    ColorModel() ColorModel
    Width() int
    Height() int
    // At(0, 0) returns the upper-left pixel of the grid.
    // At(Width()-1, Height()-1) returns the lower-right pixel.
    At(x, y int) Color
}

type NRGBA

A NRGBA is an in-memory image backed by a 2-D slice of NRGBAColor values.

type NRGBA struct {
    // The Pixel field's indices are y first, then x, so that At(x, y) == Pixel[y][x].
    Pixel [][]NRGBAColor
}

func NewNRGBA

func NewNRGBA(w, h int) *NRGBA

NewNRGBA returns a new NRGBA with the given width and height.

func (*NRGBA) At

func (p *NRGBA) At(x, y int) Color

func (*NRGBA) ColorModel

func (p *NRGBA) ColorModel() ColorModel

func (*NRGBA) Height

func (p *NRGBA) Height() int

func (*NRGBA) Set

func (p *NRGBA) Set(x, y int, c Color)

func (*NRGBA) Width

func (p *NRGBA) Width() int

type NRGBA64

A NRGBA64 is an in-memory image backed by a 2-D slice of NRGBA64Color values.

type NRGBA64 struct {
    // The Pixel field's indices are y first, then x, so that At(x, y) == Pixel[y][x].
    Pixel [][]NRGBA64Color
}

func NewNRGBA64

func NewNRGBA64(w, h int) *NRGBA64

NewNRGBA64 returns a new NRGBA64 with the given width and height.

func (*NRGBA64) At

func (p *NRGBA64) At(x, y int) Color

func (*NRGBA64) ColorModel

func (p *NRGBA64) ColorModel() ColorModel

func (*NRGBA64) Height

func (p *NRGBA64) Height() int

func (*NRGBA64) Set

func (p *NRGBA64) Set(x, y int, c Color)

func (*NRGBA64) Width

func (p *NRGBA64) Width() int

type NRGBA64Color

An NRGBA64Color represents a non-alpha-premultiplied 64-bit color, having 16 bits for each of red, green, blue and alpha.

type NRGBA64Color struct {
    R, G, B, A uint16
}

func (NRGBA64Color) RGBA

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

type NRGBAColor

An NRGBAColor represents a non-alpha-premultiplied 32-bit color.

type NRGBAColor struct {
    R, G, B, A uint8
}

func (NRGBAColor) RGBA

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

type Paletted

A Paletted is an in-memory image backed by a 2-D slice of uint8 values and a PalettedColorModel.

type Paletted struct {
    // The Pixel field's indices are y first, then x, so that At(x, y) == Palette[Pixel[y][x]].
    Pixel   [][]uint8
    Palette PalettedColorModel
}

func NewPaletted

func NewPaletted(w, h int, m PalettedColorModel) *Paletted

NewPaletted returns a new Paletted with the given width, height and palette.

func (*Paletted) At

func (p *Paletted) At(x, y int) Color

func (*Paletted) ColorIndexAt

func (p *Paletted) ColorIndexAt(x, y int) uint8

func (*Paletted) ColorModel

func (p *Paletted) ColorModel() ColorModel

func (*Paletted) Height

func (p *Paletted) Height() int

func (*Paletted) SetColorIndex

func (p *Paletted) SetColorIndex(x, y int, index uint8)

func (*Paletted) Width

func (p *Paletted) Width() int

type PalettedColorModel

A PalettedColorModel represents a fixed palette of colors.

type PalettedColorModel []Color

func (PalettedColorModel) Convert

func (p PalettedColorModel) Convert(c Color) Color

Convert returns the palette color closest to c in Euclidean R,G,B space.

type RGBA

An RGBA is an in-memory image backed by a 2-D slice of RGBAColor values.

type RGBA struct {
    // The Pixel field's indices are y first, then x, so that At(x, y) == Pixel[y][x].
    Pixel [][]RGBAColor
}

func NewRGBA

func NewRGBA(w, h int) *RGBA

NewRGBA returns a new RGBA with the given width and height.

func (*RGBA) At

func (p *RGBA) At(x, y int) Color

func (*RGBA) ColorModel

func (p *RGBA) ColorModel() ColorModel

func (*RGBA) Height

func (p *RGBA) Height() int

func (*RGBA) Set

func (p *RGBA) Set(x, y int, c Color)

func (*RGBA) Width

func (p *RGBA) Width() int

type RGBA64

An RGBA64 is an in-memory image backed by a 2-D slice of RGBA64Color values.

type RGBA64 struct {
    // The Pixel field's indices are y first, then x, so that At(x, y) == Pixel[y][x].
    Pixel [][]RGBA64Color
}

func NewRGBA64

func NewRGBA64(w, h int) *RGBA64

NewRGBA64 returns a new RGBA64 with the given width and height.

func (*RGBA64) At

func (p *RGBA64) At(x, y int) Color

func (*RGBA64) ColorModel

func (p *RGBA64) ColorModel() ColorModel

func (*RGBA64) Height

func (p *RGBA64) Height() int

func (*RGBA64) Set

func (p *RGBA64) Set(x, y int, c Color)

func (*RGBA64) Width

func (p *RGBA64) Width() int

type RGBA64Color

An RGBA64Color represents a 64-bit alpha-premultiplied color, having 16 bits for each of red, green, blue and alpha.

type RGBA64Color struct {
    R, G, B, A uint16
}

func (RGBA64Color) RGBA

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

type RGBAColor

An RGBAColor represents a traditional 32-bit alpha-premultiplied color, having 8 bits for each of red, green, blue and alpha.

type RGBAColor struct {
    R, G, B, A uint8
}

func (RGBAColor) RGBA

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

Subdirectories

Name   Synopsis
..
jpeg The jpeg package implements a decoder for JPEG images, as defined in ITU-T T.81.
png The png package implements a PNG image decoder and encoder.