netpbm: github.com/spakin/netpbm Index | Examples | Files | Directories

package netpbm

import "github.com/spakin/netpbm"

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

Examples

Package Files

netpbm.go pam.go pbm.go pgm.go ppm.go

func DecodeConfig Uses

func DecodeConfig(r io.Reader) (image.Config, error)

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 Uses

func DecodeConfigWithComments(r io.Reader) (image.Config, []string, error)

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 Uses

func Encode(w io.Writer, img image.Image, opts *EncodeOptions) error

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.

Code:

// 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

type BW Uses

type BW struct{ *image.Paletted }

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 NewBW Uses

func NewBW(r image.Rectangle) *BW

NewBW returns a new black-and-white image with the given bounds and maximum value.

func (*BW) Format Uses

func (p *BW) Format() Format

Format identifies the image as a PBM image.

func (*BW) HasAlpha Uses

func (p *BW) HasAlpha() bool

HasAlpha indicates that there is no alpha channel.

func (*BW) MaxValue Uses

func (p *BW) MaxValue() uint16

MaxValue returns the maximum index value allowed.

func (*BW) PromoteToGrayM Uses

func (p *BW) PromoteToGrayM(m uint8) *GrayM

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 Uses

func (p *BW) PromoteToGrayM32(m uint16) *GrayM32

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 Uses

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 Uses

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 Uses

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.

func (Format) String Uses

func (f Format) String() string

String outputs the name of a Netpbm format.

type GrayAM Uses

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 Uses

func NewGrayAM(r image.Rectangle, m uint8) *GrayAM

NewGrayAM returns a new GrayAM with the given bounds and maximum channel value.

func (*GrayAM) At Uses

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

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 Uses

func (p *GrayAM) Bounds() image.Rectangle

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 Uses

func (p *GrayAM) ColorModel() color.Model

ColorModel returns the GrayAM image's color model.

func (*GrayAM) Format Uses

func (p *GrayAM) Format() Format

Format identifies the image as a PGM image.

func (*GrayAM) GrayAMAt Uses

func (p *GrayAM) GrayAMAt(x, y int) npcolor.GrayAM

GrayAMAt returns the color of the pixel at (x, y) as an npcolor.GrayAM.

func (*GrayAM) HasAlpha Uses

func (p *GrayAM) HasAlpha() bool

HasAlpha indicates that there is an alpha channel.

func (*GrayAM) MaxValue Uses

func (p *GrayAM) MaxValue() uint16

MaxValue returns the maximum value allowed on any color channel.

func (*GrayAM) Opaque Uses

func (p *GrayAM) Opaque() bool

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

func (*GrayAM) PixOffset Uses

func (p *GrayAM) PixOffset(x, y int) int

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

func (*GrayAM) Set Uses

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

Set sets the pixel at (x, y) to a given color, expressed as a color.Color.

func (*GrayAM) SetGrayAM Uses

func (p *GrayAM) SetGrayAM(x, y int, c npcolor.GrayAM)

SetGrayAM sets the pixel at (x, y) to a given color, expressed as an npcolor.GrayAM.

func (*GrayAM) SubImage Uses

func (p *GrayAM) SubImage(r image.Rectangle) image.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 GrayAM48 Uses

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 Uses

func NewGrayAM48(r image.Rectangle, m uint16) *GrayAM48

NewGrayAM48 returns a new GrayAM48 with the given bounds and maximum channel value.

func (*GrayAM48) At Uses

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

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 Uses

func (p *GrayAM48) Bounds() image.Rectangle

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 Uses

func (p *GrayAM48) ColorModel() color.Model

ColorModel returns the GrayAM48 image's color model.

func (*GrayAM48) Format Uses

func (p *GrayAM48) Format() Format

Format identifies the image as a PGM image.

func (*GrayAM48) GrayAM48At Uses

func (p *GrayAM48) GrayAM48At(x, y int) npcolor.GrayAM48

GrayAM48At returns the color of the pixel at (x, y) as an npcolor.GrayAM48.

func (*GrayAM48) HasAlpha Uses

func (p *GrayAM48) HasAlpha() bool

HasAlpha indicates that there is an alpha channel.

func (*GrayAM48) MaxValue Uses

func (p *GrayAM48) MaxValue() uint16

MaxValue returns the maximum value allowed on any color channel.

func (*GrayAM48) Opaque Uses

func (p *GrayAM48) Opaque() bool

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

func (*GrayAM48) PixOffset Uses

func (p *GrayAM48) PixOffset(x, y int) int

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

func (*GrayAM48) Set Uses

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

Set sets the pixel at (x, y) to a given color, expressed as a color.Color.

func (*GrayAM48) SetGrayAM48 Uses

func (p *GrayAM48) SetGrayAM48(x, y int, c npcolor.GrayAM48)

SetGrayAM48 sets the pixel at (x, y) to a given color, expressed as an npcolor.GrayAM48.

func (*GrayAM48) SubImage Uses

func (p *GrayAM48) SubImage(r image.Rectangle) image.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 GrayM Uses

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 NewGrayM Uses

func NewGrayM(r image.Rectangle, m uint8) *GrayM

NewGrayM returns a new GrayM with the given bounds and maximum channel value.

func (*GrayM) At Uses

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

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 Uses

func (p *GrayM) Bounds() image.Rectangle

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 Uses

func (p *GrayM) ColorModel() color.Model

ColorModel returns the GrayM image's color model.

func (*GrayM) Format Uses

func (p *GrayM) Format() Format

Format identifies the image as a PGM image.

func (*GrayM) GrayMAt Uses

func (p *GrayM) GrayMAt(x, y int) npcolor.GrayM

GrayMAt returns the color of the pixel at (x, y) as an npcolor.GrayM.

func (*GrayM) HasAlpha Uses

func (p *GrayM) HasAlpha() bool

HasAlpha indicates that there is no alpha channel.

func (*GrayM) MaxValue Uses

func (p *GrayM) MaxValue() uint16

MaxValue returns the maximum grayscale value allowed.

func (*GrayM) Opaque Uses

func (p *GrayM) Opaque() bool

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

func (*GrayM) PixOffset Uses

func (p *GrayM) PixOffset(x, y int) int

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

func (*GrayM) PromoteToRGBM Uses

func (p *GrayM) PromoteToRGBM() *RGBM

PromoteToRGBM generates an 8-bit color image that looks identical to the given grayscale image.

func (*GrayM) Set Uses

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

Set sets the pixel at (x, y) to a given color, expressed as a color.Color.

func (*GrayM) SetGrayM Uses

func (p *GrayM) SetGrayM(x, y int, c npcolor.GrayM)

SetGrayM sets the pixel at (x, y) to a given color, expressed as an npcolor.GrayM.

func (*GrayM) SubImage Uses

func (p *GrayM) SubImage(r image.Rectangle) image.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 GrayM32 Uses

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 Uses

func NewGrayM32(r image.Rectangle, m uint16) *GrayM32

NewGrayM32 returns a new GrayM32 with the given bounds and maximum channel value.

func (*GrayM32) At Uses

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

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 Uses

func (p *GrayM32) Bounds() image.Rectangle

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 Uses

func (p *GrayM32) ColorModel() color.Model

ColorModel returns the GrayM32 image's color model.

func (*GrayM32) Format Uses

func (p *GrayM32) Format() Format

Format identifies the image as a PGM image.

func (*GrayM32) GrayM32At Uses

func (p *GrayM32) GrayM32At(x, y int) npcolor.GrayM32

GrayM32At returns the color of the pixel at (x, y) as an npcolor.GrayM32.

func (*GrayM32) HasAlpha Uses

func (p *GrayM32) HasAlpha() bool

HasAlpha indicates that there is no alpha channel.

func (*GrayM32) MaxValue Uses

func (p *GrayM32) MaxValue() uint16

MaxValue returns the maximum grayscale value allowed.

func (*GrayM32) Opaque Uses

func (p *GrayM32) Opaque() bool

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

func (*GrayM32) PixOffset Uses

func (p *GrayM32) PixOffset(x, y int) int

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

func (*GrayM32) PromoteToRGBM64 Uses

func (p *GrayM32) PromoteToRGBM64() *RGBM64

PromoteToRGBM64 generates a 16-bit color image that looks identical to the given grayscale image.

func (*GrayM32) Set Uses

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

Set sets the pixel at (x, y) to a given color, expressed as a color.Color.

func (*GrayM32) SetGrayM32 Uses

func (p *GrayM32) SetGrayM32(x, y int, c npcolor.GrayM32)

SetGrayM32 sets the pixel at (x, y) to a given color, expressed as an npcolor.GrayM32.

func (*GrayM32) SubImage Uses

func (p *GrayM32) SubImage(r image.Rectangle) image.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 Image Uses

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 Uses

func AddAlpha(img Image) (Image, bool)

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 Uses

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.

Code:

// 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 Uses

func DecodeWithComments(r io.Reader, opts *DecodeOptions) (Image, []string, error)

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 Uses

func RemoveAlpha(img Image) (Image, bool)

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 Uses

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 NewRGBAM Uses

func NewRGBAM(r image.Rectangle, m uint8) *RGBAM

NewRGBAM returns a new RGBAM with the given bounds and maximum channel value.

func (*RGBAM) At Uses

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

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 Uses

func (p *RGBAM) Bounds() image.Rectangle

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 Uses

func (p *RGBAM) ColorModel() color.Model

ColorModel returns the RGBAM image's color model.

func (*RGBAM) Format Uses

func (p *RGBAM) Format() Format

Format identifies the image as a PPM image.

func (*RGBAM) HasAlpha Uses

func (p *RGBAM) HasAlpha() bool

HasAlpha indicates that there is an alpha channel.

func (*RGBAM) MaxValue Uses

func (p *RGBAM) MaxValue() uint16

MaxValue returns the maximum value allowed on any color channel.

func (*RGBAM) Opaque Uses

func (p *RGBAM) Opaque() bool

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

func (*RGBAM) PixOffset Uses

func (p *RGBAM) PixOffset(x, y int) int

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

func (*RGBAM) RGBAMAt Uses

func (p *RGBAM) RGBAMAt(x, y int) npcolor.RGBAM

RGBAMAt returns the color of the pixel at (x, y) as an npcolor.RGBAM.

func (*RGBAM) Set Uses

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

Set sets the pixel at (x, y) to a given color, expressed as a color.Color.

func (*RGBAM) SetRGBAM Uses

func (p *RGBAM) SetRGBAM(x, y int, c npcolor.RGBAM)

SetRGBAM sets the pixel at (x, y) to a given color, expressed as an npcolor.RGBAM.

func (*RGBAM) SubImage Uses

func (p *RGBAM) SubImage(r image.Rectangle) image.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 RGBAM64 Uses

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 Uses

func NewRGBAM64(r image.Rectangle, m uint16) *RGBAM64

NewRGBAM64 returns a new RGBAM64 with the given bounds and maximum channel value.

func (*RGBAM64) At Uses

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

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 Uses

func (p *RGBAM64) Bounds() image.Rectangle

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 Uses

func (p *RGBAM64) ColorModel() color.Model

ColorModel returns the RGBAM64 image's color model.

func (*RGBAM64) Format Uses

func (p *RGBAM64) Format() Format

Format identifies the image as a PPM image.

func (*RGBAM64) HasAlpha Uses

func (p *RGBAM64) HasAlpha() bool

HasAlpha indicates that there is an alpha channel.

func (*RGBAM64) MaxValue Uses

func (p *RGBAM64) MaxValue() uint16

MaxValue returns the maximum value allowed on any color channel.

func (*RGBAM64) Opaque Uses

func (p *RGBAM64) Opaque() bool

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

func (*RGBAM64) PixOffset Uses

func (p *RGBAM64) PixOffset(x, y int) int

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

func (*RGBAM64) RGBAM64At Uses

func (p *RGBAM64) RGBAM64At(x, y int) npcolor.RGBAM64

RGBAM64At returns the color of the pixel at (x, y) as an npcolor.RGBAM64.

func (*RGBAM64) Set Uses

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

Set sets the pixel at (x, y) to a given color, expressed as a color.Color.

func (*RGBAM64) SetRGBAM64 Uses

func (p *RGBAM64) SetRGBAM64(x, y int, c npcolor.RGBAM64)

SetRGBAM64 sets the pixel at (x, y) to a given color, expressed as an npcolor.RGBAM64.

func (*RGBAM64) SubImage Uses

func (p *RGBAM64) SubImage(r image.Rectangle) image.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 RGBM Uses

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 NewRGBM Uses

func NewRGBM(r image.Rectangle, m uint8) *RGBM

NewRGBM returns a new RGBM with the given bounds and maximum channel value.

func (*RGBM) At Uses

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

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 Uses

func (p *RGBM) Bounds() image.Rectangle

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 Uses

func (p *RGBM) ColorModel() color.Model

ColorModel returns the RGBM image's color model.

func (*RGBM) Format Uses

func (p *RGBM) Format() Format

Format identifies the image as a PPM image.

func (*RGBM) HasAlpha Uses

func (p *RGBM) HasAlpha() bool

HasAlpha indicates that there is no alpha channel.

func (*RGBM) MaxValue Uses

func (p *RGBM) MaxValue() uint16

MaxValue returns the maximum value allowed on any color channel.

func (*RGBM) Opaque Uses

func (p *RGBM) Opaque() bool

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

func (*RGBM) PixOffset Uses

func (p *RGBM) PixOffset(x, y int) int

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

func (*RGBM) RGBMAt Uses

func (p *RGBM) RGBMAt(x, y int) npcolor.RGBM

RGBMAt returns the color of the pixel at (x, y) as an npcolor.RGBM.

func (*RGBM) Set Uses

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

Set sets the pixel at (x, y) to a given color, expressed as a color.Color.

func (*RGBM) SetRGBM Uses

func (p *RGBM) SetRGBM(x, y int, c npcolor.RGBM)

SetRGBM sets the pixel at (x, y) to a given color, expressed as an npcolor.RGBM.

func (*RGBM) SubImage Uses

func (p *RGBM) SubImage(r image.Rectangle) image.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 RGBM64 Uses

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 NewRGBM64 Uses

func NewRGBM64(r image.Rectangle, m uint16) *RGBM64

NewRGBM64 returns a new RGBM64 with the given bounds and maximum channel value.

func (*RGBM64) At Uses

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

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 Uses

func (p *RGBM64) Bounds() image.Rectangle

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 Uses

func (p *RGBM64) ColorModel() color.Model

ColorModel returns the RGBM64 image's color model.

func (*RGBM64) Format Uses

func (p *RGBM64) Format() Format

Format identifies the image as a PPM image.

func (*RGBM64) HasAlpha Uses

func (p *RGBM64) HasAlpha() bool

HasAlpha indicates that there is no alpha channel.

func (*RGBM64) MaxValue Uses

func (p *RGBM64) MaxValue() uint16

MaxValue returns the maximum value allowed on any color channel.

func (*RGBM64) Opaque Uses

func (p *RGBM64) Opaque() bool

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

func (*RGBM64) PixOffset Uses

func (p *RGBM64) PixOffset(x, y int) int

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

func (*RGBM64) RGBM64At Uses

func (p *RGBM64) RGBM64At(x, y int) npcolor.RGBM64

RGBM64At returns the color of the pixel at (x, y) as an npcolor.RGBM64.

func (*RGBM64) Set Uses

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

Set sets the pixel at (x, y) to a given color, expressed as a color.Color.

func (*RGBM64) SetRGBM64 Uses

func (p *RGBM64) SetRGBM64(x, y int, c npcolor.RGBM64)

SetRGBM64 sets the pixel at (x, y) to a given color, expressed as an npcolor.RGBM.

func (*RGBM64) SubImage Uses

func (p *RGBM64) SubImage(r image.Rectangle) image.Image

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

Directories

PathSynopsis
helpersThis program generates tests for multiple image formats.
npcolorPackage npcolor implements the color types and models used by Netpbm.

Package netpbm imports 10 packages (graph) and is imported by 2 packages. Updated 2020-01-18. Refresh now. Tools for package owners.