image

package
v0.0.0-...-e758773 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2011 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package image implements a basic 2-D image library.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Black is an opaque black ColorImage.
	Black = NewColorImage(Gray16Color{0})
	// White is an opaque white ColorImage.
	White = NewColorImage(Gray16Color{0xffff})
	// Transparent is a fully transparent ColorImage.
	Transparent = NewColorImage(Alpha16Color{0})
	// Opaque is a fully opaque ColorImage.
	Opaque = NewColorImage(Alpha16Color{0xffff})
)
View Source
var UnknownFormatErr = os.NewError("image: unknown format")

An UnknownFormatErr indicates that decoding encountered an unknown format.

Functions

func RegisterFormat

func RegisterFormat(name, magic string, decode func(io.Reader) (Image, os.Error), decodeConfig func(io.Reader) (Config, os.Error))

RegisterFormat registers an image format for use by Decode. Name is the name of the format, like "jpeg" or "png". Magic is the magic prefix that identifies the format's encoding. The magic string can contain "?" wildcards that each match any one byte. Decode is the function that decodes the encoded image. DecodeConfig is the function that decodes just its configuration.

Types

type Alpha

type Alpha struct {
	// Pix holds the image's pixels. The pixel at (x, y) is Pix[y*Stride+x].
	Pix    []AlphaColor
	Stride int
	// Rect is the image's bounds.
	Rect Rectangle
}

An Alpha is an in-memory image of AlphaColor values.

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) Bounds

func (p *Alpha) Bounds() Rectangle

func (*Alpha) ColorModel

func (p *Alpha) ColorModel() ColorModel

func (*Alpha) Opaque

func (p *Alpha) Opaque() bool

Opaque scans the entire image and returns whether or not it is fully opaque.

func (*Alpha) Set

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

func (*Alpha) SetAlpha

func (p *Alpha) SetAlpha(x, y int, c AlphaColor)

func (*Alpha) SubImage

func (p *Alpha) SubImage(r Rectangle) Image

SubImage returns an image representing the portion of the image p visible through r. The returned value shares pixels with the original image.

type Alpha16

type Alpha16 struct {
	// Pix holds the image's pixels. The pixel at (x, y) is Pix[y*Stride+x].
	Pix    []Alpha16Color
	Stride int
	// Rect is the image's bounds.
	Rect Rectangle
}

An Alpha16 is an in-memory image of Alpha16Color values.

func NewAlpha16

func NewAlpha16(w, h int) *Alpha16

NewAlpha16 returns a new Alpha16 with the given width and height.

func (*Alpha16) At

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

func (*Alpha16) Bounds

func (p *Alpha16) Bounds() Rectangle

func (*Alpha16) ColorModel

func (p *Alpha16) ColorModel() ColorModel

func (*Alpha16) Opaque

func (p *Alpha16) Opaque() bool

Opaque scans the entire image and returns whether or not it is fully opaque.

func (*Alpha16) Set

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

func (*Alpha16) SetAlpha16

func (p *Alpha16) SetAlpha16(x, y int, c Alpha16Color)

func (*Alpha16) SubImage

func (p *Alpha16) SubImage(r Rectangle) Image

SubImage returns an image representing the portion of the image p visible through r. The returned value shares pixels with the original image.

type Alpha16Color

type Alpha16Color struct {
	A uint16
}

An Alpha16Color represents a 16-bit alpha.

func (Alpha16Color) RGBA

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

type AlphaColor

type AlphaColor struct {
	A uint8
}

An AlphaColor represents an 8-bit alpha.

func (AlphaColor) RGBA

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

type Color

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

All Colors can convert themselves, with a possible loss of precision, to 64-bit alpha-premultiplied RGBA. Each channel value ranges within [0, 0xFFFF].

type ColorImage

type ColorImage struct {
	C Color
}

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

func NewColorImage

func NewColorImage(c Color) *ColorImage

func (*ColorImage) At

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

func (*ColorImage) Bounds

func (c *ColorImage) Bounds() Rectangle

func (*ColorImage) ColorModel

func (c *ColorImage) ColorModel() ColorModel

func (*ColorImage) Opaque

func (c *ColorImage) Opaque() bool

Opaque scans the entire image and returns whether or not it is fully opaque.

func (*ColorImage) RGBA

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

type ColorModel

type ColorModel interface {
	Convert(c Color) Color
}

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

var Alpha16ColorModel ColorModel = ColorModelFunc(toAlpha16Color)

The ColorModel associated with Alpha16Color.

var AlphaColorModel ColorModel = ColorModelFunc(toAlphaColor)

The ColorModel associated with AlphaColor.

var Gray16ColorModel ColorModel = ColorModelFunc(toGray16Color)

The ColorModel associated with Gray16Color.

var GrayColorModel ColorModel = ColorModelFunc(toGrayColor)

The ColorModel associated with GrayColor.

var NRGBA64ColorModel ColorModel = ColorModelFunc(toNRGBA64Color)

The ColorModel associated with NRGBA64Color.

var NRGBAColorModel ColorModel = ColorModelFunc(toNRGBAColor)

The ColorModel associated with NRGBAColor.

var RGBA64ColorModel ColorModel = ColorModelFunc(toRGBA64Color)

The ColorModel associated with RGBA64Color.

var RGBAColorModel ColorModel = ColorModelFunc(toRGBAColor)

The ColorModel associated with RGBAColor.

type ColorModelFunc

type ColorModelFunc func(Color) Color

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.

func (ColorModelFunc) Convert

func (f ColorModelFunc) Convert(c Color) Color

type Config

type Config struct {
	ColorModel    ColorModel
	Width, Height int
}

A Config consists of an image's color model and dimensions.

func DecodeConfig

func DecodeConfig(r io.Reader) (Config, string, os.Error)

DecodeConfig decodes the color model and dimensions of an image that has been encoded in a registered format. The string returned is the format name used during format registration. Format registration is typically done by the init method of the codec-specific package.

type Gray

type Gray struct {
	// Pix holds the image's pixels. The pixel at (x, y) is Pix[y*Stride+x].
	Pix    []GrayColor
	Stride int
	// Rect is the image's bounds.
	Rect Rectangle
}

A Gray is an in-memory image of GrayColor values.

func NewGray

func NewGray(w, h int) *Gray

NewGray returns a new Gray with the given width and height.

func (*Gray) At

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

func (*Gray) Bounds

func (p *Gray) Bounds() Rectangle

func (*Gray) ColorModel

func (p *Gray) ColorModel() ColorModel

func (*Gray) Opaque

func (p *Gray) Opaque() bool

Opaque scans the entire image and returns whether or not it is fully opaque.

func (*Gray) Set

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

func (*Gray) SetGray

func (p *Gray) SetGray(x, y int, c GrayColor)

func (*Gray) SubImage

func (p *Gray) SubImage(r Rectangle) Image

SubImage returns an image representing the portion of the image p visible through r. The returned value shares pixels with the original image.

type Gray16

type Gray16 struct {
	// Pix holds the image's pixels. The pixel at (x, y) is Pix[y*Stride+x].
	Pix    []Gray16Color
	Stride int
	// Rect is the image's bounds.
	Rect Rectangle
}

A Gray16 is an in-memory image of Gray16Color values.

func NewGray16

func NewGray16(w, h int) *Gray16

NewGray16 returns a new Gray16 with the given width and height.

func (*Gray16) At

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

func (*Gray16) Bounds

func (p *Gray16) Bounds() Rectangle

func (*Gray16) ColorModel

func (p *Gray16) ColorModel() ColorModel

func (*Gray16) Opaque

func (p *Gray16) Opaque() bool

Opaque scans the entire image and returns whether or not it is fully opaque.

func (*Gray16) Set

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

func (*Gray16) SetGray16

func (p *Gray16) SetGray16(x, y int, c Gray16Color)

func (*Gray16) SubImage

func (p *Gray16) SubImage(r Rectangle) Image

SubImage returns an image representing the portion of the image p visible through r. The returned value shares pixels with the original image.

type Gray16Color

type Gray16Color struct {
	Y uint16
}

A Gray16Color represents a 16-bit grayscale color.

func (Gray16Color) RGBA

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

type GrayColor

type GrayColor struct {
	Y uint8
}

A GrayColor represents an 8-bit grayscale color.

func (GrayColor) RGBA

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

type Image

type Image interface {
	// ColorModel returns the Image's ColorModel.
	ColorModel() ColorModel
	// Bounds returns the domain for which At can return non-zero color.
	// The bounds do not necessarily contain the point (0, 0).
	Bounds() Rectangle
	// At returns the color of the pixel at (x, y).
	// At(Bounds().Min.X, Bounds().Min.Y) returns the upper-left pixel of the grid.
	// At(Bounds().Max.X-1, Bounds().Max.Y-1) returns the lower-right one.
	At(x, y int) Color
}

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

func Decode

func Decode(r io.Reader) (Image, string, os.Error)

Decode decodes an image that has been encoded in a registered format. The string returned is the format name used during format registration. Format registration is typically done by the init method of the codec- specific package.

type NRGBA

type NRGBA struct {
	// Pix holds the image's pixels. The pixel at (x, y) is Pix[y*Stride+x].
	Pix    []NRGBAColor
	Stride int
	// Rect is the image's bounds.
	Rect Rectangle
}

An NRGBA is an in-memory image of NRGBAColor values.

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) Bounds

func (p *NRGBA) Bounds() Rectangle

func (*NRGBA) ColorModel

func (p *NRGBA) ColorModel() ColorModel

func (*NRGBA) Opaque

func (p *NRGBA) Opaque() bool

Opaque scans the entire image and returns whether or not it is fully opaque.

func (*NRGBA) Set

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

func (*NRGBA) SetNRGBA

func (p *NRGBA) SetNRGBA(x, y int, c NRGBAColor)

func (*NRGBA) SubImage

func (p *NRGBA) SubImage(r Rectangle) Image

SubImage returns an image representing the portion of the image p visible through r. The returned value shares pixels with the original image.

type NRGBA64

type NRGBA64 struct {
	// Pix holds the image's pixels. The pixel at (x, y) is Pix[y*Stride+x].
	Pix    []NRGBA64Color
	Stride int
	// Rect is the image's bounds.
	Rect Rectangle
}

An NRGBA64 is an in-memory image of NRGBA64Color values.

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) Bounds

func (p *NRGBA64) Bounds() Rectangle

func (*NRGBA64) ColorModel

func (p *NRGBA64) ColorModel() ColorModel

func (*NRGBA64) Opaque

func (p *NRGBA64) Opaque() bool

Opaque scans the entire image and returns whether or not it is fully opaque.

func (*NRGBA64) Set

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

func (*NRGBA64) SetNRGBA64

func (p *NRGBA64) SetNRGBA64(x, y int, c NRGBA64Color)

func (*NRGBA64) SubImage

func (p *NRGBA64) SubImage(r Rectangle) Image

SubImage returns an image representing the portion of the image p visible through r. The returned value shares pixels with the original image.

type NRGBA64Color

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

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

func (NRGBA64Color) RGBA

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

type NRGBAColor

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

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

func (NRGBAColor) RGBA

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

type Paletted

type Paletted struct {
	// Pix holds the image's pixels. The pixel at (x, y) is Pix[y*Stride+x].
	Pix    []uint8
	Stride int
	// Rect is the image's bounds.
	Rect Rectangle
	// Palette is the image's palette.
	Palette PalettedColorModel
}

A Paletted is an in-memory image backed by a 2-D slice of uint8 values and a 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) Bounds

func (p *Paletted) Bounds() Rectangle

func (*Paletted) ColorIndexAt

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

func (*Paletted) ColorModel

func (p *Paletted) ColorModel() ColorModel

func (*Paletted) Opaque

func (p *Paletted) Opaque() bool

Opaque scans the entire image and returns whether or not it is fully opaque.

func (*Paletted) SetColorIndex

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

func (*Paletted) SubImage

func (p *Paletted) SubImage(r Rectangle) Image

SubImage returns an image representing the portion of the image p visible through r. The returned value shares pixels with the original image.

type PalettedColorModel

type PalettedColorModel []Color

A PalettedColorModel represents a fixed palette of colors.

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 Point

type Point struct {
	X, Y int
}

A Point is an X, Y coordinate pair. The axes increase right and down.

var ZP Point

ZP is the zero Point.

func Pt

func Pt(X, Y int) Point

Pt is shorthand for Point{X, Y}.

func (Point) Add

func (p Point) Add(q Point) Point

Add returns the vector p+q.

func (Point) Div

func (p Point) Div(k int) Point

Div returns the vector p/k.

func (Point) Eq

func (p Point) Eq(q Point) bool

Eq returns whether p and q are equal.

func (Point) In

func (p Point) In(r Rectangle) bool

In returns whether p is in r.

func (Point) Mod

func (p Point) Mod(r Rectangle) Point

Mod returns the point q in r such that p.X-q.X is a multiple of r's width and p.Y-q.Y is a multiple of r's height.

func (Point) Mul

func (p Point) Mul(k int) Point

Mul returns the vector p*k.

func (Point) String

func (p Point) String() string

String returns a string representation of p like "(3,4)".

func (Point) Sub

func (p Point) Sub(q Point) Point

Sub returns the vector p-q.

type RGBA

type RGBA struct {
	// Pix holds the image's pixels. The pixel at (x, y) is Pix[y*Stride+x].
	Pix    []RGBAColor
	Stride int
	// Rect is the image's bounds.
	Rect Rectangle
}

An RGBA is an in-memory image of RGBAColor values.

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) Bounds

func (p *RGBA) Bounds() Rectangle

func (*RGBA) ColorModel

func (p *RGBA) ColorModel() ColorModel

func (*RGBA) Opaque

func (p *RGBA) Opaque() bool

Opaque scans the entire image and returns whether or not it is fully opaque.

func (*RGBA) Set

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

func (*RGBA) SetRGBA

func (p *RGBA) SetRGBA(x, y int, c RGBAColor)

func (*RGBA) SubImage

func (p *RGBA) SubImage(r Rectangle) Image

SubImage returns an image representing the portion of the image p visible through r. The returned value shares pixels with the original image.

type RGBA64

type RGBA64 struct {
	// Pix holds the image's pixels. The pixel at (x, y) is Pix[y*Stride+x].
	Pix    []RGBA64Color
	Stride int
	// Rect is the image's bounds.
	Rect Rectangle
}

An RGBA64 is an in-memory image of RGBA64Color values.

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) Bounds

func (p *RGBA64) Bounds() Rectangle

func (*RGBA64) ColorModel

func (p *RGBA64) ColorModel() ColorModel

func (*RGBA64) Opaque

func (p *RGBA64) Opaque() bool

Opaque scans the entire image and returns whether or not it is fully opaque.

func (*RGBA64) Set

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

func (*RGBA64) SetRGBA64

func (p *RGBA64) SetRGBA64(x, y int, c RGBA64Color)

func (*RGBA64) SubImage

func (p *RGBA64) SubImage(r Rectangle) Image

SubImage returns an image representing the portion of the image p visible through r. The returned value shares pixels with the original image.

type RGBA64Color

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

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

func (RGBA64Color) RGBA

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

type RGBAColor

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

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

func (RGBAColor) RGBA

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

type Rectangle

type Rectangle struct {
	Min, Max Point
}

A Rectangle contains the points with Min.X <= X < Max.X, Min.Y <= Y < Max.Y. It is well-formed if Min.X <= Max.X and likewise for Y. Points are always well-formed. A rectangle's methods always return well-formed outputs for well-formed inputs.

var ZR Rectangle

ZR is the zero Rectangle.

func Rect

func Rect(x0, y0, x1, y1 int) Rectangle

Rect is shorthand for Rectangle{Pt(x0, y0), Pt(x1, y1)}.

func (Rectangle) Add

func (r Rectangle) Add(p Point) Rectangle

Add returns the rectangle r translated by p.

func (Rectangle) Canon

func (r Rectangle) Canon() Rectangle

Canon returns the canonical version of r. The returned rectangle has minimum and maximum coordinates swapped if necessary so that it is well-formed.

func (Rectangle) Dx

func (r Rectangle) Dx() int

Dx returns r's width.

func (Rectangle) Dy

func (r Rectangle) Dy() int

Dy returns r's height.

func (Rectangle) Empty

func (r Rectangle) Empty() bool

Empty returns whether the rectangle contains no points.

func (Rectangle) Eq

func (r Rectangle) Eq(s Rectangle) bool

Eq returns whether r and s are equal.

func (Rectangle) In

func (r Rectangle) In(s Rectangle) bool

In returns whether every point in r is in s.

func (Rectangle) Inset

func (r Rectangle) Inset(n int) Rectangle

Inset returns the rectangle r inset by n, which may be negative. If either of r's dimensions is less than 2*n then an empty rectangle near the center of r will be returned.

func (Rectangle) Intersect

func (r Rectangle) Intersect(s Rectangle) Rectangle

Intersect returns the largest rectangle contained by both r and s. If the two rectangles do not overlap then the zero rectangle will be returned.

func (Rectangle) Overlaps

func (r Rectangle) Overlaps(s Rectangle) bool

Overlaps returns whether r and s have a non-empty intersection.

func (Rectangle) Size

func (r Rectangle) Size() Point

Size returns r's width and height.

func (Rectangle) String

func (r Rectangle) String() string

String returns a string representation of r like "(3,4)-(6,5)".

func (Rectangle) Sub

func (r Rectangle) Sub(p Point) Rectangle

Add returns the rectangle r translated by -p.

func (Rectangle) Union

func (r Rectangle) Union(s Rectangle) Rectangle

Union returns the smallest rectangle that contains both r and s.

type Tiled

type Tiled struct {
	I      Image
	Offset Point
}

A Tiled is an infinite-sized Image that repeats another Image in both directions. Tiled{i, p}.At(x, y) will equal i.At(x+p.X, y+p.Y) for all points {x+p.X, y+p.Y} within i's Bounds.

func NewTiled

func NewTiled(i Image, offset Point) *Tiled

func (*Tiled) At

func (t *Tiled) At(x, y int) Color

func (*Tiled) Bounds

func (t *Tiled) Bounds() Rectangle

func (*Tiled) ColorModel

func (t *Tiled) ColorModel() ColorModel

Directories

Path Synopsis
Package bmp implements a BMP image decoder.
Package bmp implements a BMP image decoder.
Package draw provides image composition functions in the style of the Plan 9 graphics library (see http://plan9.bell-labs.com/magic/man2html/2/draw) and the X Render extension.
Package draw provides image composition functions in the style of the Plan 9 graphics library (see http://plan9.bell-labs.com/magic/man2html/2/draw) and the X Render extension.
Package gif implements a GIF image decoder.
Package gif implements a GIF image decoder.
Package jpeg implements a JPEG image decoder and encoder.
Package jpeg implements a JPEG image decoder and encoder.
Package png implements a PNG image decoder and encoder.
Package png implements a PNG image decoder and encoder.
Package tiff implements a TIFF image decoder.
Package tiff implements a TIFF image decoder.
Package ycbcr provides images from the Y'CbCr color model.
Package ycbcr provides images from the Y'CbCr color model.

Jump to

Keyboard shortcuts

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