Package image
import "image"
Package image implements a basic 2-D image library.
See "The Go image package" for an introduction to this package: http://blog.golang.org/2011/09/go-image-package.html
Package files
color.go format.go geom.go image.go names.goVariables
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})
)
An UnknownFormatErr indicates that decoding encountered an unknown format.
var UnknownFormatErr = os.NewError("image: unknown format")
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.
type Alpha
Alpha is an in-memory image of AlphaColor values.
type Alpha struct {
// Pix holds the image's pixels, as alpha values. The pixel at
// (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*1].
Pix []uint8
// Stride is the Pix stride (in bytes) between vertically adjacent pixels.
Stride int
// Rect is the image's bounds.
Rect Rectangle
}
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
Alpha16 is an in-memory image of Alpha16Color values.
type Alpha16 struct {
// Pix holds the image's pixels, as alpha values in big-endian format. The pixel at
// (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*2].
Pix []uint8
// Stride is the Pix stride (in bytes) between vertically adjacent pixels.
Stride int
// Rect is the image's bounds.
Rect Rectangle
}
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
Alpha16Color represents a 16-bit alpha.
type Alpha16Color struct {
A uint16
}
func (Alpha16Color) RGBA
func (c Alpha16Color) RGBA() (r, g, b, a uint32)
type AlphaColor
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
Color can convert itself to alpha-premultiplied RGBA, with a possible loss of precision. Each value ranges within [0, 0xFFFF], but is represented by a uint32 so that multiplying by a blend factor up to 0xFFFF will not overflow.
type Color interface {
RGBA() (r, g, b, a uint32)
}
type ColorImage
A ColorImage is an infinite-sized Image of uniform Color. It implements both the Color and Image interfaces.
type ColorImage struct {
C Color
}
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
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 Alpha16Color.
var Alpha16ColorModel ColorModel = ColorModelFunc(toAlpha16Color)
The ColorModel associated with AlphaColor.
var AlphaColorModel ColorModel = ColorModelFunc(toAlphaColor)
The ColorModel associated with Gray16Color.
var Gray16ColorModel ColorModel = ColorModelFunc(toGray16Color)
The ColorModel associated with GrayColor.
var GrayColorModel ColorModel = ColorModelFunc(toGrayColor)
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 Config
Config holds an image's color model and dimensions.
type Config struct {
ColorModel ColorModel
Width, Height int
}
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
Gray is an in-memory image of GrayColor values.
type Gray struct {
// Pix holds the image's pixels, as gray values. The pixel at
// (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*1].
Pix []uint8
// Stride is the Pix stride (in bytes) between vertically adjacent pixels.
Stride int
// Rect is the image's bounds.
Rect Rectangle
}
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
Gray16 is an in-memory image of Gray16Color values.
type Gray16 struct {
// Pix holds the image's pixels, as gray values in big-endian format. The pixel at
// (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*2].
Pix []uint8
// Stride is the Pix stride (in bytes) between vertically adjacent pixels.
Stride int
// Rect is the image's bounds.
Rect Rectangle
}
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
Gray16Color represents a 16-bit grayscale color.
type Gray16Color struct {
Y uint16
}
func (Gray16Color) RGBA
func (c Gray16Color) RGBA() (r, g, b, a uint32)
type GrayColor
GrayColor represents an 8-bit grayscale color.
type GrayColor struct {
Y uint8
}
func (GrayColor) RGBA
func (c GrayColor) RGBA() (r, g, b, a uint32)
type Image
Image is a finite rectangular grid of Colors drawn from a ColorModel.
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
}
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
NRGBA is an in-memory image of NRGBAColor values.
type NRGBA struct {
// Pix holds the image's pixels, in R, G, B, A order. The pixel at
// (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*4].
Pix []uint8
// Stride is the Pix stride (in bytes) between vertically adjacent pixels.
Stride int
// Rect is the image's bounds.
Rect Rectangle
}
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
NRGBA64 is an in-memory image of NRGBA64Color values.
type NRGBA64 struct {
// Pix holds the image's pixels, in R, G, B, A order and big-endian format. The pixel at
// (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*8].
Pix []uint8
// Stride is the Pix stride (in bytes) between vertically adjacent pixels.
Stride int
// Rect is the image's bounds.
Rect Rectangle
}
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
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
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
Paletted is an in-memory image of uint8 indices into a given palette.
type Paletted struct {
// Pix holds the image's pixels, as palette indices. The pixel at
// (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*1].
Pix []uint8
// Stride is the Pix stride (in bytes) between vertically adjacent pixels.
Stride int
// Rect is the image's bounds.
Rect Rectangle
// Palette is the image's palette.
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) 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) Set
func (p *Paletted) Set(x, y int, c Color)
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
A PalettedColorModel represents a fixed palette of at most 256 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.
func (PalettedColorModel) Index
func (p PalettedColorModel) Index(c Color) int
Index returns the index of the palette color closest to c in Euclidean R,G,B space.
type Point
A Point is an X, Y coordinate pair. The axes increase right and down.
type Point struct {
X, Y int
}
ZP is the zero Point.
var ZP 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
RGBA is an in-memory image of RGBAColor values.
type RGBA struct {
// Pix holds the image's pixels, in R, G, B, A order. The pixel at
// (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*4].
Pix []uint8
// Stride is the Pix stride (in bytes) between vertically adjacent pixels.
Stride int
// Rect is the image's bounds.
Rect Rectangle
}
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
RGBA64 is an in-memory image of RGBA64Color values.
type RGBA64 struct {
// Pix holds the image's pixels, in R, G, B, A order and big-endian format. The pixel at
// (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*8].
Pix []uint8
// Stride is the Pix stride (in bytes) between vertically adjacent pixels.
Stride int
// Rect is the image's bounds.
Rect Rectangle
}
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
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
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)
type Rectangle
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.
type Rectangle struct {
Min, Max Point
}
ZR is the zero Rectangle.
var ZR 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
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.
type Tiled struct {
I Image
Offset Point
}
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
Need more packages? The Package Dashboard provides a list of goinstallable packages.
Subdirectories
| Name | Synopsis | |
|---|---|---|
| .. | ||
| bmp | Package bmp implements a BMP image decoder. | |
| draw | Package draw provides image composition functions. | |
| gif | Package gif implements a GIF image decoder. | |
| jpeg | Package jpeg implements a JPEG image decoder and encoder. | |
| png | Package png implements a PNG image decoder and encoder. | |
| tiff | Package tiff implements a TIFF image decoder. | |
| ycbcr | Package ycbcr provides images from the Y'CbCr color model. |