Imports #
"image/color"
"bufio"
"errors"
"io"
"sync"
"sync/atomic"
"image/color"
"math/bits"
"strconv"
"image/color"
"image/color"
"image/color"
"bufio"
"errors"
"io"
"sync"
"sync/atomic"
"image/color"
"math/bits"
"strconv"
"image/color"
"image/color"
Black is an opaque black uniform image.
var Black = *ast.CallExpr
ErrFormat indicates that decoding encountered an unknown format.
var ErrFormat = *ast.CallExpr
Opaque is a fully opaque uniform image.
var Opaque = *ast.CallExpr
Transparent is a fully transparent uniform image.
var Transparent = *ast.CallExpr
White is an opaque white uniform image.
var White = *ast.CallExpr
const YCbCrSubsampleRatio410
const YCbCrSubsampleRatio411
const YCbCrSubsampleRatio420
const YCbCrSubsampleRatio422
const YCbCrSubsampleRatio440
const YCbCrSubsampleRatio444 YCbCrSubsampleRatio = iota
ZP is the zero [Point]. Deprecated: Use a literal [image.Point] instead.
var ZP Point
ZR is the zero [Rectangle]. Deprecated: Use a literal [image.Rectangle] instead.
var ZR Rectangle
Formats is the list of registered formats.
var atomicFormats atomic.Value
Formats is the list of registered formats.
var formatsMu sync.Mutex
YCbCrSubsampleRatio is the chroma subsample ratio used in a YCbCr image.
type YCbCrSubsampleRatio int
Image is a finite rectangular grid of [color.Color] values taken from a color model.
type Image interface {
ColorModel() color.Model
Bounds() Rectangle
At(x int, y int) color.Color
}
PalettedImage is an image whose colors may come from a limited palette. If m is a PalettedImage and m.ColorModel() returns a [color.Palette] p, then m.At(x, y) should be equivalent to p[m.ColorIndexAt(x, y)]. If m's color model is not a color.Palette, then ColorIndexAt's behavior is undefined.
type PalettedImage interface {
ColorIndexAt(x int, y int) uint8
Image
}
RGBA64Image is an [Image] whose pixels can be converted directly to a color.RGBA64.
type RGBA64Image interface {
RGBA64At(x int, y int) color.RGBA64
Image
}
A reader is an io.Reader that can also peek ahead.
type reader interface {
io.Reader
Peek(int) ([]byte, error)
}
Alpha is an in-memory image whose At method returns [color.Alpha] values.
type Alpha struct {
Pix []uint8
Stride int
Rect Rectangle
}
Alpha16 is an in-memory image whose At method returns [color.Alpha16] values.
type Alpha16 struct {
Pix []uint8
Stride int
Rect Rectangle
}
CMYK is an in-memory image whose At method returns [color.CMYK] values.
type CMYK struct {
Pix []uint8
Stride int
Rect Rectangle
}
Config holds an image's color model and dimensions.
type Config struct {
ColorModel color.Model
Width int
Height int
}
Gray is an in-memory image whose At method returns [color.Gray] values.
type Gray struct {
Pix []uint8
Stride int
Rect Rectangle
}
Gray16 is an in-memory image whose At method returns [color.Gray16] values.
type Gray16 struct {
Pix []uint8
Stride int
Rect Rectangle
}
NRGBA is an in-memory image whose At method returns [color.NRGBA] values.
type NRGBA struct {
Pix []uint8
Stride int
Rect Rectangle
}
NRGBA64 is an in-memory image whose At method returns [color.NRGBA64] values.
type NRGBA64 struct {
Pix []uint8
Stride int
Rect Rectangle
}
NYCbCrA is an in-memory image of non-alpha-premultiplied Y'CbCr-with-alpha colors. A and AStride are analogous to the Y and YStride fields of the embedded YCbCr.
type NYCbCrA struct {
YCbCr
A []uint8
AStride int
}
Paletted is an in-memory image of uint8 indices into a given palette.
type Paletted struct {
Pix []uint8
Stride int
Rect Rectangle
Palette color.Palette
}
A Point is an X, Y coordinate pair. The axes increase right and down.
type Point struct {
X int
Y int
}
RGBA is an in-memory image whose At method returns [color.RGBA] values.
type RGBA struct {
Pix []uint8
Stride int
Rect Rectangle
}
RGBA64 is an in-memory image whose At method returns [color.RGBA64] values.
type RGBA64 struct {
Pix []uint8
Stride int
Rect 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. A Rectangle is also an [Image] whose bounds are the rectangle itself. At returns color.Opaque for points in the rectangle and color.Transparent otherwise.
type Rectangle struct {
Min Point
Max Point
}
Uniform is an infinite-sized [Image] of uniform color. It implements the [color.Color], [color.Model], and [Image] interfaces.
type Uniform struct {
C color.Color
}
YCbCr is an in-memory image of Y'CbCr colors. There is one Y sample per pixel, but each Cb and Cr sample can span one or more pixels. YStride is the Y slice index delta between vertically adjacent pixels. CStride is the Cb and Cr slice index delta between vertically adjacent pixels that map to separate chroma samples. It is not an absolute requirement, but YStride and len(Y) are typically multiples of 8, and: For 4:4:4, CStride == YStride/1 && len(Cb) == len(Cr) == len(Y)/1. For 4:2:2, CStride == YStride/2 && len(Cb) == len(Cr) == len(Y)/2. For 4:2:0, CStride == YStride/2 && len(Cb) == len(Cr) == len(Y)/4. For 4:4:0, CStride == YStride/1 && len(Cb) == len(Cr) == len(Y)/2. For 4:1:1, CStride == YStride/4 && len(Cb) == len(Cr) == len(Y)/4. For 4:1:0, CStride == YStride/4 && len(Cb) == len(Cr) == len(Y)/8.
type YCbCr struct {
Y []uint8
Cb []uint8
Cr []uint8
YStride int
CStride int
SubsampleRatio YCbCrSubsampleRatio
Rect Rectangle
}
A format holds an image format's name, magic header and how to decode it.
type format struct {
name string
magic string
decode func(io.Reader) (Image, error)
decodeConfig func(io.Reader) (Config, error)
}
AOffset returns the index of the first element of A that corresponds to the pixel at (x, y).
func (p *NYCbCrA) AOffset(x int, y int) int
Add returns the vector p+q.
func (p Point) Add(q Point) Point
Add returns the rectangle r translated by p.
func (r Rectangle) Add(p Point) Rectangle
func (p *Alpha16) Alpha16At(x int, y int) color.Alpha16
func (p *Alpha) AlphaAt(x int, y int) color.Alpha
func (p *Paletted) At(x int, y int) color.Color
func (p *NRGBA64) At(x int, y int) color.Color
func (p *RGBA64) At(x int, y int) color.Color
At implements the [Image] interface.
func (r Rectangle) At(x int, y int) color.Color
func (p *Gray16) At(x int, y int) color.Color
func (p *Gray) At(x int, y int) color.Color
func (p *Alpha16) At(x int, y int) color.Color
func (p *NRGBA) At(x int, y int) color.Color
func (p *NYCbCrA) At(x int, y int) color.Color
func (p *RGBA) At(x int, y int) color.Color
func (p *Alpha) At(x int, y int) color.Color
func (p *YCbCr) At(x int, y int) color.Color
func (c *Uniform) At(x int, y int) color.Color
func (p *CMYK) At(x int, y int) color.Color
func (p *Alpha16) Bounds() Rectangle
func (p *CMYK) Bounds() Rectangle
func (p *RGBA) Bounds() Rectangle
func (p *Alpha) Bounds() Rectangle
func (p *Paletted) Bounds() Rectangle
func (p *YCbCr) Bounds() Rectangle
Bounds implements the [Image] interface.
func (r Rectangle) Bounds() Rectangle
func (p *NRGBA64) Bounds() Rectangle
func (p *NRGBA) Bounds() Rectangle
func (p *Gray16) Bounds() Rectangle
func (p *RGBA64) Bounds() Rectangle
func (p *Gray) Bounds() Rectangle
func (c *Uniform) Bounds() Rectangle
func (p *CMYK) CMYKAt(x int, y int) color.CMYK
COffset returns the index of the first element of Cb or Cr that corresponds to the pixel at (x, y).
func (p *YCbCr) COffset(x int, y int) int
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 (r Rectangle) Canon() Rectangle
func (p *Paletted) ColorIndexAt(x int, y int) uint8
func (p *NYCbCrA) ColorModel() color.Model
func (p *Gray) ColorModel() color.Model
func (c *Uniform) ColorModel() color.Model
func (p *RGBA64) ColorModel() color.Model
func (p *NRGBA64) ColorModel() color.Model
ColorModel implements the [Image] interface.
func (r Rectangle) ColorModel() color.Model
func (p *YCbCr) ColorModel() color.Model
func (p *Paletted) ColorModel() color.Model
func (p *Alpha16) ColorModel() color.Model
func (p *NRGBA) ColorModel() color.Model
func (p *Alpha) ColorModel() color.Model
func (p *CMYK) ColorModel() color.Model
func (p *Gray16) ColorModel() color.Model
func (p *RGBA) ColorModel() color.Model
func (c *Uniform) Convert(color.Color) color.Color
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 an init function in the codec- specific package.
func Decode(r io.Reader) (Image, string, 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 an init function in the codec-specific package.
func DecodeConfig(r io.Reader) (Config, string, error)
Div returns the vector p/k.
func (p Point) Div(k int) Point
Dx returns r's width.
func (r Rectangle) Dx() int
Dy returns r's height.
func (r Rectangle) Dy() int
Empty reports whether the rectangle contains no points.
func (r Rectangle) Empty() bool
Eq reports whether p and q are equal.
func (p Point) Eq(q Point) bool
Eq reports whether r and s contain the same set of points. All empty rectangles are considered equal.
func (r Rectangle) Eq(s Rectangle) bool
func (p *Gray16) Gray16At(x int, y int) color.Gray16
func (p *Gray) GrayAt(x int, y int) color.Gray
In reports whether every point in r is in s.
func (r Rectangle) In(s Rectangle) bool
In reports whether p is in r.
func (p Point) In(r Rectangle) bool
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 (r Rectangle) Inset(n int) 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 (r Rectangle) Intersect(s Rectangle) Rectangle
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 (p Point) Mod(r Rectangle) Point
Mul returns the vector p*k.
func (p Point) Mul(k int) Point
func (p *NRGBA64) NRGBA64At(x int, y int) color.NRGBA64
func (p *NRGBA) NRGBAAt(x int, y int) color.NRGBA
func (p *NYCbCrA) NYCbCrAAt(x int, y int) color.NYCbCrA
NewAlpha returns a new [Alpha] image with the given bounds.
func NewAlpha(r Rectangle) *Alpha
NewAlpha16 returns a new [Alpha16] image with the given bounds.
func NewAlpha16(r Rectangle) *Alpha16
NewCMYK returns a new CMYK image with the given bounds.
func NewCMYK(r Rectangle) *CMYK
NewGray returns a new [Gray] image with the given bounds.
func NewGray(r Rectangle) *Gray
NewGray16 returns a new [Gray16] image with the given bounds.
func NewGray16(r Rectangle) *Gray16
NewNRGBA returns a new [NRGBA] image with the given bounds.
func NewNRGBA(r Rectangle) *NRGBA
NewNRGBA64 returns a new [NRGBA64] image with the given bounds.
func NewNRGBA64(r Rectangle) *NRGBA64
NewNYCbCrA returns a new [NYCbCrA] image with the given bounds and subsample ratio.
func NewNYCbCrA(r Rectangle, subsampleRatio YCbCrSubsampleRatio) *NYCbCrA
NewPaletted returns a new [Paletted] image with the given width, height and palette.
func NewPaletted(r Rectangle, p color.Palette) *Paletted
NewRGBA returns a new [RGBA] image with the given bounds.
func NewRGBA(r Rectangle) *RGBA
NewRGBA64 returns a new [RGBA64] image with the given bounds.
func NewRGBA64(r Rectangle) *RGBA64
NewUniform returns a new [Uniform] image of the given color.
func NewUniform(c color.Color) *Uniform
NewYCbCr returns a new YCbCr image with the given bounds and subsample ratio.
func NewYCbCr(r Rectangle, subsampleRatio YCbCrSubsampleRatio) *YCbCr
Opaque scans the entire image and reports whether it is fully opaque.
func (p *NYCbCrA) Opaque() bool
func (p *YCbCr) Opaque() bool
Opaque scans the entire image and reports whether it is fully opaque.
func (p *RGBA64) Opaque() bool
Opaque scans the entire image and reports whether it is fully opaque.
func (c *Uniform) Opaque() bool
Opaque scans the entire image and reports whether it is fully opaque.
func (p *NRGBA64) Opaque() bool
Opaque scans the entire image and reports whether it is fully opaque.
func (p *Gray) Opaque() bool
Opaque scans the entire image and reports whether it is fully opaque.
func (p *NRGBA) Opaque() bool
Opaque scans the entire image and reports whether it is fully opaque.
func (p *Paletted) Opaque() bool
Opaque scans the entire image and reports whether it is fully opaque.
func (p *Alpha) Opaque() bool
Opaque scans the entire image and reports whether it is fully opaque.
func (p *RGBA) Opaque() bool
Opaque scans the entire image and reports whether it is fully opaque.
func (p *CMYK) Opaque() bool
Opaque scans the entire image and reports whether it is fully opaque.
func (p *Gray16) Opaque() bool
Opaque scans the entire image and reports whether it is fully opaque.
func (p *Alpha16) Opaque() bool
Overlaps reports whether r and s have a non-empty intersection.
func (r Rectangle) Overlaps(s Rectangle) bool
PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).
func (p *Gray) PixOffset(x int, y int) int
PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).
func (p *Gray16) PixOffset(x int, y int) int
PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).
func (p *Alpha16) PixOffset(x int, y int) int
PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).
func (p *CMYK) PixOffset(x int, y int) int
PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).
func (p *NRGBA64) PixOffset(x int, y int) int
PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).
func (p *Paletted) PixOffset(x int, y int) int
PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).
func (p *Alpha) PixOffset(x int, y int) int
PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).
func (p *RGBA64) PixOffset(x int, y int) int
PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).
func (p *RGBA) PixOffset(x int, y int) int
PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).
func (p *NRGBA) PixOffset(x int, y int) int
Pt is shorthand for [Point]{X, Y}.
func Pt(X int, Y int) Point
func (c *Uniform) RGBA() (r uint32, g uint32, b uint32, a uint32)
func (p *YCbCr) RGBA64At(x int, y int) color.RGBA64
func (p *CMYK) RGBA64At(x int, y int) color.RGBA64
func (p *Gray16) RGBA64At(x int, y int) color.RGBA64
func (p *NRGBA64) RGBA64At(x int, y int) color.RGBA64
func (p *RGBA64) RGBA64At(x int, y int) color.RGBA64
func (p *RGBA) RGBA64At(x int, y int) color.RGBA64
func (p *Alpha) RGBA64At(x int, y int) color.RGBA64
func (p *NYCbCrA) RGBA64At(x int, y int) color.RGBA64
func (p *NRGBA) RGBA64At(x int, y int) color.RGBA64
func (p *Alpha16) RGBA64At(x int, y int) color.RGBA64
func (p *Gray) RGBA64At(x int, y int) color.RGBA64
func (p *Paletted) RGBA64At(x int, y int) color.RGBA64
func (c *Uniform) RGBA64At(x int, y int) color.RGBA64
RGBA64At implements the [RGBA64Image] interface.
func (r Rectangle) RGBA64At(x int, y int) color.RGBA64
func (p *RGBA) RGBAAt(x int, y int) color.RGBA
Rect is shorthand for [Rectangle]{Pt(x0, y0), [Pt](x1, y1)}. The returned rectangle has minimum and maximum coordinates swapped if necessary so that it is well-formed.
func Rect(x0 int, y0 int, x1 int, y1 int) Rectangle
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.
func RegisterFormat(name string, magic string, decode func(io.Reader) (Image, error), decodeConfig func(io.Reader) (Config, error))
func (p *RGBA64) Set(x int, y int, c color.Color)
func (p *RGBA) Set(x int, y int, c color.Color)
func (p *Alpha) Set(x int, y int, c color.Color)
func (p *Gray) Set(x int, y int, c color.Color)
func (p *Alpha16) Set(x int, y int, c color.Color)
func (p *NRGBA) Set(x int, y int, c color.Color)
func (p *Paletted) Set(x int, y int, c color.Color)
func (p *NRGBA64) Set(x int, y int, c color.Color)
func (p *Gray16) Set(x int, y int, c color.Color)
func (p *CMYK) Set(x int, y int, c color.Color)
func (p *Alpha) SetAlpha(x int, y int, c color.Alpha)
func (p *Alpha16) SetAlpha16(x int, y int, c color.Alpha16)
func (p *CMYK) SetCMYK(x int, y int, c color.CMYK)
func (p *Paletted) SetColorIndex(x int, y int, index uint8)
func (p *Gray) SetGray(x int, y int, c color.Gray)
func (p *Gray16) SetGray16(x int, y int, c color.Gray16)
func (p *NRGBA) SetNRGBA(x int, y int, c color.NRGBA)
func (p *NRGBA64) SetNRGBA64(x int, y int, c color.NRGBA64)
func (p *RGBA) SetRGBA(x int, y int, c color.RGBA)
func (p *NRGBA64) SetRGBA64(x int, y int, c color.RGBA64)
func (p *CMYK) SetRGBA64(x int, y int, c color.RGBA64)
func (p *Alpha16) SetRGBA64(x int, y int, c color.RGBA64)
func (p *NRGBA) SetRGBA64(x int, y int, c color.RGBA64)
func (p *RGBA64) SetRGBA64(x int, y int, c color.RGBA64)
func (p *Alpha) SetRGBA64(x int, y int, c color.RGBA64)
func (p *Paletted) SetRGBA64(x int, y int, c color.RGBA64)
func (p *RGBA) SetRGBA64(x int, y int, c color.RGBA64)
func (p *Gray) SetRGBA64(x int, y int, c color.RGBA64)
func (p *Gray16) SetRGBA64(x int, y int, c color.RGBA64)
Size returns r's width and height.
func (r Rectangle) Size() Point
func (s YCbCrSubsampleRatio) String() string
String returns a string representation of p like "(3,4)".
func (p Point) String() string
String returns a string representation of r like "(3,4)-(6,5)".
func (r Rectangle) String() string
Sub returns the rectangle r translated by -p.
func (r Rectangle) Sub(p Point) Rectangle
Sub returns the vector p-q.
func (p Point) Sub(q Point) Point
SubImage returns an image representing the portion of the image p visible through r. The returned value shares pixels with the original image.
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.
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.
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.
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.
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.
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.
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.
func (p *YCbCr) 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.
func (p *CMYK) 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.
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.
func (p *NYCbCrA) 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.
func (p *NRGBA64) SubImage(r Rectangle) Image
Union returns the smallest rectangle that contains both r and s.
func (r Rectangle) Union(s Rectangle) Rectangle
func (p *YCbCr) YCbCrAt(x int, y int) color.YCbCr
YOffset returns the index of the first element of Y that corresponds to the pixel at (x, y).
func (p *YCbCr) YOffset(x int, y int) int
add2NonNeg returns (x + y), unless at least one argument is negative or if the computation overflows the int type, in which case it returns -1.
func add2NonNeg(x int, y int) int
asReader converts an io.Reader to a reader.
func asReader(r io.Reader) reader
match reports whether magic matches b. Magic may contain "?" wildcards.
func match(magic string, b []byte) bool
mul3NonNeg returns (x * y * z), unless at least one argument is negative or if the computation overflows the int type, in which case it returns -1.
func mul3NonNeg(x int, y int, z int) int
pixelBufferLength returns the length of the []uint8 typed Pix slice field for the NewXxx functions. Conceptually, this is just (bpp * width * height), but this function panics if at least one of those is negative or if the computation would overflow the int type. This panics instead of returning an error because of backwards compatibility. The NewXxx functions do not return an error.
func pixelBufferLength(bytesPerPixel int, r Rectangle, imageTypeName string) int
sniff determines the format of r's data.
func sniff(r reader) format
func yCbCrSize(r Rectangle, subsampleRatio YCbCrSubsampleRatio) (w int, h int, cw int, ch int)
Generated with Arrow