Documentation ¶
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
import _ "image/png"
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: https://golang.org/doc/articles/image_package.html
Example ¶
package main import ( "context" "encoding/base64" "fmt" "log" "strings" "github.com/rmamba/image" // Package image/jpeg is not used explicitly in the code below, // but is imported for its initialization side-effect, which allows // image.Decode to understand JPEG formatted images. Uncomment these // two lines to also understand GIF and PNG images: // _ "image/gif" // _ "image/png" _ "github.com/rmamba/image/jpeg" ) func main() { // Decode the JPEG data. If reading from file, create a reader with // // reader, err := os.Open("testdata/video-001.q50.420.jpeg") // if err != nil { // log.Fatal(err) // } // defer reader.Close() ctx := context.TODO() reader := base64.NewDecoder(base64.StdEncoding, strings.NewReader(data)) m, _, err := image.DecodeImage(ctx, reader) if err != nil { log.Fatal(err) } bounds := m.Bounds() // Calculate a 16-bin histogram for m's red, green, blue and alpha components. // // An image's bounds do not necessarily start at (0, 0), so the two loops start // at bounds.Min.Y and bounds.Min.X. Looping over Y first and X second is more // likely to result in better memory access patterns than X first and Y second. var histogram [16][4]int for y := bounds.Min.Y; y < bounds.Max.Y; y++ { for x := bounds.Min.X; x < bounds.Max.X; x++ { r, g, b, a := m.At(x, y).RGBA() // A color's RGBA method returns values in the range [0, 65535]. // Shifting by 12 reduces this to the range [0, 15]. histogram[r>>12][0]++ histogram[g>>12][1]++ histogram[b>>12][2]++ histogram[a>>12][3]++ } } // Print the results. fmt.Printf("%-14s %6s %6s %6s %6s\n", "bin", "red", "green", "blue", "alpha") for i, x := range histogram { fmt.Printf("0x%04x-0x%04x: %6d %6d %6d %6d\n", i<<12, (i+1)<<12-1, x[0], x[1], x[2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JF+T/r4f+QrqqKKQwzQenNFFMCOKFIgNuThdoJ5OPSk ubeK6t3gnXdG4wwziiii/UTKMOg6dbzJLFE4dSCP3rEdeOM8805tDsGMvySgSsS6rM6gk9eAcUUVftZt 3uyVGNthuq3Eei6DK8H7sRR7YuMgHtXkc8rzTNLM26RyWY+p70UVnLY0iEsUipG7rhZBlDkc1HgYoorM 0HwyBXGeRjmrcUhMg2ghezd//rUUVcTKW5s2jZtY/QDaOKKKK8ip8bPRj8KP/9k= `
Output: bin red green blue alpha 0x0000-0x0fff: 364 790 7242 0 0x1000-0x1fff: 645 2967 1039 0 0x2000-0x2fff: 1072 2299 979 0 0x3000-0x3fff: 820 2266 980 0 0x4000-0x4fff: 537 1305 541 0 0x5000-0x5fff: 319 962 261 0 0x6000-0x6fff: 322 375 177 0 0x7000-0x7fff: 601 279 214 0 0x8000-0x8fff: 3478 227 273 0 0x9000-0x9fff: 2260 234 329 0 0xa000-0xafff: 921 282 373 0 0xb000-0xbfff: 321 335 397 0 0xc000-0xcfff: 229 388 298 0 0xd000-0xdfff: 260 414 277 0 0xe000-0xefff: 516 428 298 0 0xf000-0xffff: 2785 1899 1772 15450
Example (DecodeConfig) ¶
package main import ( "encoding/base64" "fmt" "log" "strings" "github.com/rmamba/image" // Package image/jpeg is not used explicitly in the code below, // but is imported for its initialization side-effect, which allows // image.Decode to understand JPEG formatted images. Uncomment these // two lines to also understand GIF and PNG images: // _ "image/gif" // _ "image/png" _ "github.com/rmamba/image/jpeg" ) func main() { reader := base64.NewDecoder(base64.StdEncoding, strings.NewReader(data)) config, format, err := image.DecodeConfig(reader) if err != nil { log.Fatal(err) } fmt.Println("Width:", config.Width, "Height:", config.Height, "Format:", format) } const data = ` /9j/4AAQSkZJRgABAQIAHAAcAAD/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdA SFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2N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M26RyWY+p70UVnLY0iEsUipG7rhZBlDkc1HgYoorM 0HwyBXGeRjmrcUhMg2ghezd//rUUVcTKW5s2jZtY/QDaOKKKK8ip8bPRj8KP/9k= `
Output:
Index ¶
- Variables
- func DecodeWithOptions(ctx context.Context, r io.Reader, opts ...ReadOption) (Image, Metadata, string, error)
- func RegisterFormat(name, magic string, decode func(io.Reader) (Image, error), ...)
- func RegisterFormatExtended(name, magic string, ...)
- type Alpha
- func (p *Alpha) AlphaAt(x, y int) color.Alpha
- func (p *Alpha) At(x, y int) color.Color
- func (p *Alpha) Bounds() Rectangle
- func (p *Alpha) ColorModel() color.Model
- func (p *Alpha) Opaque() bool
- func (p *Alpha) PixOffset(x, y int) int
- func (p *Alpha) Set(x, y int, c color.Color)
- func (p *Alpha) SetAlpha(x, y int, c color.Alpha)
- func (p *Alpha) SubImage(r Rectangle) Image
- type Alpha16
- func (p *Alpha16) Alpha16At(x, y int) color.Alpha16
- func (p *Alpha16) At(x, y int) color.Color
- func (p *Alpha16) Bounds() Rectangle
- func (p *Alpha16) ColorModel() color.Model
- func (p *Alpha16) Opaque() bool
- func (p *Alpha16) PixOffset(x, y int) int
- func (p *Alpha16) Set(x, y int, c color.Color)
- func (p *Alpha16) SetAlpha16(x, y int, c color.Alpha16)
- func (p *Alpha16) SubImage(r Rectangle) Image
- type CMYK
- func (p *CMYK) At(x, y int) color.Color
- func (p *CMYK) Bounds() Rectangle
- func (p *CMYK) CMYKAt(x, y int) color.CMYK
- func (p *CMYK) ColorModel() color.Model
- func (p *CMYK) Opaque() bool
- func (p *CMYK) PixOffset(x, y int) int
- func (p *CMYK) Set(x, y int, c color.Color)
- func (p *CMYK) SetCMYK(x, y int, c color.CMYK)
- func (p *CMYK) SubImage(r Rectangle) Image
- type Config
- type DamageHandlingOptions
- type DataDecodeOptions
- type DecodingOption
- type Gray
- func (p *Gray) At(x, y int) color.Color
- func (p *Gray) Bounds() Rectangle
- func (p *Gray) ColorModel() color.Model
- func (p *Gray) GrayAt(x, y int) color.Gray
- func (p *Gray) Opaque() bool
- func (p *Gray) PixOffset(x, y int) int
- func (p *Gray) Set(x, y int, c color.Color)
- func (p *Gray) SetGray(x, y int, c color.Gray)
- func (p *Gray) SubImage(r Rectangle) Image
- type Gray16
- func (p *Gray16) At(x, y int) color.Color
- func (p *Gray16) Bounds() Rectangle
- func (p *Gray16) ColorModel() color.Model
- func (p *Gray16) Gray16At(x, y int) color.Gray16
- func (p *Gray16) Opaque() bool
- func (p *Gray16) PixOffset(x, y int) int
- func (p *Gray16) Set(x, y int, c color.Color)
- func (p *Gray16) SetGray16(x, y int, c color.Gray16)
- func (p *Gray16) SubImage(r Rectangle) Image
- type Image
- type ImageTransformOptions
- type LimitOptions
- type Metadata
- type NRGBA
- func (p *NRGBA) At(x, y int) color.Color
- func (p *NRGBA) Bounds() Rectangle
- func (p *NRGBA) ColorModel() color.Model
- func (p *NRGBA) NRGBAAt(x, y int) color.NRGBA
- func (p *NRGBA) Opaque() bool
- func (p *NRGBA) PixOffset(x, y int) int
- func (p *NRGBA) Set(x, y int, c color.Color)
- func (p *NRGBA) SetNRGBA(x, y int, c color.NRGBA)
- func (p *NRGBA) SubImage(r Rectangle) Image
- type NRGBA64
- func (p *NRGBA64) At(x, y int) color.Color
- func (p *NRGBA64) Bounds() Rectangle
- func (p *NRGBA64) ColorModel() color.Model
- func (p *NRGBA64) NRGBA64At(x, y int) color.NRGBA64
- func (p *NRGBA64) Opaque() bool
- func (p *NRGBA64) PixOffset(x, y int) int
- func (p *NRGBA64) Set(x, y int, c color.Color)
- func (p *NRGBA64) SetNRGBA64(x, y int, c color.NRGBA64)
- func (p *NRGBA64) SubImage(r Rectangle) Image
- type NYCbCrA
- type Paletted
- func (p *Paletted) At(x, y int) color.Color
- func (p *Paletted) Bounds() Rectangle
- func (p *Paletted) ColorIndexAt(x, y int) uint8
- func (p *Paletted) ColorModel() color.Model
- func (p *Paletted) Opaque() bool
- func (p *Paletted) PixOffset(x, y int) int
- func (p *Paletted) Set(x, y int, c color.Color)
- func (p *Paletted) SetColorIndex(x, y int, index uint8)
- func (p *Paletted) SubImage(r Rectangle) Image
- type PalettedImage
- type Point
- type RGBA
- func (p *RGBA) At(x, y int) color.Color
- func (p *RGBA) Bounds() Rectangle
- func (p *RGBA) ColorModel() color.Model
- func (p *RGBA) Opaque() bool
- func (p *RGBA) PixOffset(x, y int) int
- func (p *RGBA) RGBAAt(x, y int) color.RGBA
- func (p *RGBA) Set(x, y int, c color.Color)
- func (p *RGBA) SetRGBA(x, y int, c color.RGBA)
- func (p *RGBA) SubImage(r Rectangle) Image
- type RGBA64
- func (p *RGBA64) At(x, y int) color.Color
- func (p *RGBA64) Bounds() Rectangle
- func (p *RGBA64) ColorModel() color.Model
- func (p *RGBA64) Opaque() bool
- func (p *RGBA64) PixOffset(x, y int) int
- func (p *RGBA64) RGBA64At(x, y int) color.RGBA64
- func (p *RGBA64) Set(x, y int, c color.Color)
- func (p *RGBA64) SetRGBA64(x, y int, c color.RGBA64)
- func (p *RGBA64) SubImage(r Rectangle) Image
- type ReadOption
- type Rectangle
- func (r Rectangle) Add(p Point) Rectangle
- func (r Rectangle) At(x, y int) color.Color
- func (r Rectangle) Bounds() Rectangle
- func (r Rectangle) Canon() Rectangle
- func (r Rectangle) ColorModel() color.Model
- func (r Rectangle) Dx() int
- func (r Rectangle) Dy() int
- func (r Rectangle) Empty() bool
- func (r Rectangle) Eq(s Rectangle) bool
- func (r Rectangle) In(s Rectangle) bool
- func (r Rectangle) Inset(n int) Rectangle
- func (r Rectangle) Intersect(s Rectangle) Rectangle
- func (r Rectangle) Overlaps(s Rectangle) bool
- func (r Rectangle) Size() Point
- func (r Rectangle) String() string
- func (r Rectangle) Sub(p Point) Rectangle
- func (r Rectangle) Union(s Rectangle) Rectangle
- type TransformOption
- type Uniform
- type WriteOption
- type YCbCr
- func (p *YCbCr) At(x, y int) color.Color
- func (p *YCbCr) Bounds() Rectangle
- func (p *YCbCr) COffset(x, y int) int
- func (p *YCbCr) ColorModel() color.Model
- func (p *YCbCr) Opaque() bool
- func (p *YCbCr) SubImage(r Rectangle) Image
- func (p *YCbCr) YCbCrAt(x, y int) color.YCbCr
- func (p *YCbCr) YOffset(x, y int) int
- type YCbCrSubsampleRatio
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( OptionDecodeImage = DataDecodeOptions{DecodeData, DiscardData} OptionDecodeMetadata = DataDecodeOptions{DiscardData, DecodeData} )
Sadly Go doesn't support constant structs or this would be a const
var ( // Black is an opaque black uniform image. Black = NewUniform(color.Black) // White is an opaque white uniform image. White = NewUniform(color.White) // Transparent is a fully transparent uniform image. Transparent = NewUniform(color.Transparent) // Opaque is a fully opaque uniform image. Opaque = NewUniform(color.Opaque) )
var ErrFormat = errors.New("image: unknown format")
ErrFormat indicates that decoding encountered an unknown format.
var ErrOption = errors.New("image: invalid options")
OptionError indicates that the read or write options provided to a call are invalid.
Functions ¶
func DecodeWithOptions ¶
func DecodeWithOptions(ctx context.Context, r io.Reader, opts ...ReadOption) (Image, Metadata, string, error)
DecodeWithOptions decodes an image in a registered format, its metadata, and its config. 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 RegisterFormat ¶
func RegisterFormat(name, magic string, decode func(io.Reader) (Image, error), decodeConfig func(io.Reader) (Config, 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.
This function is deprecated, and should only be used by image format decoders that don't support metadata decoding.
func RegisterFormatExtended ¶
func RegisterFormatExtended(name, magic string, decode func(context.Context, io.Reader, ...ReadOption) (Image, Metadata, error))
RegisterFormatExtended 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, its metadata, and its configuration information.
Types ¶
type Alpha ¶
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 }
Alpha is an in-memory image whose At method returns color.Alpha values.
func (*Alpha) ColorModel ¶
type Alpha16 ¶
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 }
Alpha16 is an in-memory image whose At method returns color.Alpha16 values.
func NewAlpha16 ¶
NewAlpha16 returns a new Alpha16 image with the given bounds.
func (*Alpha16) ColorModel ¶
type CMYK ¶
type CMYK struct { // Pix holds the image's pixels, in C, M, Y, K 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 }
CMYK is an in-memory image whose At method returns color.CMYK values.
func (*CMYK) ColorModel ¶
type Config ¶
Config holds an image's color model and dimensions.
func DecodeConfig ¶
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.
This function has been deprecated; use DecodeWithOptions or DecodeMetadata and extract the info you need from the metadata returned.
type DamageHandlingOptions ¶
type DamageHandlingOptions struct { // AllowTrailingData, if set to true, means that image file readers // won't consider extra data after the end of an image to be an // error. AllowTrailingData bool // SkipDamagedSections indicates that an image decoder should skip // damaged data instead of treating it as an error. Image readers // will ignore sections with format or checksum issues rather than // erroring out, and will skip damaged image data where possible. // // Even with this set images may still not decode, depending on what // kind of damage the image file has. SkipDamagedData bool // AllowMisorderedSections indicates that image decoders should // allow misordered data in image files if at all possible. This // does not guarantee that any random ordering of image data is // allowed -- image decoders may, for example, stop reading data // when the end-of-image marker is encountered (if the image file // format has one). Images may decode poorly in this case and // integrity or proper decoding isn't guaranteed. AllowMisorderedData bool }
DamageHandlingOptions hold settings that may allow reader code to read damaged or malformed image files. These options should only be provided when code is explicitly trying to read known-damaged image files and should not be used under normal circumstances.
func (DamageHandlingOptions) IsImageReadOption ¶
func (_ DamageHandlingOptions) IsImageReadOption()
IsImageReadOption is a no-op function which exists to satisfy the ReadOption interface.
type DataDecodeOptions ¶
type DataDecodeOptions struct { // DecodeImage specifies whether the image data should be decoded // when an image file is read. Valid options are // DefaultDecodeOption, DiscardData, or DecodeData. Default is // DecodeData. DecodeImage DecodingOption // DecodeMetadata specifies whether the image metadata should be // decoded when an image is read. Valid options are // DefaultDecodeData, DiscardData, DeferData, and // DecodeData. Default is DeferData. DecodeMetadata DecodingOption }
DataDecodeOptions notes which
func (DataDecodeOptions) IsImageReadOption ¶
func (_ DataDecodeOptions) IsImageReadOption()
IsImageReadOption is a no-op function which exists to satisfy the ReadOption interface.
type DecodingOption ¶
type DecodingOption int
DecodingOption notes when and if data should be decoded.
const ( // DefaultDecodeOption means the data should be read, ignored, or // deferred as appropriate for the data item. DefaultDecodeOption DecodingOption = iota // DiscardData indicates the data shouldn't be decoded at all. DiscardData // DeferData means as much of the data decoding should be deferred // as possible until it is used by the calling program Not all // decoding can be deferred. DeferData // DecodeData meads the data should be decoded as the image file is // read. DecodeData )
type Gray ¶
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 }
Gray is an in-memory image whose At method returns color.Gray values.
func (*Gray) ColorModel ¶
type Gray16 ¶
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 }
Gray16 is an in-memory image whose At method returns color.Gray16 values.
func (*Gray16) ColorModel ¶
type Image ¶
type Image interface { // ColorModel returns the Image's color model. ColorModel() color.Model // 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.Color }
Image is a finite rectangular grid of color.Color values taken from a color model.
func Decode ¶
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. (DEPRECATED)
func DecodeImage ¶
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 ImageTransformOptions ¶
type ImageTransformOptions struct { // RotationTransform controls how the image transform metadata // should be applied when reading an image. By defaul the image has // no rotation transformations applied. RotationTransform TransformOption // ColorTransform controls how the color metadata should be applied // when reading an image. By default the returned image has no color // transformations applied. ColorTransform TransformOption // GammaTransform controls how the gamma metadata should be applied // when reading an image. By default the returned image has no gamma // transformations applied. GammaTransform TransformOption }
ImageTransformOptions controls how the image transformation metadata embedded in an image file should be interpreted and applied.
For example, when you take a picture with your phone in landscape mode the image file will be saved in portrait orientation (that is, as if your phone was upright) with a metadata annotation noting the image should be rotated 90 degrees. If you read that image without reading the metadata then the image will look as if it's on its side. If you set RotationTransform to ForwardImageTransform, however, the image will be in its proper orientation.
func (ImageTransformOptions) IsImageReadOption ¶
func (_ ImageTransformOptions) IsImageReadOption()
IsImageReadOption is a no-op finction which exists to satisfy the ReadOption interface.
type LimitOptions ¶
type LimitOptions struct { // MaxImageSize is the maximum size, in bytes, a decoded image can // take. Images that decode larger than this will throw an error. MaxImageSize int // MaxMetadataSize is the maximum size, in bytes, decoded metadata // can take. Images with metadata larger than this will throw an // error. MaxMetadataSize int }
LimitOptions holds limits for the standard read options.
func (LimitOptions) IsImageReadOption ¶
func (_ LimitOptions) IsImageReadOption()
IsImageReadOption is a no-op function which exists to satisfy the ReadOption interface.
func (LimitOptions) IsImageWriteOption ¶
func (_ LimitOptions) IsImageWriteOption()
IsImaegWriteOption allows a LimitOptions struct get passed when writing out an image to allow size limits to be placed on the output file.
type Metadata ¶
type Metadata interface { // ImageMetadataFormat returns the image format for the // metadata. This should be the plain name of the format -- for // example, "jpeg", "gif", or "png" for jpeg, gif, or png image // metadata respectively. // // This is also appropriate for shared metadata structures, such as // XMP or EXIF, which can be applied to multiple image types. ImageMetadataFormat() string GetConfig() Config }
Metadata is image-encoding-specific metadata which can be attached to an image.
func DecodeMetadata ¶
Decode decodes the metadata for 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.
Note that if you need both the image and the metadata for an image it's more efficient to call DecodeWithOption and extract both simiultaneously.
type NRGBA ¶
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 }
NRGBA is an in-memory image whose At method returns color.NRGBA values.
func (*NRGBA) ColorModel ¶
type NRGBA64 ¶
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 }
NRGBA64 is an in-memory image whose At method returns color.NRGBA64 values.
func NewNRGBA64 ¶
NewNRGBA64 returns a new NRGBA64 image with the given bounds.
func (*NRGBA64) ColorModel ¶
type NYCbCrA ¶
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 ¶
func NewNYCbCrA(r Rectangle, subsampleRatio YCbCrSubsampleRatio) *NYCbCrA
NewNYCbCrA returns a new NYCbCrA image with the given bounds and subsample ratio.
func (*NYCbCrA) AOffset ¶
AOffset returns the index of the first element of A that corresponds to the pixel at (x, y).
func (*NYCbCrA) ColorModel ¶
type Paletted ¶
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 color.Palette }
Paletted is an in-memory image of uint8 indices into a given palette.
func NewPaletted ¶
NewPaletted returns a new Paletted image with the given width, height and palette.
func (*Paletted) ColorIndexAt ¶
func (*Paletted) ColorModel ¶
func (*Paletted) PixOffset ¶
PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).
func (*Paletted) SetColorIndex ¶
type PalettedImage ¶
type PalettedImage interface { // ColorIndexAt returns the palette index of the pixel at (x, y). ColorIndexAt(x, y int) uint8 Image }
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 Point ¶
type Point struct {
X, Y int
}
A Point is an X, Y coordinate pair. The axes increase right and down.
func (Point) Mod ¶
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.
type RGBA ¶
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 }
RGBA is an in-memory image whose At method returns color.RGBA values.
func (*RGBA) ColorModel ¶
type RGBA64 ¶
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 }
RGBA64 is an in-memory image whose At method returns color.RGBA64 values.
func (*RGBA64) ColorModel ¶
type ReadOption ¶
type ReadOption interface {
IsImageReadOption()
}
ReadOption is an option that controls how an image file is read. There are multiple different kinds of read options and individual image formats may declare their own as necessary.
type Rectangle ¶
type Rectangle struct {
Min, Max Point
}
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.
func Rect ¶
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) Canon ¶
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) ColorModel ¶
ColorModel implements the Image interface.
func (Rectangle) Eq ¶
Eq reports whether r and s contain the same set of points. All empty rectangles are considered equal.
func (Rectangle) Inset ¶
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 ¶
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.
type TransformOption ¶
type TransformOption int
const ( // ForwardImageTransform indicates the raw image data has not had // the metadata transformation applied, and that transformation // should be applied when the image is read. ForwardImageTransform TransformOption = 1 // ReverseImageTransform indicates the raw image has already had the // metadata transform applied, and that transformation should be // reversed when the image is read. ReverseImageTransform TransformOption = -1 // NoImageTransform indicates that the raw image data should not be // transformed. NoImageTransform TransformOption = 0 )
type Uniform ¶
Uniform is an infinite-sized Image of uniform color. It implements the color.Color, color.Model, and Image interfaces.
func NewUniform ¶
func (*Uniform) ColorModel ¶
type WriteOption ¶
type WriteOption interface {
IsImageWriteOption()
}
WriteOption holds options for writing image data out. Each image package may implement its own write options but should support the core image package's write options.
type YCbCr ¶
type YCbCr struct {
Y, Cb, Cr []uint8
YStride int
CStride int
SubsampleRatio YCbCrSubsampleRatio
Rect Rectangle
}
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.
func NewYCbCr ¶
func NewYCbCr(r Rectangle, subsampleRatio YCbCrSubsampleRatio) *YCbCr
NewYCbCr returns a new YCbCr image with the given bounds and subsample ratio.
func (*YCbCr) COffset ¶
COffset returns the index of the first element of Cb or Cr that corresponds to the pixel at (x, y).
func (*YCbCr) ColorModel ¶
type YCbCrSubsampleRatio ¶
type YCbCrSubsampleRatio int
YCbCrSubsampleRatio is the chroma subsample ratio used in a YCbCr image.
const ( YCbCrSubsampleRatio444 YCbCrSubsampleRatio = iota YCbCrSubsampleRatio422 YCbCrSubsampleRatio420 YCbCrSubsampleRatio440 YCbCrSubsampleRatio411 YCbCrSubsampleRatio410 )
func (YCbCrSubsampleRatio) String ¶
func (s YCbCrSubsampleRatio) String() string
Directories ¶
Path | Synopsis |
---|---|
Package color implements a basic color library.
|
Package color implements a basic color library. |
palette
Package palette provides standard color palettes.
|
Package palette provides standard color palettes. |
Package draw provides image composition functions.
|
Package draw provides image composition functions. |
example
|
|
forgiving
This program demonstrates loading in a potentally broken image to try and extract as much information as possible from it.
|
This program demonstrates loading in a potentally broken image to try and extract as much information as possible from it. |
metadata
This program takes an image file as an argument and dumps out some of the metadata information contained inside it.
|
This program takes an image file as an argument and dumps out some of the metadata information contained inside it. |
spacebound
This program demonstrates reading an image file with a bounded maximum amount of memory allowed for the image.
|
This program demonstrates reading an image file with a bounded maximum amount of memory allowed for the image. |
timeout
This program demonstrates reading an image file with a context that has a timeout set.
|
This program demonstrates reading an image file with a context that has a timeout set. |
transform
Transform shows how to load in an image and apply the transforms indicated in its metadata.
|
Transform shows how to load in an image and apply the transforms indicated in its metadata. |
Package gif implements a GIF image decoder and encoder.
|
Package gif implements a GIF image decoder and encoder. |
internal
|
|
imageutil
Package imageutil contains code shared by image-related packages.
|
Package imageutil contains code shared by image-related packages. |
Package jpeg implements a JPEG image decoder and encoder.
|
Package jpeg implements a JPEG image decoder and encoder. |
exif
Package exif encodes and decodes EXIF format image metadata.
|
Package exif encodes and decodes EXIF format image metadata. |
icc
Package icc encodes and decodes ICC color profiles.
|
Package icc encodes and decodes ICC color profiles. |
xmp
Package xmp encodes and decodes XMP format image metadata.
|
Package xmp encodes and decodes XMP format image metadata. |
Package png implements a PNG image decoder and encoder.
|
Package png implements a PNG image decoder and encoder. |