rowenc

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package rowenc writes PNG and TIFF files from the rows of an image as they come, for an image drawn in bands (imagebdf.PageRows) that is not all in memory at once: a page at 600 dpi is written with the memory of a band of it and of the compression.

A Writer is made for an image of a width, height and Kind, takes the rows in order with WriteRows, and is closed. The files decode (with image/png and a TIFF reader) to the pixels given: the PNG of an RGBA image is written as image/png writes an *image.RGBA, in colour type RGBA with the alpha unmultiplied, whether or not the image is opaque, since the rows to come are not known.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(w io.Writer, format string, img image.Image, kind Kind, opts *Options) error

Encode writes a whole image in a format (see New): the image is the rows.

Types

type Kind

type Kind int

Kind is the pixels of an image written.

const (
	// RGBA is 8 bits a channel with premultiplied alpha, as *image.RGBA
	// holds them: the PNG is of colour type RGBA (the alpha unmultiplied,
	// as image/png writes it), the TIFF of RGB with an associated alpha
	// sample.
	RGBA Kind = iota
	// Gray is 8 bits a pixel, as *image.Gray.
	Gray
	// Bilevel is a bit a pixel, black and white: the rows are an
	// *image.Paletted of two colours, black first (as imagebdf.Bilevel
	// draws them), or an *image.Gray whose values below 128 are black.
	// The PNG is of a palette of the two colours at a bit a pixel, the
	// TIFF of a bit a pixel with 0 black (min-is-black).
	Bilevel
)

func KindOf

func KindOf(img image.Image) Kind

KindOf returns the Kind of an image the renderer draws (see imagebdf.Mono): an *image.Gray is Gray, an *image.Paletted of black and white is Bilevel, the rest RGBA (converted when they are not an *image.RGBA).

type Options

type Options struct {
	// Level is the zlib compression level of a PNG, from 1 (fastest) to
	// 9 (smallest), as compress/flate numbers them; 0 is the default
	// level (6). A TIFF is not compressed.
	Level int
	// DPI is the resolution noted in the file: the pHYs chunk of a PNG
	// and the resolution tags of a TIFF. Zero notes none in a PNG and 72
	// in a TIFF.
	DPI float64
	// Threads is how many goroutines filter and compress the rows of a
	// PNG, in chunks of rows: zero uses those of the machine, up to
	// eight. The file is the same whatever the number.
	Threads int
}

Options configures a Writer.

type PNG

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

PNG writes a PNG file from the rows of an image (see Writer).

The rows are filtered and compressed in chunks of a fixed number of rows, each by a goroutine (see Options.Threads): the deflate stream of the image is the streams of the chunks one after the other, each ended with a sync flush, so the file is the same however the rows come and however many goroutines write it.

func NewPNG

func NewPNG(w io.Writer, width, height int, kind Kind, opts *Options) (*PNG, error)

NewPNG returns a writer of a PNG file of width × height pixels of a kind to w (see Options).

func (*PNG) Close

func (p *PNG) Close() error

Close ends the image (see Writer).

func (*PNG) WriteRows

func (p *PNG) WriteRows(rows image.Image) error

WriteRows writes the next rows (see Writer).

type TIFF

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

TIFF writes a TIFF file from the rows of an image (see Writer): not compressed, in one strip, with the directory before the pixels, so that the file is written in order without seeking. The pixels are 8 bits a sample (RGB with an associated alpha sample for RGBA, gray), or a bit a pixel with 0 black for Bilevel.

func NewTIFF

func NewTIFF(w io.Writer, width, height int, kind Kind, opts *Options) (*TIFF, error)

NewTIFF returns a writer of a TIFF file of width × height pixels of a kind to w (see Options; the compression level does not apply).

func (*TIFF) Close

func (t *TIFF) Close() error

Close ends the image (see Writer): nothing follows the pixels.

func (*TIFF) WriteRows

func (t *TIFF) WriteRows(rows image.Image) error

WriteRows writes the next rows (see Writer).

type Writer

type Writer interface {
	// WriteRows writes the next rows: an image as wide as the one
	// written, of the kind of the writer (see Kind), whose rows follow
	// those written before. Its bounds may start anywhere.
	WriteRows(rows image.Image) error
	// Close writes what ends the file and reports an error if the rows
	// written are not all of the image.
	Close() error
}

Writer writes an image from its rows, from the top.

func New

func New(w io.Writer, format string, width, height int, kind Kind, opts *Options) (Writer, error)

New returns a writer of the format: "png" or "tiff".

Jump to

Keyboard shortcuts

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