png

package module
v0.0.0-...-2266efc Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2022 License: BSD-3-Clause Imports: 11 Imported by: 0

README

PNG image library Go Reference

Documentation

Overview

Package png implements a PNG image decoder and encoder. It is a fork of the standard library's png package, but with a focus on memory usage and speed on image.NRGBA images.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompressionLevel

type CompressionLevel int

CompressionLevel indicates the compression level.

const (
	DefaultCompression CompressionLevel = 0
	NoCompression      CompressionLevel = -1
	BestSpeed          CompressionLevel = -2
	BestCompression    CompressionLevel = -3
)

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

A Decoder is a row-by-row decoder for png image.NRGBA images. Compared to the standard library, it reduces memory usage by loading only the current row.

func NewDecoder

func NewDecoder(r io.Reader) (*Decoder, error)

NewDecoder decodes the metadata of an image data stream.

func (*Decoder) Bounds

func (d *Decoder) Bounds() image.Rectangle

Bounds returns the bounds of the decoded image.

func (*Decoder) Close

func (d *Decoder) Close() error

Close checks the validity of the decoded image stream at the end.

func (*Decoder) DecodeRow

func (d *Decoder) DecodeRow() ([]byte, error)

DecodeRow decodes the current row. Users must take care of not modifying the returned buffer, as it is used in the decoding of subsequent rows.

type Encoder

type Encoder struct {
	CompressionLevel CompressionLevel

	// BufferPool optionally specifies a buffer pool to get temporary
	// EncoderBuffers when encoding an image.
	BufferPool EncoderBufferPool
}

Encoder configures encoding PNG images.

func NewEncoder

func NewEncoder(level CompressionLevel) *Encoder

NewEncoder returns a png image encoder. It supports only image.NRGBA images. It is roughly 5x (10x for identical RGBA images) faster than the standard library, according to the profiling results in https://github.com/golang/go/issues/51982#issuecomment-1085538951

func (*Encoder) Encode

func (enc *Encoder) Encode(w io.Writer, m *image.NRGBA) error

Encode writes the Image m to w in PNG format.

type EncoderBuffer

type EncoderBuffer encoder

EncoderBuffer holds the buffers used for encoding PNG images.

type EncoderBufferPool

type EncoderBufferPool interface {
	Get() *EncoderBuffer
	Put(*EncoderBuffer)
}

EncoderBufferPool is an interface for getting and returning temporary instances of the EncoderBuffer struct. This can be used to reuse buffers when encoding multiple images.

type FormatError

type FormatError string

A FormatError reports that the input is not a valid PNG.

func (FormatError) Error

func (e FormatError) Error() string

type UnsupportedError

type UnsupportedError string

An UnsupportedError reports that the input uses a valid but unimplemented PNG feature.

func (UnsupportedError) Error

func (e UnsupportedError) Error() string

Jump to

Keyboard shortcuts

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