netpbm

package module
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2024 License: BSD-3-Clause Imports: 10 Imported by: 12

README

netpbm

GitHub Actions Go Report Card Go Reference

Introduction

netpbm is a package for the Go programming language that implements image decoders and encoders for the Netpbm image formats. The package supports all of the following:

  • All of the Netpbm image formats:

    • PBM (portable bitmap): black and white only
    • PGM (portable graymap): grayscale
    • PPM (portable pixmap): color
    • PAM (portable arbitrary map): alpha
  • Both "raw" (binary) and "plain" (ASCII) files

  • Both 8-bit and 16-bit color channels

  • Any maximum per-color-channel value (up to what the given number of bits can represent)

  • Full compatibility with Go's image package

    • Implements the image.Image interface
    • Additionally defines Opaque, PixOffset, Set, and Subimage methods (and color-model-specific variants of At and Set), like most of Go's standard image types
  • Automatic promotion of image formats, if desired

That last feature means that 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.

Installation

netpbm is a Go module so it can be installed by running

go get github.com/spakin/netpbm

on the command line.

Usage

netpbm works just like the standard image/gif, image/jpeg, and image/png packages in that

import (
    _ "github.com/spakin/netpbm"
)

will enable image.Decode to import Netpbm image formats.

Various package-specific functions, types, interfaces, and methods are available only with a normal (not "_") import. A normal import is needed both to export Netpbm images and to exert more precise control over the Netpbm variants that are allowed to be imported. See the netpbm API documentation for details.

Author

Scott Pakin, scott-npbm@pakin.org

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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeConfig

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 added in v1.1.0

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

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.

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

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

func NewBW(r image.Rectangle) *BW

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

func (*BW) Format

func (p *BW) Format() Format

Format identifies the image as a PBM image.

func (*BW) HasAlpha added in v1.2.0

func (p *BW) HasAlpha() bool

HasAlpha indicates that there is no alpha channel.

func (*BW) MaxValue

func (p *BW) MaxValue() uint16

MaxValue returns the maximum index value allowed.

func (*BW) PromoteToGrayM

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

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

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.

func (Format) String

func (f Format) String() string

String outputs the name of a 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

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

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

func (*GrayAM) At added in v1.2.0

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 added in v1.2.0

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 added in v1.2.0

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

ColorModel returns the GrayAM image's color model.

func (*GrayAM) Format added in v1.2.0

func (p *GrayAM) Format() Format

Format identifies the image as a PGM image.

func (*GrayAM) GrayAMAt added in v1.2.0

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 added in v1.2.0

func (p *GrayAM) HasAlpha() bool

HasAlpha indicates that there is an alpha channel.

func (*GrayAM) MaxValue added in v1.2.0

func (p *GrayAM) MaxValue() uint16

MaxValue returns the maximum value allowed on any color channel.

func (*GrayAM) Opaque added in v1.2.0

func (p *GrayAM) Opaque() bool

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

func (*GrayAM) PixOffset added in v1.2.0

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 added in v1.2.0

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 added in v1.2.0

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 added in v1.2.0

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

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

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

func (*GrayAM48) At added in v1.2.0

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 added in v1.2.0

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 added in v1.2.0

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

ColorModel returns the GrayAM48 image's color model.

func (*GrayAM48) Format added in v1.2.0

func (p *GrayAM48) Format() Format

Format identifies the image as a PGM image.

func (*GrayAM48) GrayAM48At added in v1.2.0

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 added in v1.2.0

func (p *GrayAM48) HasAlpha() bool

HasAlpha indicates that there is an alpha channel.

func (*GrayAM48) MaxValue added in v1.2.0

func (p *GrayAM48) MaxValue() uint16

MaxValue returns the maximum value allowed on any color channel.

func (*GrayAM48) Opaque added in v1.2.0

func (p *GrayAM48) Opaque() bool

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

func (*GrayAM48) PixOffset added in v1.2.0

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 added in v1.2.0

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 added in v1.2.0

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 added in v1.2.0

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

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

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

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

func (*GrayM) At

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

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

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

ColorModel returns the GrayM image's color model.

func (*GrayM) Format

func (p *GrayM) Format() Format

Format identifies the image as a PGM image.

func (*GrayM) GrayMAt

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 added in v1.2.0

func (p *GrayM) HasAlpha() bool

HasAlpha indicates that there is no alpha channel.

func (*GrayM) MaxValue

func (p *GrayM) MaxValue() uint16

MaxValue returns the maximum grayscale value allowed.

func (*GrayM) Opaque

func (p *GrayM) Opaque() bool

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

func (*GrayM) PixOffset

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

func (p *GrayM) PromoteToRGBM() *RGBM

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

func (*GrayM) Set

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

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

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

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

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

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

func (*GrayM32) At

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

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

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

ColorModel returns the GrayM32 image's color model.

func (*GrayM32) Format

func (p *GrayM32) Format() Format

Format identifies the image as a PGM image.

func (*GrayM32) GrayM32At

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 added in v1.2.0

func (p *GrayM32) HasAlpha() bool

HasAlpha indicates that there is no alpha channel.

func (*GrayM32) MaxValue

func (p *GrayM32) MaxValue() uint16

MaxValue returns the maximum grayscale value allowed.

func (*GrayM32) Opaque

func (p *GrayM32) Opaque() bool

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

func (*GrayM32) PixOffset

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

func (p *GrayM32) PromoteToRGBM64() *RGBM64

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

func (*GrayM32) Set

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

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

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

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

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

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

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 added in v1.2.0

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

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

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

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

func (*RGBAM) At

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

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

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

ColorModel returns the RGBAM image's color model.

func (*RGBAM) Format

func (p *RGBAM) Format() Format

Format identifies the image as a PPM image.

func (*RGBAM) HasAlpha added in v1.2.0

func (p *RGBAM) HasAlpha() bool

HasAlpha indicates that there is an alpha channel.

func (*RGBAM) MaxValue

func (p *RGBAM) MaxValue() uint16

MaxValue returns the maximum value allowed on any color channel.

func (*RGBAM) Opaque

func (p *RGBAM) Opaque() bool

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

func (*RGBAM) PixOffset

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

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

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

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

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

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

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

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

func (*RGBAM64) At

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

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

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

ColorModel returns the RGBAM64 image's color model.

func (*RGBAM64) Format

func (p *RGBAM64) Format() Format

Format identifies the image as a PPM image.

func (*RGBAM64) HasAlpha added in v1.2.0

func (p *RGBAM64) HasAlpha() bool

HasAlpha indicates that there is an alpha channel.

func (*RGBAM64) MaxValue

func (p *RGBAM64) MaxValue() uint16

MaxValue returns the maximum value allowed on any color channel.

func (*RGBAM64) Opaque

func (p *RGBAM64) Opaque() bool

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

func (*RGBAM64) PixOffset

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

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

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

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

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

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

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

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

func (*RGBM) At

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

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

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

ColorModel returns the RGBM image's color model.

func (*RGBM) Format

func (p *RGBM) Format() Format

Format identifies the image as a PPM image.

func (*RGBM) HasAlpha added in v1.2.0

func (p *RGBM) HasAlpha() bool

HasAlpha indicates that there is no alpha channel.

func (*RGBM) MaxValue

func (p *RGBM) MaxValue() uint16

MaxValue returns the maximum value allowed on any color channel.

func (*RGBM) Opaque

func (p *RGBM) Opaque() bool

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

func (*RGBM) PixOffset

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

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

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

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

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

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

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

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

func (*RGBM64) At

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

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

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

ColorModel returns the RGBM64 image's color model.

func (*RGBM64) Format

func (p *RGBM64) Format() Format

Format identifies the image as a PPM image.

func (*RGBM64) HasAlpha added in v1.2.0

func (p *RGBM64) HasAlpha() bool

HasAlpha indicates that there is no alpha channel.

func (*RGBM64) MaxValue

func (p *RGBM64) MaxValue() uint16

MaxValue returns the maximum value allowed on any color channel.

func (*RGBM64) Opaque

func (p *RGBM64) Opaque() bool

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

func (*RGBM64) PixOffset

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

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

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

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

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

Path Synopsis
This program generates tests for multiple image formats.
This program generates tests for multiple image formats.
Package npcolor implements the color types and models used by Netpbm.
Package npcolor implements the color types and models used by Netpbm.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL