pnm

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: BSD-2-Clause Imports: 7 Imported by: 0

README

Package pnm

Build Status GoDoc

Package pnm implements a PBM, PGM and PPM image decoder and encoder.

This package is compatible with Go version 1.

Installation

	go install github.com/UNO-SOFT/gopnm

Limitations

Not implemented are:

  • Writing pnm files in raw format.
  • Writing images with 16 bits per channel.
  • Writing images with a custom Maxvalue.
  • Reading/and writing PAM images.

(I would be happy to accept patches for these.)

Documentation

Overview

Package pnm implements a PBM, PGM and PPM image decoder and encoder.

The decoder can read files in both plain and raw format with 8 or 16 bits per channel. The encoder can only write files in plain format with 8 bits per channel.

To only be able to load pnm images using image.Decode, use

import _ "github.com/UNO-SOFT/gopnm"

Not implemented are:

  • Writing pnm files in raw format.
  • Reading/and writing PAM images.

(I would be happy to accept patches for these.)

Specifications can be found at http://netpbm.sourceforge.net/doc/#formats.

Index

Constants

View Source
const (
	PBM int = 0
	PGM int = 1
	PPM int = 2
)

Variables

This section is empty.

Functions

func Decode

func Decode(r io.Reader) (image.Image, error)

Decode reads a PNM image from r and returns it as an image.Image.

The type of Image returned depends on the PNM contents:

  • PBM: image.Gray with black = 0 and white = 255
  • PGM: image.Gray or image.Gray16, values as in the file
  • PPM: image.RGBA or image.RGBA64, values as in the file
  • PAM: not supported (yet)

func DecodeConfig

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

DecodeConfig returns the color model and dimensions of a PNM image without decoding the entire image.

func Encode

func Encode(w io.Writer, m image.Image, pnmType int) error

Encode writes an image.Image m to io.Writer w in PNM format.

The specific format is determined by pnmType, this can be one of:

  • pnm.PBM (black/white)
  • pnm.PGM (grayscale)
  • pnm.PPM (RGB)

The image m is converted if necessary.

Types

type PNMConfig

type PNMConfig struct {
	Width  int
	Height int
	Maxval int
	// contains filtered or unexported fields
}

func DecodeConfigPNM

func DecodeConfigPNM(r *bufio.Reader) (c PNMConfig, err error)

DecodeConfigPNM reads and returns header data of PNM files.

This may be useful to obtain the actual file type and for files that have a Maxval other than the maximum supported Maxval. To apply gamma correction this value is needed. Note that gamma correction is not performed by the decoder.

Jump to

Keyboard shortcuts

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