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.CallExprErrFormat indicates that decoding encountered an unknown format.
var ErrFormat = *ast.CallExprOpaque is a fully opaque uniform image.
var Opaque = *ast.CallExprTransparent is a fully transparent uniform image.
var Transparent = *ast.CallExprWhite is an opaque white uniform image.
var White = *ast.CallExprconst YCbCrSubsampleRatio410const YCbCrSubsampleRatio411const YCbCrSubsampleRatio420const YCbCrSubsampleRatio422const YCbCrSubsampleRatio440const YCbCrSubsampleRatio444 YCbCrSubsampleRatio = iotaZP is the zero [Point]. Deprecated: Use a literal [image.Point] instead.
var ZP PointZR is the zero [Rectangle]. Deprecated: Use a literal [image.Rectangle] instead.
var ZR RectangleFormats is the list of registered formats.
var atomicFormats atomic.ValueFormats is the list of registered formats.
var formatsMu sync.MutexYCbCrSubsampleRatio is the chroma subsample ratio used in a YCbCr image.
type YCbCrSubsampleRatio intImage 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) intAdd returns the vector p+q.
func (p Point) Add(q Point) PointAdd returns the rectangle r translated by p.
func (r Rectangle) Add(p Point) Rectanglefunc (p *Alpha16) Alpha16At(x int, y int) color.Alpha16func (p *Alpha) AlphaAt(x int, y int) color.Alphafunc (p *Paletted) At(x int, y int) color.Colorfunc (p *NRGBA64) At(x int, y int) color.Colorfunc (p *RGBA64) At(x int, y int) color.ColorAt implements the [Image] interface.
func (r Rectangle) At(x int, y int) color.Colorfunc (p *Gray16) At(x int, y int) color.Colorfunc (p *Gray) At(x int, y int) color.Colorfunc (p *Alpha16) At(x int, y int) color.Colorfunc (p *NRGBA) At(x int, y int) color.Colorfunc (p *NYCbCrA) At(x int, y int) color.Colorfunc (p *RGBA) At(x int, y int) color.Colorfunc (p *Alpha) At(x int, y int) color.Colorfunc (p *YCbCr) At(x int, y int) color.Colorfunc (c *Uniform) At(x int, y int) color.Colorfunc (p *CMYK) At(x int, y int) color.Colorfunc (p *Alpha16) Bounds() Rectanglefunc (p *CMYK) Bounds() Rectanglefunc (p *RGBA) Bounds() Rectanglefunc (p *Alpha) Bounds() Rectanglefunc (p *Paletted) Bounds() Rectanglefunc (p *YCbCr) Bounds() RectangleBounds implements the [Image] interface.
func (r Rectangle) Bounds() Rectanglefunc (p *NRGBA64) Bounds() Rectanglefunc (p *NRGBA) Bounds() Rectanglefunc (p *Gray16) Bounds() Rectanglefunc (p *RGBA64) Bounds() Rectanglefunc (p *Gray) Bounds() Rectanglefunc (c *Uniform) Bounds() Rectanglefunc (p *CMYK) CMYKAt(x int, y int) color.CMYKCOffset 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) intCanon 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() Rectanglefunc (p *Paletted) ColorIndexAt(x int, y int) uint8func (p *NYCbCrA) ColorModel() color.Modelfunc (p *Gray) ColorModel() color.Modelfunc (c *Uniform) ColorModel() color.Modelfunc (p *RGBA64) ColorModel() color.Modelfunc (p *NRGBA64) ColorModel() color.ModelColorModel implements the [Image] interface.
func (r Rectangle) ColorModel() color.Modelfunc (p *YCbCr) ColorModel() color.Modelfunc (p *Paletted) ColorModel() color.Modelfunc (p *Alpha16) ColorModel() color.Modelfunc (p *NRGBA) ColorModel() color.Modelfunc (p *Alpha) ColorModel() color.Modelfunc (p *CMYK) ColorModel() color.Modelfunc (p *Gray16) ColorModel() color.Modelfunc (p *RGBA) ColorModel() color.Modelfunc (c *Uniform) Convert(color.Color) color.ColorDecode 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) PointDx returns r's width.
func (r Rectangle) Dx() intDy returns r's height.
func (r Rectangle) Dy() intEmpty reports whether the rectangle contains no points.
func (r Rectangle) Empty() boolEq reports whether p and q are equal.
func (p Point) Eq(q Point) boolEq reports whether r and s contain the same set of points. All empty rectangles are considered equal.
func (r Rectangle) Eq(s Rectangle) boolfunc (p *Gray16) Gray16At(x int, y int) color.Gray16func (p *Gray) GrayAt(x int, y int) color.GrayIn reports whether every point in r is in s.
func (r Rectangle) In(s Rectangle) boolIn reports whether p is in r.
func (p Point) In(r Rectangle) boolInset 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) RectangleIntersect 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) RectangleMod 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) PointMul returns the vector p*k.
func (p Point) Mul(k int) Pointfunc (p *NRGBA64) NRGBA64At(x int, y int) color.NRGBA64func (p *NRGBA) NRGBAAt(x int, y int) color.NRGBAfunc (p *NYCbCrA) NYCbCrAAt(x int, y int) color.NYCbCrANewAlpha returns a new [Alpha] image with the given bounds.
func NewAlpha(r Rectangle) *AlphaNewAlpha16 returns a new [Alpha16] image with the given bounds.
func NewAlpha16(r Rectangle) *Alpha16NewCMYK returns a new CMYK image with the given bounds.
func NewCMYK(r Rectangle) *CMYKNewGray returns a new [Gray] image with the given bounds.
func NewGray(r Rectangle) *GrayNewGray16 returns a new [Gray16] image with the given bounds.
func NewGray16(r Rectangle) *Gray16NewNRGBA returns a new [NRGBA] image with the given bounds.
func NewNRGBA(r Rectangle) *NRGBANewNRGBA64 returns a new [NRGBA64] image with the given bounds.
func NewNRGBA64(r Rectangle) *NRGBA64NewNYCbCrA returns a new [NYCbCrA] image with the given bounds and subsample ratio.
func NewNYCbCrA(r Rectangle, subsampleRatio YCbCrSubsampleRatio) *NYCbCrANewPaletted returns a new [Paletted] image with the given width, height and palette.
func NewPaletted(r Rectangle, p color.Palette) *PalettedNewRGBA returns a new [RGBA] image with the given bounds.
func NewRGBA(r Rectangle) *RGBANewRGBA64 returns a new [RGBA64] image with the given bounds.
func NewRGBA64(r Rectangle) *RGBA64NewUniform returns a new [Uniform] image of the given color.
func NewUniform(c color.Color) *UniformNewYCbCr returns a new YCbCr image with the given bounds and subsample ratio.
func NewYCbCr(r Rectangle, subsampleRatio YCbCrSubsampleRatio) *YCbCrOpaque scans the entire image and reports whether it is fully opaque.
func (p *NYCbCrA) Opaque() boolfunc (p *YCbCr) Opaque() boolOpaque scans the entire image and reports whether it is fully opaque.
func (p *RGBA64) Opaque() boolOpaque scans the entire image and reports whether it is fully opaque.
func (c *Uniform) Opaque() boolOpaque scans the entire image and reports whether it is fully opaque.
func (p *NRGBA64) Opaque() boolOpaque scans the entire image and reports whether it is fully opaque.
func (p *Gray) Opaque() boolOpaque scans the entire image and reports whether it is fully opaque.
func (p *NRGBA) Opaque() boolOpaque scans the entire image and reports whether it is fully opaque.
func (p *Paletted) Opaque() boolOpaque scans the entire image and reports whether it is fully opaque.
func (p *Alpha) Opaque() boolOpaque scans the entire image and reports whether it is fully opaque.
func (p *RGBA) Opaque() boolOpaque scans the entire image and reports whether it is fully opaque.
func (p *CMYK) Opaque() boolOpaque scans the entire image and reports whether it is fully opaque.
func (p *Gray16) Opaque() boolOpaque scans the entire image and reports whether it is fully opaque.
func (p *Alpha16) Opaque() boolOverlaps reports whether r and s have a non-empty intersection.
func (r Rectangle) Overlaps(s Rectangle) boolPixOffset 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) intPixOffset 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) intPixOffset 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) intPixOffset 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) intPixOffset 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) intPixOffset 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) intPixOffset 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) intPixOffset 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) intPixOffset 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) intPixOffset 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) intPt is shorthand for [Point]{X, Y}.
func Pt(X int, Y int) Pointfunc (c *Uniform) RGBA() (r uint32, g uint32, b uint32, a uint32)func (p *YCbCr) RGBA64At(x int, y int) color.RGBA64func (p *CMYK) RGBA64At(x int, y int) color.RGBA64func (p *Gray16) RGBA64At(x int, y int) color.RGBA64func (p *NRGBA64) RGBA64At(x int, y int) color.RGBA64func (p *RGBA64) RGBA64At(x int, y int) color.RGBA64func (p *RGBA) RGBA64At(x int, y int) color.RGBA64func (p *Alpha) RGBA64At(x int, y int) color.RGBA64func (p *NYCbCrA) RGBA64At(x int, y int) color.RGBA64func (p *NRGBA) RGBA64At(x int, y int) color.RGBA64func (p *Alpha16) RGBA64At(x int, y int) color.RGBA64func (p *Gray) RGBA64At(x int, y int) color.RGBA64func (p *Paletted) RGBA64At(x int, y int) color.RGBA64func (c *Uniform) RGBA64At(x int, y int) color.RGBA64RGBA64At implements the [RGBA64Image] interface.
func (r Rectangle) RGBA64At(x int, y int) color.RGBA64func (p *RGBA) RGBAAt(x int, y int) color.RGBARect 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) RectangleRegisterFormat 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() Pointfunc (s YCbCrSubsampleRatio) String() stringString returns a string representation of p like "(3,4)".
func (p Point) String() stringString returns a string representation of r like "(3,4)-(6,5)".
func (r Rectangle) String() stringSub returns the rectangle r translated by -p.
func (r Rectangle) Sub(p Point) RectangleSub returns the vector p-q.
func (p Point) Sub(q Point) PointSubImage 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) ImageSubImage 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) ImageSubImage 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) ImageSubImage 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) ImageSubImage 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) ImageSubImage 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) ImageSubImage 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) ImageSubImage 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) ImageSubImage 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) ImageSubImage 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) ImageSubImage 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) ImageSubImage 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) ImageUnion returns the smallest rectangle that contains both r and s.
func (r Rectangle) Union(s Rectangle) Rectanglefunc (p *YCbCr) YCbCrAt(x int, y int) color.YCbCrYOffset 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) intadd2NonNeg 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) intasReader converts an io.Reader to a reader.
func asReader(r io.Reader) readermatch reports whether magic matches b. Magic may contain "?" wildcards.
func match(magic string, b []byte) boolmul3NonNeg 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) intpixelBufferLength 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) intsniff determines the format of r's data.
func sniff(r reader) formatfunc yCbCrSize(r Rectangle, subsampleRatio YCbCrSubsampleRatio) (w int, h int, cw int, ch int)Generated with Arrow