Documentation ¶
Overview ¶
Package netpbm implements image decoders and encoders for the Netpbm image formats: PBM (black and white), PGM (grayscale), PPM (color), and PAM (black and white, grayscale, or color, as indicated by the image header). Both "raw" (binary) and "plain" (ASCII) files can be read and written. Both 8-bit and 16-bit color channels are supported.
The netpbm package is fully compatible with the image package in the standard library but additionally reproduces the Netpbm library's ability to promote formats during decode. That is, a program that expects to read a grayscale image can also be given a black-and-white image, and a program that expects to read a color image can also be given either a grayscale or a black-and-white image.
The Netpbm home page is at http://netpbm.sourceforge.net/.
Index ¶
- func DecodeConfig(r io.Reader) (image.Config, error)
- func DecodeConfigWithComments(r io.Reader) (image.Config, []string, error)
- func Encode(w io.Writer, img image.Image, opts *EncodeOptions) error
- type BW
- type DecodeOptions
- type EncodeOptions
- type Format
- type GrayAM
- func (p *GrayAM) At(x, y int) color.Color
- func (p *GrayAM) Bounds() image.Rectangle
- func (p *GrayAM) ColorModel() color.Model
- func (p *GrayAM) Format() Format
- func (p *GrayAM) GrayAMAt(x, y int) npcolor.GrayAM
- func (p *GrayAM) HasAlpha() bool
- func (p *GrayAM) MaxValue() uint16
- func (p *GrayAM) Opaque() bool
- func (p *GrayAM) PixOffset(x, y int) int
- func (p *GrayAM) Set(x, y int, c color.Color)
- func (p *GrayAM) SetGrayAM(x, y int, c npcolor.GrayAM)
- func (p *GrayAM) SubImage(r image.Rectangle) image.Image
- type GrayAM48
- func (p *GrayAM48) At(x, y int) color.Color
- func (p *GrayAM48) Bounds() image.Rectangle
- func (p *GrayAM48) ColorModel() color.Model
- func (p *GrayAM48) Format() Format
- func (p *GrayAM48) GrayAM48At(x, y int) npcolor.GrayAM48
- func (p *GrayAM48) HasAlpha() bool
- func (p *GrayAM48) MaxValue() uint16
- func (p *GrayAM48) Opaque() bool
- func (p *GrayAM48) PixOffset(x, y int) int
- func (p *GrayAM48) Set(x, y int, c color.Color)
- func (p *GrayAM48) SetGrayAM48(x, y int, c npcolor.GrayAM48)
- func (p *GrayAM48) SubImage(r image.Rectangle) image.Image
- type GrayM
- func (p *GrayM) At(x, y int) color.Color
- func (p *GrayM) Bounds() image.Rectangle
- func (p *GrayM) ColorModel() color.Model
- func (p *GrayM) Format() Format
- func (p *GrayM) GrayMAt(x, y int) npcolor.GrayM
- func (p *GrayM) HasAlpha() bool
- func (p *GrayM) MaxValue() uint16
- func (p *GrayM) Opaque() bool
- func (p *GrayM) PixOffset(x, y int) int
- func (p *GrayM) PromoteToRGBM() *RGBM
- func (p *GrayM) Set(x, y int, c color.Color)
- func (p *GrayM) SetGrayM(x, y int, c npcolor.GrayM)
- func (p *GrayM) SubImage(r image.Rectangle) image.Image
- type GrayM32
- func (p *GrayM32) At(x, y int) color.Color
- func (p *GrayM32) Bounds() image.Rectangle
- func (p *GrayM32) ColorModel() color.Model
- func (p *GrayM32) Format() Format
- func (p *GrayM32) GrayM32At(x, y int) npcolor.GrayM32
- func (p *GrayM32) HasAlpha() bool
- func (p *GrayM32) MaxValue() uint16
- func (p *GrayM32) Opaque() bool
- func (p *GrayM32) PixOffset(x, y int) int
- func (p *GrayM32) PromoteToRGBM64() *RGBM64
- func (p *GrayM32) Set(x, y int, c color.Color)
- func (p *GrayM32) SetGrayM32(x, y int, c npcolor.GrayM32)
- func (p *GrayM32) SubImage(r image.Rectangle) image.Image
- type Image
- type RGBAM
- func (p *RGBAM) At(x, y int) color.Color
- func (p *RGBAM) Bounds() image.Rectangle
- func (p *RGBAM) ColorModel() color.Model
- func (p *RGBAM) Format() Format
- func (p *RGBAM) HasAlpha() bool
- func (p *RGBAM) MaxValue() uint16
- func (p *RGBAM) Opaque() bool
- func (p *RGBAM) PixOffset(x, y int) int
- func (p *RGBAM) RGBAMAt(x, y int) npcolor.RGBAM
- func (p *RGBAM) Set(x, y int, c color.Color)
- func (p *RGBAM) SetRGBAM(x, y int, c npcolor.RGBAM)
- func (p *RGBAM) SubImage(r image.Rectangle) image.Image
- type RGBAM64
- func (p *RGBAM64) At(x, y int) color.Color
- func (p *RGBAM64) Bounds() image.Rectangle
- func (p *RGBAM64) ColorModel() color.Model
- func (p *RGBAM64) Format() Format
- func (p *RGBAM64) HasAlpha() bool
- func (p *RGBAM64) MaxValue() uint16
- func (p *RGBAM64) Opaque() bool
- func (p *RGBAM64) PixOffset(x, y int) int
- func (p *RGBAM64) RGBAM64At(x, y int) npcolor.RGBAM64
- func (p *RGBAM64) Set(x, y int, c color.Color)
- func (p *RGBAM64) SetRGBAM64(x, y int, c npcolor.RGBAM64)
- func (p *RGBAM64) SubImage(r image.Rectangle) image.Image
- type RGBM
- func (p *RGBM) At(x, y int) color.Color
- func (p *RGBM) Bounds() image.Rectangle
- func (p *RGBM) ColorModel() color.Model
- func (p *RGBM) Format() Format
- func (p *RGBM) HasAlpha() bool
- func (p *RGBM) MaxValue() uint16
- func (p *RGBM) Opaque() bool
- func (p *RGBM) PixOffset(x, y int) int
- func (p *RGBM) RGBMAt(x, y int) npcolor.RGBM
- func (p *RGBM) Set(x, y int, c color.Color)
- func (p *RGBM) SetRGBM(x, y int, c npcolor.RGBM)
- func (p *RGBM) SubImage(r image.Rectangle) image.Image
- type RGBM64
- func (p *RGBM64) At(x, y int) color.Color
- func (p *RGBM64) Bounds() image.Rectangle
- func (p *RGBM64) ColorModel() color.Model
- func (p *RGBM64) Format() Format
- func (p *RGBM64) HasAlpha() bool
- func (p *RGBM64) MaxValue() uint16
- func (p *RGBM64) Opaque() bool
- func (p *RGBM64) PixOffset(x, y int) int
- func (p *RGBM64) RGBM64At(x, y int) npcolor.RGBM64
- func (p *RGBM64) Set(x, y int, c color.Color)
- func (p *RGBM64) SetRGBM64(x, y int, c npcolor.RGBM64)
- func (p *RGBM64) SubImage(r image.Rectangle) image.Image
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeConfig ¶
DecodeConfig returns image metadata without decoding the entire image. Pass in a bufio.Reader if you intend to read data following the image header.
func DecodeConfigWithComments ¶ added in v1.1.0
DecodeConfigWithComments returns image metadata without decoding the entire image. Unlike Decode, it also returns any comments appearing in the file. Pass in a bufio.Reader if you intend to read data following the image header.
func Encode ¶
Encode writes an arbitrary image in any of the Netpbm formats. Given an opts.Format of PNM, use the image's Format if img is a Netpbm image or PPM if not. Given an opts.MaxValue of 0, use the image's MaxValue if img is a Netpbm image or 255 if not. Given a nil opts, assign Format as if it were PNM and MaxValue as if it were 0.
Example ¶
package main import ( "bytes" "fmt" "image" "strings" "github.com/spakin/netpbm" "github.com/spakin/netpbm/npcolor" ) func main() { // In this example, we create an 800x800 color image with a maximum // per-channel value of 800 and fill it with a gradient pattern. We // then write the image in "plain" (ASCII) PPM format to a string and // output the first few lines of that string. More typical usage would // be to write to a file and to output in "raw" (binary) format. // Create an image with a gradient pattern. const edge = 800 // Width, height, and maximum channel value img := netpbm.NewRGBM64(image.Rect(0, 0, edge, edge), edge) for r := 0; r < edge; r++ { for c := 0; c < edge; c++ { rgbm := npcolor.RGBM64{ R: uint16(r), G: 0, B: uint16(c), M: edge, } img.SetRGBM64(c, r, rgbm) } } // Write the image to a string. var ppmBytes bytes.Buffer err := netpbm.Encode(&ppmBytes, img, &netpbm.EncodeOptions{ Format: img.Format(), // Original format MaxValue: img.MaxValue(), // Original maximum value Plain: true, // ASCII output to clarify output Comments: []string{"Sample PPM file"}, }) if err != nil { panic(err) } ppmLines := strings.Split(ppmBytes.String(), "\n") // Output the first few lines of the PPM file. for i, line := range ppmLines { fmt.Println(line) if i == 6 { break } } }
Output: P3 # Sample PPM file 800 800 800 0 0 0 0 0 1 0 0 2 0 0 3 0 0 4 0 0 5 0 0 6 0 0 7 0 0 8 0 0 9 0 0 10 0 0 11 0 0 12 0 0 13 0 0 14 0 0 15 0 0 16 0 0 17 0 0 18 0 0 19 0 0 20 0 0 21 0 0 22 0 0 23 0 0 24 0 0 25 0 0 26 0 0 27 0 0 28 0 0 29 0 0 30 0
Types ¶
type BW ¶
A BW is simply an alias for an image.Paletted. However, it is intended to represent images containing only white and black in their color palette.
func (*BW) PromoteToGrayM ¶
PromoteToGrayM generates an 8-bit grayscale image that looks identical to the given black-and-white image. It takes as input a maximum channel value.
func (*BW) PromoteToGrayM32 ¶
PromoteToGrayM32 generates an 16-bit grayscale image that looks identical to the given black-and-white image. It takes as input a maximum channel value.
type DecodeOptions ¶
type DecodeOptions struct { Target Format // Netpbm format to return Exact bool // true=allow only Target; false=promote lesser formats PBMMaxValue uint16 // Maximum channel value to use when promoting a PBM image (0=default) }
DecodeOptions represents a list of options for decoding a Netpbm file.
type EncodeOptions ¶
type EncodeOptions struct { Format Format // Netpbm format MaxValue uint16 // Maximum value for each color channel (ignored for PBM) Plain bool // true="plain" (ASCII); false="raw" (binary) TupleType string // Image tuple type for a PAM image (RGB_ALPHA, etc.) Comments []string // Header comments, with no leading "#" or trailing newlines }
EncodeOptions represents a list of options for writing a Netpbm file.
type Format ¶
type Format int
A Format represents a specific Netpbm format.
const ( PNM Format = iota // Portable Any Map (any of PBM, PGM, or PPM) PBM // Portable Bit Map (black and white) PGM // Portable Gray Map (grayscale) PPM // Portable Pixel Map (color) PAM // Portable Arbitrary Map (B&W, grayscale, or color with optional alpha) )
Define a symbol for each supported Netpbm format.
type GrayAM ¶ added in v1.2.0
type GrayAM struct { // Pix holds the image's pixels in Y, A order. 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 image.Rectangle // Model is the image's color model. Model npcolor.GrayAMModel }
A GrayAM is an in-memory image whose At method returns npcolor.GrayAM values.
func NewGrayAM ¶ added in v1.2.0
NewGrayAM returns a new GrayAM with the given bounds and maximum channel value.
func (*GrayAM) At ¶ added in v1.2.0
At returns the color of the pixel at (x, y) as a color.Color. 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.
func (*GrayAM) Bounds ¶ added in v1.2.0
Bounds returns the domain for which At can return non-zero color. The bounds do not necessarily contain the point (0, 0).
func (*GrayAM) ColorModel ¶ added in v1.2.0
ColorModel returns the GrayAM image's color model.
func (*GrayAM) GrayAMAt ¶ added in v1.2.0
GrayAMAt returns the color of the pixel at (x, y) as an npcolor.GrayAM.
func (*GrayAM) MaxValue ¶ added in v1.2.0
MaxValue returns the maximum value allowed on any color channel.
func (*GrayAM) Opaque ¶ added in v1.2.0
Opaque scans the entire image and reports whether it is fully opaque.
func (*GrayAM) PixOffset ¶ added in v1.2.0
PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).
func (*GrayAM) Set ¶ added in v1.2.0
Set sets the pixel at (x, y) to a given color, expressed as a color.Color.
type GrayAM48 ¶ added in v1.2.0
type GrayAM48 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)*4]. Pix []uint8 // Stride is the Pix stride (in bytes) between vertically adjacent // pixels. Stride int // Rect is the image's bounds. Rect image.Rectangle // Model is the image's color model. Model npcolor.GrayAM48Model }
A GrayAM48 is an in-memory image whose At method returns npcolor.GrayAM48 values.
func NewGrayAM48 ¶ added in v1.2.0
NewGrayAM48 returns a new GrayAM48 with the given bounds and maximum channel value.
func (*GrayAM48) At ¶ added in v1.2.0
At returns the color of the pixel at (x, y) as a color.Color. 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.
func (*GrayAM48) Bounds ¶ added in v1.2.0
Bounds returns the domain for which At can return non-zero color. The bounds do not necessarily contain the point (0, 0).
func (*GrayAM48) ColorModel ¶ added in v1.2.0
ColorModel returns the GrayAM48 image's color model.
func (*GrayAM48) GrayAM48At ¶ added in v1.2.0
GrayAM48At returns the color of the pixel at (x, y) as an npcolor.GrayAM48.
func (*GrayAM48) MaxValue ¶ added in v1.2.0
MaxValue returns the maximum value allowed on any color channel.
func (*GrayAM48) Opaque ¶ added in v1.2.0
Opaque scans the entire image and reports whether it is fully opaque.
func (*GrayAM48) PixOffset ¶ added in v1.2.0
PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).
func (*GrayAM48) Set ¶ added in v1.2.0
Set sets the pixel at (x, y) to a given color, expressed as a color.Color.
func (*GrayAM48) SetGrayAM48 ¶ added in v1.2.0
SetGrayAM48 sets the pixel at (x, y) to a given color, expressed as an npcolor.GrayAM48.
type GrayM ¶
type GrayM 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 image.Rectangle // Model is the image's color model. Model npcolor.GrayMModel }
GrayM is an in-memory image whose At method returns npcolor.GrayM values.
func (*GrayM) At ¶
At returns the color of the pixel at (x, y) as a color.Color. 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.
func (*GrayM) Bounds ¶
Bounds returns the domain for which At can return non-zero color. The bounds do not necessarily contain the point (0, 0).
func (*GrayM) ColorModel ¶
ColorModel returns the GrayM image's color model.
func (*GrayM) PixOffset ¶
PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).
func (*GrayM) PromoteToRGBM ¶
PromoteToRGBM generates an 8-bit color image that looks identical to the given grayscale image.
type GrayM32 ¶
type GrayM32 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 image.Rectangle // Model is the image's color model. Model npcolor.GrayM32Model }
GrayM32 is an in-memory image whose At method returns npcolor.GrayM32 values.
func NewGrayM32 ¶
NewGrayM32 returns a new GrayM32 with the given bounds and maximum channel value.
func (*GrayM32) At ¶
At returns the color of the pixel at (x, y) as a color.Color. 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.
func (*GrayM32) Bounds ¶
Bounds returns the domain for which At can return non-zero color. The bounds do not necessarily contain the point (0, 0).
func (*GrayM32) ColorModel ¶
ColorModel returns the GrayM32 image's color model.
func (*GrayM32) GrayM32At ¶
GrayM32At returns the color of the pixel at (x, y) as an npcolor.GrayM32.
func (*GrayM32) PixOffset ¶
PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).
func (*GrayM32) PromoteToRGBM64 ¶
PromoteToRGBM64 generates a 16-bit color image that looks identical to the given grayscale image.
func (*GrayM32) SetGrayM32 ¶
SetGrayM32 sets the pixel at (x, y) to a given color, expressed as an npcolor.GrayM32.
type Image ¶
type Image interface { image.Image // At, Bounds, and ColorModel MaxValue() uint16 // Maximum value on each color channel Format() Format // Netpbm format HasAlpha() bool // true=alpha channel; false=no alpha channel Opaque() bool // Report whether the image is fully opaque PixOffset(x, y int) int // Find (x, y) in pixel data Set(x, y int, c color.Color) // Set a pixel to a color SubImage(r image.Rectangle) image.Image // Portion of the image visible through r }
An Image extends image.Image to include a few extra methods.
func AddAlpha ¶ added in v1.2.0
AddAlpha adds an alpha channel to a Netpbm image. It returns a new image and a success code. If the input image already has an alpha channel, this is considered failure.
func Decode ¶
func Decode(r io.Reader, opts *DecodeOptions) (Image, error)
Decode reads a Netpbm image from r and returns it as an Image. a bufio.Reader if you intend to read data following the image.
Example ¶
package main import ( "bytes" "compress/flate" "fmt" "github.com/spakin/netpbm" ) func main() { // In this example, we read a PBM (black and white) "file" (really a // hard-wired string to make the example self-contained) into a PPM // (color) image. Because netpbm.Decode returns a netpbm.Image, not a // generic image.Image we can query its Netpbm format and maximum // value. We also output an arbitrary white pixel to show how B&W can // be promoted to color. const pbmRaw = "\n0\xe1RVp\x0eru\f\xf1\x0f\xb2Rp\xf7\xf4\rP\b\xf0\xf3Up\xcb\xcc)I-R\bK-*\xce\xcc\xcfS0\xd43\xe423Q02\xe1\xfa\x0f\x02\xff\xfe\xff\x06\xd3\x1f\xec\x1b\xc1\xf4a{\x060\xddo\xc3\x01\xa6\xe5l*\xc0\xca\xea,~\x80\xe8?\u007f\n\u007f\x82\xe8\x9f\xff\x1eC\xe8\xff\xcf?\x02\xa9\v\xc6\xff\xfa?\xff\xff\xdf\xc0\xfd|A\xff\xe3\xff\x17\xe2\xff\x1fc\x90?\xfe\x83\xf5\xff\x97\xbeB\xfb\xe3M\xff\xff2\xcc\u007fd/\xbf\xff/\x03\xb7\xfc\xa1:\xf9\xff\f\xfc\xff\xed\xfbj\xec\xff\x89\xff\a\xd2\x15\xf5 \xe3\xed\xe4\x12\xc0\xd6\xd8\xd81\x82i\x81\u007f\xec`\x9a\xf1\u007f?\xd8\x19`\x1e\x1a\x00\x04\x00\x00\xff\xff" r := flate.NewReader(bytes.NewBufferString(pbmRaw)) img, err := netpbm.Decode(r, &netpbm.DecodeOptions{ Target: netpbm.PPM, // Want to wind up with color Exact: false, // Can accept grayscale or B&W too PBMMaxValue: 42, // B&W white --> (42, 42, 42) }) if err != nil { panic(err) } r.Close() fmt.Printf("Image is of type %s.\n", img.Format()) fmt.Printf("Maximum channel value is %d.\n", img.MaxValue()) fmt.Printf("Color at (32, 20) is %#v.\n", img.At(32, 20)) }
Output: Image is of type PPM. Maximum channel value is 42. Color at (32, 20) is npcolor.RGBM{R:0x2a, G:0x2a, B:0x2a, M:0x2a}.
func DecodeWithComments ¶ added in v1.1.0
DecodeWithComments reads a Netpbm image from r and returns it as an Image. Unlike Decode, it also returns any comments appearing in the file. Pass in a bufio.Reader if you intend to read data following the image.
func RemoveAlpha ¶ added in v1.2.0
RemoveAlpha removes the alpha channel from a Netpbm image. It returns a new image and a success code. If the input image does not have an alpha channel, this is considered failure.
type RGBAM ¶
type RGBAM struct { // Pix holds the image's pixels, in R, G, B (no M) 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 image.Rectangle // Model is the image's color model. Model npcolor.RGBAMModel }
A RGBAM is an in-memory image whose At method returns npcolor.RGBAM values.
func (*RGBAM) At ¶
At returns the color of the pixel at (x, y) as a color.Color. 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.
func (*RGBAM) Bounds ¶
Bounds returns the domain for which At can return non-zero color. The bounds do not necessarily contain the point (0, 0).
func (*RGBAM) ColorModel ¶
ColorModel returns the RGBAM image's color model.
func (*RGBAM) PixOffset ¶
PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).
type RGBAM64 ¶
type RGBAM64 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 image.Rectangle // Model is the image's color model. Model npcolor.RGBAM64Model }
A RGBAM64 is an in-memory image whose At method returns npcolor.RGBAM64 values.
func NewRGBAM64 ¶
NewRGBAM64 returns a new RGBAM64 with the given bounds and maximum channel value.
func (*RGBAM64) At ¶
At returns the color of the pixel at (x, y) as a color.Color. 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.
func (*RGBAM64) Bounds ¶
Bounds returns the domain for which At can return non-zero color. The bounds do not necessarily contain the point (0, 0).
func (*RGBAM64) ColorModel ¶
ColorModel returns the RGBAM64 image's color model.
func (*RGBAM64) PixOffset ¶
PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).
func (*RGBAM64) RGBAM64At ¶
RGBAM64At returns the color of the pixel at (x, y) as an npcolor.RGBAM64.
func (*RGBAM64) SetRGBAM64 ¶
SetRGBAM64 sets the pixel at (x, y) to a given color, expressed as an npcolor.RGBAM64.
type RGBM ¶
type RGBM struct { // Pix holds the image's pixels, in R, G, B (no M) order. The pixel at // (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*3]. Pix []uint8 // Stride is the Pix stride (in bytes) between vertically adjacent // pixels. Stride int // Rect is the image's bounds. Rect image.Rectangle // Model is the image's color model. Model npcolor.RGBMModel }
An RGBM is an in-memory image whose At method returns npcolor.RGBM values.
func (*RGBM) At ¶
At returns the color of the pixel at (x, y) as a color.Color. 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.
func (*RGBM) Bounds ¶
Bounds returns the domain for which At can return non-zero color. The bounds do not necessarily contain the point (0, 0).
func (*RGBM) ColorModel ¶
ColorModel returns the RGBM image's color model.
func (*RGBM) PixOffset ¶
PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).
type RGBM64 ¶
type RGBM64 struct { // Pix holds the image's pixels, in R, G, B, M 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 image.Rectangle // Model is the image's color model. Model npcolor.RGBM64Model }
An RGBM64 is an in-memory image whose At method returns npcolor.RGBM64 values.
func (*RGBM64) At ¶
At returns the color of the pixel at (x, y) as a color.Color. 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.
func (*RGBM64) Bounds ¶
Bounds returns the domain for which At can return non-zero color. The bounds do not necessarily contain the point (0, 0).
func (*RGBM64) ColorModel ¶
ColorModel returns the RGBM64 image's color model.
func (*RGBM64) PixOffset ¶
PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).