Package image
import "image"
The image package implements a basic 2-D image library.
Package files
color.go format.go geom.go image.go names.goVariables
var (
// Black is an opaque black ColorImage.
Black = ColorImage{Gray16Color{0}}
// White is an opaque white ColorImage.
White = ColorImage{Gray16Color{0xffff}}
// Transparent is a fully transparent ColorImage.
Transparent = ColorImage{Alpha16Color{0}}
// Opaque is a fully opaque ColorImage.
Opaque = ColorImage{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))
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. Decode is the function that decodes the encoded image.
type Alpha
An Alpha is an in-memory image of AlphaColor values.
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
}
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)
type Alpha16
An Alpha16 is an in-memory image of Alpha16Color values.
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
}
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)
type Alpha16Color
An 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
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 64-bit alpha-premultiplied RGBA. Each channel value ranges within [0, 0xFFFF].
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) 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
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 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 Gray
A Gray is an in-memory image of GrayColor values.
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
}
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)
type Gray16
A Gray16 is an in-memory image of Gray16Color values.
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
}
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)
type Gray16Color
A 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
A 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
An 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) (m Image, formatName string, err os.Error)
Decode decodes an image that has been encoded in a registered format. Format registration is typically done by the init method of the codec- specific package.
type NRGBA
An NRGBA is an in-memory image of NRGBAColor values.
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
}
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)
type NRGBA64
An NRGBA64 is an in-memory image of NRGBA64Color values.
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
}
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)
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 {
// 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
}
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)
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 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) 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
An RGBA is an in-memory image of RGBAColor values.
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
}
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)
type RGBA64
An RGBA64 is an in-memory image of RGBA64Color values.
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
}
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)
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)
type Rectangle
A Rectangle contains the points with Min.X <= X < Max.X, Min.Y <= Y < Max.Y.
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 Min.X <= Max.X and Min.Y <= Max.Y.
func (Rectangle) Contains
func (r Rectangle) Contains(p Point) bool
Contains returns whether r contains p.
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) Inset
func (r Rectangle) Inset(n int) Rectangle
Inset returns the rectangle r inset by n, which may be negative.
func (Rectangle) Overlaps
func (r Rectangle) Overlaps(s Rectangle) bool
Overlaps returns whether r and s have a non-empty intersection.
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.
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. |
