Skip to content

Latest commit

 

History

History
112 lines (68 loc) · 3.02 KB

dither.pod

File metadata and controls

112 lines (68 loc) · 3.02 KB

NAME

dither -- reduce number of colors in an image with dithering

SYNOPSIS

dither [-dv] [-p name[.size]] input output

DESCRIPTION

dither processes image files in PNG or binary PPM format with the goal of reducing its number of colors. Functionality includes generating a palette of colors automatically and writing the output image with the signal optionally dithered (Floyd-Steinberg method).

Arguments for the input and output file are both required.

The palette used in the operation can be generated from different presets and sizes, or be completely customized. Details about palette generation are described below in the corresponding section.

The input file format is deduced by analysing the image header. The output file format is decided according to its extension. Use a .png extension to have output written as a PNG file. Any other extension will result in a binary PPM file.

Options

Accepted options are:

-v

Verbose mode: the program will write the palette used to stdout. Useful to capture a palette generated by the program.

-p name[.size]

Palette generation method. Size must be an integer greater than 0 and is optional in some cases. Check the section on palettes below to learn more.

-d

Disables dithering. Final image will have pixels matched to the closest palette color only.

Palette Generation

These are the possible palettes and their descriptions, according to the identifier. If no palette is set the program will use rgb by default.

auto

Automatically generate a palette of colors from the input image, using a median-cut algorithm. Size is required and must be a power of 2.

custom

Custom palette, given by the user and read from stdin. Size is required. The palette format must be a sequence of triplets, integers in the range [0-255] separated by whitespace. Example:

0 0 0
12 150 255
255 255 255
rgb

Standard 8 colors RGB, equivalent to 3-bit RGB. Size is not required and will be ignored if set.

bw

Black and white palette. Size is optional and will default to 2. When size is greater than 2, a grayscale palette with size number of colors will be generated.

EXAMPLES

Apply dithering to an image, using a 3-bit RGB palette:

$ dither input.ppm output.ppm

Apply dithering to an image, using a 4 tone grayscale palette:

$ dither -p bw.4 input.ppm output.ppm

Apply dithering to an image, using an automatically generated palette of 8 colors, dumping the palette to a file named palette.txt:

$ dither -vp auto.8 input.ppm output.ppm > palette.txt

Only generate a palette of colors of size 16, printing it to stdout without saving the final image:

$ dither -vp auto.16 input.ppm /dev/null

ACKNOWLEDGEMENTS

Thank you Robert W. Floyd, Louis Steinberg and Paul Heckbert for your work and development of these algorithms.

AUTHORS

This software and manual were written by Cesar Tessarin on August 2017.