Overview

Package image implements a basic 2-D image library.

The fundamental interface is called Image. An Image contains colors, which are
described in the image/color package.

Values of the Image interface are created either by calling functions such as
NewRGBA and NewPaletted, or by calling Decode on an io.Reader containing image
data in a format such as GIF, JPEG or PNG. Decoding any particular image format
requires the prior registration of a decoder function. Registration is typically
automatic as a side effect of initializing that format’s package so that, to
decode a PNG image, it suffices to have

in a program’s main package. The _ means to import a package purely for its
initialization side effects.

See “The Go image package” for more details:


Example:

  1. // This example demonstrates decoding a JPEG image and examining its pixels.
  2. package image_test
  3. import (
  4. "encoding/base64"
  5. "fmt"
  6. "image"
  7. "log"
  8. "strings"
  9. // Package image/jpeg is not used explicitly in the code below,
  10. // but is imported for its initialization side-effect, which allows
  11. // image.Decode to understand JPEG formatted images. Uncomment these
  12. // two lines to also understand GIF and PNG images:
  13. // _ "image/gif"
  14. // _ "image/png"
  15. _ "image/jpeg"
  16. )
  17. func Example() {
  18. // Decode the JPEG data. If reading from file, create a reader with
  19. //
  20. // reader, err := os.Open("testdata/video-001.q50.420.jpeg")
  21. // if err != nil {
  22. // log.Fatal(err)
  23. // }
  24. // defer reader.Close()
  25. reader := base64.NewDecoder(base64.StdEncoding, strings.NewReader(data))
  26. m, _, err := image.Decode(reader)
  27. if err != nil {
  28. log.Fatal(err)
  29. }
  30. bounds := m.Bounds()
  31. // Calculate a 16-bin histogram for m's red, green, blue and alpha components.
  32. //
  33. // An image's bounds do not necessarily start at (0, 0), so the two loops start
  34. // at bounds.Min.Y and bounds.Min.X. Looping over Y first and X second is more
  35. // likely to result in better memory access patterns than X first and Y second.
  36. var histogram [16][4]int
  37. for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
  38. for x := bounds.Min.X; x < bounds.Max.X; x++ {
  39. r, g, b, a := m.At(x, y).RGBA()
  40. // A color's RGBA method returns values in the range [0, 65535].
  41. // Shifting by 12 reduces this to the range [0, 15].
  42. histogram[r>>12][0]++
  43. histogram[b>>12][2]++
  44. histogram[a>>12][3]++
  45. }
  46. }
  47. // Print the results.
  48. fmt.Printf("%-14s %6s %6s %6s %6s\n", "bin", "red", "green", "blue", "alpha")
  49. for i, x := range histogram {
  50. fmt.Printf("0x%04x-0x%04x: %6d %6d %6d %6d\n", i<<12, (i+1)<<12-1, x[0], x[1], x[2], x[3])
  51. }
  52. // Output:
  53. // bin red green blue alpha
  54. // 0x0000-0x0fff: 364 790 7242 0
  55. // 0x1000-0x1fff: 645 2967 1039 0
  56. // 0x2000-0x2fff: 1072 2299 979 0
  57. // 0x3000-0x3fff: 820 2266 980 0
  58. // 0x4000-0x4fff: 537 1305 541 0
  59. // 0x5000-0x5fff: 319 962 261 0
  60. // 0x6000-0x6fff: 322 375 177 0
  61. // 0x7000-0x7fff: 601 279 214 0
  62. // 0x8000-0x8fff: 3478 227 273 0
  63. // 0x9000-0x9fff: 2260 234 329 0
  64. // 0xa000-0xafff: 921 282 373 0
  65. // 0xb000-0xbfff: 321 335 397 0
  66. // 0xc000-0xcfff: 229 388 298 0
  67. // 0xd000-0xdfff: 260 414 277 0
  68. // 0xe000-0xefff: 516 428 298 0
  69. // 0xf000-0xffff: 2785 1899 1772 15450
  70. }
  71. const data = `
  72. /9j/4AAQSkZJRgABAQIAHAAcAAD/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdA
  73. SFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2Nj
  74. Y2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wAARCABnAJYDASIAAhEBAxEB/8QA
  75. HwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIh
  76. MUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVW
  77. V1hZWmNkZWZnaGlqc3R1dnd4e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x9KKveJblXuordSGES5b6n/62PzorKVdp2LjQTVyWz8UWEWlq
  116. jSgyxfJt6EgdDzWTdeLIZGO7zHI/hVajGmWWP+PWL8qwlAIURrhpMAHHJA71pRcZrToZzcoEuo6heakA
  117. GHk245CZ6/X1qPTLq40q+W5t2QybSpDAkEEc55/zilk5k2r91eKhLDzWz2rpsczbbuemeD76fUNG865I
  118. MiysmQMZAAwa3a5j4ftu0ByP+fh/5CulkLLG7INzhSVHqe1Fh3uOoqn9qQQxyhndmHIxwOmSR2xQ13KD
  119. KoiBZOV9JBnt707MVy5RWdNdy7wRGf3bfMinnO1jg+vY03WXLaJO3mhQ20b0zwpYf0qlG7S7icrJs08U
  120. VwumgC+YiQyeVtZH567hzj8aSL949oGhE/2v5pJCDkksQwBHC4/+vXQ8LZ2uYxxCavY7us/xCcaBfn0h
  121. b+VP0bnSrb94ZMJgOecj1rl/GfidUE2k2gy5+SeQjgA/wj3rlas2jdao48qrjLAGkSKPk4Gc1WMj92I+
  122. lIJnU8OfxPWo5inBokmtQTmM4OOh71b0q6vbFmWCbaxHyqQGAP0PT8KhSTzVyo5ocSKA5VfTOTmqsmRd
  123. pl99XjPzThzK3zOeOSeveirNmkgg/fIpYsTkYORxRXmzlTjJqx6EVUcU7mhkKCzdAK59QI9zYxtG1fYU
  124. UVtgtmY4nZEa8Ak9aqFv3rfSiiu1nMeifDv/AJF+T/r4f+QrqqKKQwzQenNFFMCOKFIgNuThdoJ5OPSk
  125. ubeK6t3gnXdG4wwziiii/UTKMOg6dbzJLFE4dSCP3rEdeOM8805tDsGMvySgSsS6rM6gk9eAcUUVftZt
  126. 3uyVGNthuq3Eei6DK8H7sRR7YuMgHtXkc8rzTNLM26RyWY+p70UVnLY0iEsUipG7rhZBlDkc1HgYoorM
  127. 0HwyBXGeRjmrcUhMg2ghezd//rUUVcTKW5s2jZtY/QDaOKKKK8ip8bPRj8KP/9k=
  128. `

Index

Package files

geom.go names.go

Variables

  1. var (
  2. // Black is an opaque black uniform image.
  3. Black = NewUniform(.Black)
  4. // White is an opaque white uniform image.
  5. White = (color.)
  6. // Transparent is a fully transparent uniform image.
  7. Transparent = NewUniform(.Transparent)
  8. // Opaque is a fully opaque uniform image.
  9. Opaque = (color.)
  10. )
  1. var ErrFormat = errors.("image: unknown format")

ErrFormat indicates that decoding encountered an unknown format.

func RegisterFormat

  1. func RegisterFormat(name, magic string, decode func(.Reader) (, error), decodeConfig func(.Reader) (, 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

  1. type Alpha struct {
  2. // Pix holds the image's pixels, as alpha values. The pixel at
  3. // (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*1].
  4. Pix []
  5. // Stride is the Pix stride (in bytes) between vertically adjacent pixels.
  6. Stride int
  7. // Rect is the image's bounds.
  8. Rect
  9. }

Alpha is an in-memory image whose At method returns color.Alpha values.

func NewAlpha

  1. func NewAlpha(r Rectangle) *

NewAlpha returns a new Alpha image with the given bounds.

func (*Alpha) AlphaAt

  1. func (p *Alpha) AlphaAt(x, y ) color.

func (*Alpha) At

  1. func (p *Alpha) At(x, y ) color.

func (*Alpha) Bounds

  1. func (p *Alpha) Bounds()

func (*Alpha) ColorModel

  1. func (p *Alpha) ColorModel() .Model

func (*Alpha)

  1. func (p *) Opaque() bool

Opaque scans the entire image and reports whether it is fully opaque.

func (*Alpha)

  1. func (p *) PixOffset(x, y int)

PixOffset returns the index of the first element of Pix that corresponds to the
pixel at (x, y).

func (*Alpha) Set

  1. func (p *Alpha) Set(x, y , c color.)

func (*Alpha) SetAlpha

  1. func (p *Alpha) SetAlpha(x, y , c color.)

func (*Alpha) SubImage

  1. func (p *Alpha) SubImage(r ) 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

  1. type Alpha16 struct {
  2. // Pix holds the image's pixels, as alpha values in big-endian format. The pixel at
  3. // (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*2].
  4. Pix []
  5. // Stride is the Pix stride (in bytes) between vertically adjacent pixels.
  6. Stride int
  7. // Rect is the image's bounds.
  8. Rect
  9. }

Alpha16 is an in-memory image whose At method returns color.Alpha16 values.

func NewAlpha16

  1. func NewAlpha16(r Rectangle) *

NewAlpha16 returns a new Alpha16 image with the given bounds.

func (*Alpha16) Alpha16At

  1. func (p *Alpha16) Alpha16At(x, y ) color.

func (*Alpha16) At

  1. func (p *Alpha16) At(x, y ) color.

func (*Alpha16) Bounds

  1. func (p *Alpha16) Bounds()

func (*Alpha16) ColorModel

  1. func (p *Alpha16) ColorModel() .Model

func (*Alpha16)

  1. func (p *) Opaque() bool

Opaque scans the entire image and reports whether it is fully opaque.

func (*Alpha16)

  1. func (p *) PixOffset(x, y int)

PixOffset returns the index of the first element of Pix that corresponds to the
pixel at (x, y).

func (*Alpha16) Set

  1. func (p *Alpha16) Set(x, y , c color.)

func (*Alpha16) SetAlpha16

  1. func (p *Alpha16) SetAlpha16(x, y , c color.)

func (*Alpha16) SubImage

  1. func (p *Alpha16) SubImage(r ) 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

  1. type CMYK struct {
  2. // Pix holds the image's pixels, in C, M, Y, K order. The pixel at
  3. // (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*4].
  4. Pix []
  5. // Stride is the Pix stride (in bytes) between vertically adjacent pixels.
  6. Stride int
  7. // Rect is the image's bounds.
  8. Rect
  9. }

CMYK is an in-memory image whose At method returns color.CMYK values.

func NewCMYK

  1. func NewCMYK(r Rectangle) *

NewCMYK returns a new CMYK image with the given bounds.

func (*CMYK) At

  1. func (p *CMYK) At(x, y ) color.

func (*CMYK) Bounds

  1. func (p *CMYK) Bounds()

func (*CMYK) CMYKAt

  1. func (p *CMYK) CMYKAt(x, y ) color.

func (*CMYK) ColorModel

  1. func (p *CMYK) ColorModel() .Model

func (*CMYK)

  1. func (p *) Opaque() bool

Opaque scans the entire image and reports whether it is fully opaque.

func (*CMYK)

  1. func (p *) PixOffset(x, y int)

PixOffset returns the index of the first element of Pix that corresponds to the
pixel at (x, y).

func (*CMYK) Set

  1. func (p *CMYK) Set(x, y , c color.)

func (*CMYK) SetCMYK

  1. func (p *CMYK) SetCMYK(x, y , c color.)

func (*CMYK) SubImage

  1. func (p *CMYK) SubImage(r ) Image

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

  1. type Config struct {
  2. ColorModel .Model
  3. Width, Height
  4. }

Config holds an image’s color model and dimensions.

func DecodeConfig

  1. func DecodeConfig(r io.) (Config, , 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.

type

  1. type Gray struct {
  2. // Pix holds the image's pixels, as gray values. The pixel at
  3. // (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*1].
  4. Pix []
  5. // Stride is the Pix stride (in bytes) between vertically adjacent pixels.
  6. Stride int
  7. // Rect is the image's bounds.
  8. Rect
  9. }

Gray is an in-memory image whose At method returns color.Gray values.

func NewGray

  1. func NewGray(r Rectangle) *

NewGray returns a new Gray image with the given bounds.

func (*Gray) At

  1. func (p *Gray) At(x, y ) color.

func (*Gray) Bounds

  1. func (p *Gray) Bounds()

func (*Gray) ColorModel

  1. func (p *Gray) ColorModel() .Model

func (*Gray)

  1. func (p *) GrayAt(x, y int) .Gray

func (*Gray)

  1. func (p *) Opaque() bool

Opaque scans the entire image and reports whether it is fully opaque.

func (*Gray)

  1. func (p *) PixOffset(x, y int)

PixOffset returns the index of the first element of Pix that corresponds to the
pixel at (x, y).

func (*Gray) Set

  1. func (p *Gray) Set(x, y , c color.)

func (*Gray) SetGray

  1. func (p *Gray) SetGray(x, y , c color.)

func (*Gray) SubImage

  1. func (p *Gray) SubImage(r ) 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

  1. type Gray16 struct {
  2. // Pix holds the image's pixels, as gray values in big-endian format. The pixel at
  3. // (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*2].
  4. Pix []
  5. // Stride is the Pix stride (in bytes) between vertically adjacent pixels.
  6. Stride int
  7. // Rect is the image's bounds.
  8. Rect
  9. }

Gray16 is an in-memory image whose At method returns color.Gray16 values.

func NewGray16

  1. func NewGray16(r Rectangle) *

NewGray16 returns a new Gray16 image with the given bounds.

func (*Gray16) At

  1. func (p *Gray16) At(x, y ) color.

func (*Gray16) Bounds

  1. func (p *Gray16) Bounds()

func (*Gray16) ColorModel

    func (*Gray16) Gray16At

    1. func (p *Gray16) Gray16At(x, y ) color.

    func (*Gray16) Opaque

    1. func (p *Gray16) Opaque()

    Opaque scans the entire image and reports whether it is fully opaque.

    func (*Gray16) PixOffset

    1. func (p *Gray16) PixOffset(x, y ) int

    PixOffset returns the index of the first element of Pix that corresponds to the
    pixel at (x, y).

    func (*Gray16)

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

    func (*Gray16)

    1. func (p *) SubImage(r Rectangle)

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

    type Image

    1. type Image interface {
    2. // ColorModel returns the Image's color model.
    3. ColorModel() color.
    4. // Bounds returns the domain for which At can return non-zero color.
    5. // The bounds do not necessarily contain the point (0, 0).
    6. Bounds() Rectangle
    7. // At returns the color of the pixel at (x, y).
    8. // At(Bounds().Min.X, Bounds().Min.Y) returns the upper-left pixel of the grid.
    9. // At(Bounds().Max.X-1, Bounds().Max.Y-1) returns the lower-right one.
    10. At(x, y ) color.
    11. }

    Image is a finite rectangular grid of color.Color values taken from a color
    model.

    func Decode

    1. func Decode(r io.) (Image, , 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 an init function in the codec- specific package.

    type

    1. type NRGBA struct {
    2. // Pix holds the image's pixels, in R, G, B, A order. The pixel at
    3. // (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*4].
    4. Pix []
    5. // Stride is the Pix stride (in bytes) between vertically adjacent pixels.
    6. Stride int
    7. // Rect is the image's bounds.
    8. Rect
    9. }

    NRGBA is an in-memory image whose At method returns color.NRGBA values.

    func NewNRGBA

    1. func NewNRGBA(r Rectangle) *

    NewNRGBA returns a new NRGBA image with the given bounds.

    func (*NRGBA) At

    1. func (p *NRGBA) At(x, y ) color.

    func (*NRGBA) Bounds

    1. func (p *NRGBA) Bounds()

    func (*NRGBA) ColorModel

    1. func (p *NRGBA) ColorModel() .Model

    func (*NRGBA)

    1. func (p *) NRGBAAt(x, y int) .NRGBA

    func (*NRGBA)

    1. func (p *) Opaque() bool

    Opaque scans the entire image and reports whether it is fully opaque.

    func (*NRGBA)

    1. func (p *) PixOffset(x, y int)

    PixOffset returns the index of the first element of Pix that corresponds to the
    pixel at (x, y).

    func (*NRGBA) Set

    1. func (p *NRGBA) Set(x, y , c color.)

    func (*NRGBA) SetNRGBA

    1. func (p *NRGBA) SetNRGBA(x, y , c color.)

    func (*NRGBA) SubImage

    1. func (p *NRGBA) SubImage(r ) 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

    1. type NRGBA64 struct {
    2. // Pix holds the image's pixels, in R, G, B, A order and big-endian format. The pixel at
    3. // (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*8].
    4. Pix []
    5. // Stride is the Pix stride (in bytes) between vertically adjacent pixels.
    6. Stride int
    7. // Rect is the image's bounds.
    8. Rect
    9. }

    NRGBA64 is an in-memory image whose At method returns color.NRGBA64 values.

    func NewNRGBA64

    1. func NewNRGBA64(r Rectangle) *

    NewNRGBA64 returns a new NRGBA64 image with the given bounds.

    func (*NRGBA64) At

    1. func (p *NRGBA64) At(x, y ) color.

    func (*NRGBA64) Bounds

    1. func (p *NRGBA64) Bounds()

    func (*NRGBA64) ColorModel

    1. func (p *NRGBA64) ColorModel() .Model

    func (*NRGBA64)

    1. func (p *) NRGBA64At(x, y int) .NRGBA64

    func (*NRGBA64)

    1. func (p *) Opaque() bool

    Opaque scans the entire image and reports whether it is fully opaque.

    func (*NRGBA64)

    1. func (p *) PixOffset(x, y int)

    PixOffset returns the index of the first element of Pix that corresponds to the
    pixel at (x, y).

    func (*NRGBA64) Set

    1. func (p *NRGBA64) Set(x, y , c color.)

    func (*NRGBA64) SetNRGBA64

    1. func (p *NRGBA64) SetNRGBA64(x, y , c color.)

    func (*NRGBA64) SubImage

    1. func (p *NRGBA64) SubImage(r ) 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

    1. type NYCbCrA struct {
    2. A []uint8
    3. AStride
    4. }

    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.

    func NewNYCbCrA

    1. func NewNYCbCrA(r Rectangle, subsampleRatio ) *NYCbCrA

    NewNYCbCrA returns a new NYCbCrA image with the given bounds and subsample
    ratio.

    func (*NYCbCrA)

    1. func (p *) AOffset(x, y int)

    AOffset returns the index of the first element of A that corresponds to the
    pixel at (x, y).

    func (*NYCbCrA) At

    1. func (p *NYCbCrA) At(x, y ) color.

    func (*NYCbCrA) ColorModel

    1. func (p *NYCbCrA) ColorModel() .Model

    func (*NYCbCrA)

    1. func (p *) NYCbCrAAt(x, y int) .NYCbCrA

    func (*NYCbCrA)

    1. func (p *) Opaque() bool

    Opaque scans the entire image and reports whether it is fully opaque.

    func (*NYCbCrA)

    1. func (p *) SubImage(r Rectangle)

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

    type Paletted

    1. type Paletted struct {
    2. // Pix holds the image's pixels, as palette indices. The pixel at
    3. // (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*1].
    4. Pix []uint8
    5. // Stride is the Pix stride (in bytes) between vertically adjacent pixels.
    6. Stride
    7. // Rect is the image's bounds.
    8. Rect Rectangle
    9. // Palette is the image's palette.
    10. Palette .Palette
    11. }

    Paletted is an in-memory image of uint8 indices into a given palette.

    func

    1. func NewPaletted(r , p color.) *Paletted

    NewPaletted returns a new Paletted image with the given width, height and
    palette.

    func (*Paletted)

    1. func (p *) At(x, y int) .Color

    func (*Paletted)

    1. func (p *) Bounds() Rectangle

    func (*Paletted)

    1. func (p *) ColorIndexAt(x, y int)

    func (*Paletted) ColorModel

    1. func (p *Paletted) ColorModel() .Model

    func (*Paletted)

    1. func (p *) Opaque() bool

    Opaque scans the entire image and reports whether it is fully opaque.

    func (*Paletted)

    1. func (p *) PixOffset(x, y int)

    PixOffset returns the index of the first element of Pix that corresponds to the
    pixel at (x, y).

    func (*Paletted) Set

    1. func (p *Paletted) Set(x, y , c color.)

    func (*Paletted) SetColorIndex

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

    func (*Paletted)

    1. func (p *) SubImage(r Rectangle)

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

    1. type PalettedImage interface {
    2. // ColorIndexAt returns the palette index of the pixel at (x, y).
    3. ColorIndexAt(x, y int)
    4. Image
    5. }

    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

    1. type Point struct {
    2. X, Y
    3. }

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

    1. var ZP Point

    ZP is the zero Point.

    func

    1. func Pt(X, Y ) Point

    Pt is shorthand for Point{X, Y}.

    func (Point)

    1. func (p ) Add(q Point)

    Add returns the vector p+q.

    func (Point) Div

    1. func (p Point) Div(k ) Point

    Div returns the vector p/k.

    func (Point)

    1. func (p ) Eq(q Point)

    Eq reports whether p and q are equal.

    func (Point) In

    1. func (p Point) In(r ) bool

    In reports whether p is in r.

    func (Point)

    1. func (p ) Mod(r 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 (Point) Mul

    1. func (p Point) Mul(k ) Point

    Mul returns the vector p*k.

    func (Point)

    1. func (p ) String() string

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

    func (Point)

    1. func (p ) Sub(q Point)

    Sub returns the vector p-q.

    type RGBA

    1. type RGBA struct {
    2. // Pix holds the image's pixels, in R, G, B, A order. The pixel at
    3. // (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*4].
    4. Pix []uint8
    5. // Stride is the Pix stride (in bytes) between vertically adjacent pixels.
    6. Stride
    7. // Rect is the image's bounds.
    8. Rect Rectangle
    9. }

    RGBA is an in-memory image whose At method returns color.RGBA values.

    func

    1. func NewRGBA(r ) *RGBA

    NewRGBA returns a new RGBA image with the given bounds.

    func (*RGBA)

    1. func (p *) At(x, y int) .Color

    func (*RGBA)

    1. func (p *) ColorModel() color.

    func (*RGBA) Opaque

    1. func (p *RGBA) Opaque()

    Opaque scans the entire image and reports whether it is fully opaque.

    func (*RGBA) PixOffset

    1. func (p *RGBA) PixOffset(x, y ) int

    PixOffset returns the index of the first element of Pix that corresponds to the
    pixel at (x, y).

    func (*RGBA)

    1. func (p *) RGBAAt(x, y int) .RGBA

    func (*RGBA)

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

    func (*RGBA)

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

    func (*RGBA)

    1. func (p *) SubImage(r Rectangle)

    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

    1. type RGBA64 struct {
    2. // Pix holds the image's pixels, in R, G, B, A order and big-endian format. The pixel at
    3. // (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*8].
    4. Pix []uint8
    5. // Stride is the Pix stride (in bytes) between vertically adjacent pixels.
    6. Stride
    7. // Rect is the image's bounds.
    8. Rect Rectangle
    9. }

    RGBA64 is an in-memory image whose At method returns color.RGBA64 values.

    func

    1. func NewRGBA64(r ) *RGBA64

    NewRGBA64 returns a new RGBA64 image with the given bounds.

    func (*RGBA64)

    1. func (p *) At(x, y int) .Color

    func (*RGBA64)

    1. func (p *) Bounds() Rectangle

    func (*RGBA64)

    1. func (p *) ColorModel() color.

    func (*RGBA64) Opaque

    1. func (p *RGBA64) Opaque()

    Opaque scans the entire image and reports whether it is fully opaque.

    func (*RGBA64) PixOffset

    1. func (p *RGBA64) PixOffset(x, y ) int

    PixOffset returns the index of the first element of Pix that corresponds to the
    pixel at (x, y).

    func (*RGBA64)

    1. func (p *) RGBA64At(x, y int) .RGBA64

    func (*RGBA64)

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

    func (*RGBA64)

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

    func (*RGBA64)

    1. func (p *) SubImage(r Rectangle)

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

    type Rectangle

    1. type Rectangle struct {
    2. Min, Max Point
    3. }

    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.

    1. var ZR

    ZR is the zero Rectangle.

    func Rect

    1. func Rect(x0, y0, x1, y1 int)

    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 (Rectangle) Add

    1. func (r Rectangle) Add(p ) Rectangle

    Add returns the rectangle r translated by p.

    func (Rectangle)

    1. func (r ) At(x, y int) .Color

    At implements the Image interface.

    func (Rectangle)

    1. func (r ) Bounds() Rectangle

    Bounds implements the Image interface.

    func (Rectangle)

    1. func (r ) 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)

    1. func (r ) ColorModel() color.

    ColorModel implements the Image interface.

    func (Rectangle) Dx

    1. func (r Rectangle) Dx()

    Dx returns r’s width.

    func (Rectangle) Dy

    1. func (r Rectangle) Dy()

    Dy returns r’s height.

    func (Rectangle) Empty

    1. func (r Rectangle) Empty()

    Empty reports whether the rectangle contains no points.

    func (Rectangle) Eq

    1. func (r Rectangle) Eq(s ) bool

    Eq reports whether r and s contain the same set of points. All empty rectangles
    are considered equal.

    func (Rectangle)

    1. func (r ) In(s Rectangle)

    In reports whether every point in r is in s.

    func (Rectangle) Inset

    1. func (r Rectangle) Inset(n ) 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)

    1. func (r ) Intersect(s 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

    1. func (r Rectangle) Overlaps(s ) bool

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

    func (Rectangle)

    1. func (r ) Size() Point

    Size returns r’s width and height.

    func (Rectangle)

    1. func (r ) String() string

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

    func (Rectangle)

    1. func (r ) Sub(p Point)

    Sub returns the rectangle r translated by -p.

    func (Rectangle) Union

    1. func (r Rectangle) Union(s ) Rectangle

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

    type

    1. type Uniform struct {
    2. C .Color
    3. }

    Uniform is an infinite-sized Image of uniform color. It implements the
    color.Color, color.Model, and Image interfaces.

    func

    1. func NewUniform(c .Color) *

    func (*Uniform) At

    1. func (c *Uniform) At(x, y ) color.

    func (*Uniform) Bounds

    1. func (c *Uniform) Bounds()

    func (*Uniform) ColorModel

    1. func (c *Uniform) ColorModel() .Model

    func (*Uniform)

    1. func (c *) Convert(color.) color.

    func (*Uniform) Opaque

    1. func (c *Uniform) Opaque()

    Opaque scans the entire image and reports whether it is fully opaque.

    func (*Uniform) RGBA

    1. func (c *Uniform) RGBA() (r, g, b, a )

    type YCbCr

    1. type YCbCr struct {
    2. Y, Cb, Cr []uint8
    3. YStride
    4. CStride int
    5. SubsampleRatio
    6. Rect Rectangle
    7. }

    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:

    1. For 4:4:4, CStride == YStride/1 && len(Cb) == len(Cr) == len(Y)/1.
    2. For 4:2:2, CStride == YStride/2 && len(Cb) == len(Cr) == len(Y)/2.
    3. For 4:2:0, CStride == YStride/2 && len(Cb) == len(Cr) == len(Y)/4.
    4. For 4:4:0, CStride == YStride/1 && len(Cb) == len(Cr) == len(Y)/2.
    5. For 4:1:0, CStride == YStride/4 && len(Cb) == len(Cr) == len(Y)/8.

    func

    1. func NewYCbCr(r , subsampleRatio YCbCrSubsampleRatio) *

    NewYCbCr returns a new YCbCr image with the given bounds and subsample ratio.

    func (*YCbCr) At

    1. func (p *YCbCr) At(x, y ) color.

    func (*YCbCr) Bounds

    1. func (p *YCbCr) Bounds()

    func (*YCbCr) COffset

    1. func (p *YCbCr) COffset(x, y ) int

    COffset returns the index of the first element of Cb or Cr that corresponds to
    the pixel at (x, y).

    func (*YCbCr)

    1. func (p *) ColorModel() color.

    func (*YCbCr) Opaque

    1. func (p *YCbCr) Opaque()

    func (*YCbCr) SubImage

    1. func (p *YCbCr) SubImage(r ) 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 (*YCbCr)

    1. func (p *) YCbCrAt(x, y int) .YCbCr

    1. func (p *) YOffset(x, y int)

    YOffset returns the index of the first element of Y that corresponds to the
    pixel at (x, y).

    type YCbCrSubsampleRatio

    1. type YCbCrSubsampleRatio int

    YCbCrSubsampleRatio is the chroma subsample ratio used in a YCbCr image.

    1. const (
    2. YCbCrSubsampleRatio444 = iota
    3. YCbCrSubsampleRatio422
    4. YCbCrSubsampleRatio420
    5. YCbCrSubsampleRatio440
    6. YCbCrSubsampleRatio411
    7. YCbCrSubsampleRatio410
    8. )

    func (YCbCrSubsampleRatio)