GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
Typedefs | Enumerations | Functions
gp_dither.gen.h File Reference

Dithering algorithms. More...

#include <filters/gp_filter.h>

Go to the source code of this file.

Typedefs

typedef enum gp_dither_type gp_dither_type
 Dithering types.
 

Enumerations

enum  gp_dither_type {
  GP_DITHER_FLOYD_STEINBERG , GP_DITHER_ATKINSON , GP_DITHER_SIERRA , GP_DITHER_SIERRA_LITE ,
  GP_DITHER_HILBERT_PEANO , GP_DITHER_MAX
}
 Dithering types. More...
 

Functions

gp_dither_type gp_dither_type_by_name (const char *dither_name)
 Returns dithering type by name.
 
const char * gp_dither_type_name (gp_dither_type dither_type)
 Returns dithering name for a given dithering type.
 
int gp_filter_dither (gp_dither_type type, const gp_pixmap *src, gp_pixmap *dst, gp_progress_cb *callback)
 Runs dithering from src->pixel_type to dst->pixel_type.
 
gp_pixmapgp_filter_dither_alloc (gp_dither_type type, const gp_pixmap *src, gp_pixel_type pixel_type, gp_progress_cb *callback)
 Allocates dst and runs dithering from src->pixel_type to pixel_type.
 
int gp_filter_floyd_steinberg (const gp_pixmap *src, gp_pixmap *dst, gp_progress_cb *callback)
 Runs floyd_steinberg dithering from src::pixel_type to dst::pixel_type.
 
static gp_pixmapgp_filter_floyd_steinberg_alloc (const gp_pixmap *src, gp_pixel_type pixel_type, gp_progress_cb *callback)
 Allocates dst and runs floyd_steinberg dithering from src->pixel_type to dst->pixel_type.
 
int gp_filter_atkinson (const gp_pixmap *src, gp_pixmap *dst, gp_progress_cb *callback)
 Runs atkinson dithering from src::pixel_type to dst::pixel_type.
 
static gp_pixmapgp_filter_atkinson_alloc (const gp_pixmap *src, gp_pixel_type pixel_type, gp_progress_cb *callback)
 Allocates dst and runs atkinson dithering from src->pixel_type to dst->pixel_type.
 
int gp_filter_sierra (const gp_pixmap *src, gp_pixmap *dst, gp_progress_cb *callback)
 Runs sierra dithering from src::pixel_type to dst::pixel_type.
 
static gp_pixmapgp_filter_sierra_alloc (const gp_pixmap *src, gp_pixel_type pixel_type, gp_progress_cb *callback)
 Allocates dst and runs sierra dithering from src->pixel_type to dst->pixel_type.
 
int gp_filter_sierra_lite (const gp_pixmap *src, gp_pixmap *dst, gp_progress_cb *callback)
 Runs sierra_lite dithering from src::pixel_type to dst::pixel_type.
 
static gp_pixmapgp_filter_sierra_lite_alloc (const gp_pixmap *src, gp_pixel_type pixel_type, gp_progress_cb *callback)
 Allocates dst and runs sierra_lite dithering from src->pixel_type to dst->pixel_type.
 
int gp_filter_hilbert_peano (const gp_pixmap *src, gp_pixmap *dst, gp_progress_cb *callback)
 Runs hilbert_peano dithering from src::pixel_type to dst::pixel_type.
 
static gp_pixmapgp_filter_hilbert_peano_alloc (const gp_pixmap *src, gp_pixel_type pixel_type, gp_progress_cb *callback)
 Allocates dst and runs hilbert_peano dithering from src->pixel_type to dst->pixel_type.
 

Detailed Description

Dithering algorithms.

Simple Conversion

Original Image RGB332 G8 G4 G2 G1

Floyd Steinberg Dithering

Original Image RGB332 G8 G4 G2 G1

Atkinson Dithering

Original Image RGB332 G8 G4 G2 G1

Sierra Dithering

Original Image RGB332 G8 G4 G2 G1

Sierra Lite Dithering

Original Image RGB332 G8 G4 G2 G1

Hilbert Peano Dithering

Original Image RGB332 G8 G4 G2 G1

Definition in file gp_dither.gen.h.

Enumeration Type Documentation

◆ gp_dither_type

Dithering types.

Enumerator
GP_DITHER_FLOYD_STEINBERG 

Classical Floyd-Steinberg.

Error distribution:

| | X | 7/16 |
|------|-------|-------|
| 3/16 | 5/16 | 1/16 |
GP_DITHER_ATKINSON 

Modified Atkinson dithering.

Distributes only 7/8 of the error, result has best contrast, but large areas may be "washed out" and the image tends to be darker.

I've found that the original Atkinson that distributes 6/8 of the error tends to be too dark and that distributing 7/8 works better.

Error distribution:

| | X | 1/8 | 1/8 |
|------|-------|-------|------|
| 1/8 | 1/8 | 1/8 | |
|------|-------|-------|------|
| 1/8 | 1/8 | | |
^
This is zero in the original Atkinson.
GP_DITHER_SIERRA 

A sierra dithering.

Sierra, produces shaper than Floyd-Steinberg, sometimes with less patterns. Generally preferable for small image sizes.

Error distribution:

| | | X | 5/32 | 3/32 |
|------|------|------|------|------|
| 2/32 | 4/32 | 5/32 | 4/32 | 2/32 |
|------|------|------|------|------|
| | 2/32 | 3/32 | 2/32 | |
GP_DITHER_SIERRA_LITE 

A sierra lite dithering.

Sierra Lite, comparable to Floyd-Steinberg, result is sometimes slightly sharper.

Error distribution:

| | X | 2/4 |
|-----|-----|-----|
| 1/4 | 1/4 | |
GP_DITHER_HILBERT_PEANO 

A hilbert-peano dithering.

Distributes error along Hilbert curve, produces no patterns on photos, but the end result is less sharp. Does not work well when large areas filed with the same color, since the hilbert curve end up being visible in the result.

GP_DITHER_MAX 

Number of dithering types.

Last valid types is GP_DITHER_MAX-1.

Definition at line 25 of file gp_dither.gen.h.

Function Documentation

◆ gp_dither_type_by_name()

gp_dither_type gp_dither_type_by_name ( const char *  dither_name)

Returns dithering type by name.

The lookup is not case sensitive and also works for two letter acronyms of the ditherings. The indended usage for two letter acronyms are shorter command line options, e.g. '-d at'.

Canonical name Acronym
Floyd Steinberg fs
Atkinson at
Sierra si
Sierra Lite sl
Hilbert Peano hp
Parameters
dither_nameA dithering name.
Returns
Dithering type or GP_DITHER_MAX on invalid name.

◆ gp_dither_type_name()

const char * gp_dither_type_name ( gp_dither_type  dither_type)

Returns dithering name for a given dithering type.

Parameters
dither_typeA dithering type id.
Returns
A canonical name for a dithering.

◆ gp_filter_atkinson()

int gp_filter_atkinson ( const gp_pixmap src,
gp_pixmap dst,
gp_progress_cb callback 
)

Runs atkinson dithering from src::pixel_type to dst::pixel_type.

Returns
Zero on success, non-zero on invalid type or aborted filter.

◆ gp_filter_atkinson_alloc()

static gp_pixmap * gp_filter_atkinson_alloc ( const gp_pixmap src,
gp_pixel_type  pixel_type,
gp_progress_cb callback 
)
inlinestatic

Allocates dst and runs atkinson dithering from src->pixel_type to dst->pixel_type.

Returns
Newly allocated pixmap on success, NULL on invalid type or aborted filter.

Definition at line 189 of file gp_dither.gen.h.

References GP_DITHER_ATKINSON, and gp_filter_dither_alloc().

◆ gp_filter_dither()

int gp_filter_dither ( gp_dither_type  type,
const gp_pixmap src,
gp_pixmap dst,
gp_progress_cb callback 
)

Runs dithering from src->pixel_type to dst->pixel_type.

Returns
Zero on success, non-zero on invalid type or aborted filter.

◆ gp_filter_dither_alloc()

gp_pixmap * gp_filter_dither_alloc ( gp_dither_type  type,
const gp_pixmap src,
gp_pixel_type  pixel_type,
gp_progress_cb callback 
)

Allocates dst and runs dithering from src->pixel_type to pixel_type.

Returns
Newly allocated pixmap on success, NULL on invalid type or aborted filter.

Referenced by gp_filter_atkinson_alloc(), gp_filter_floyd_steinberg_alloc(), gp_filter_hilbert_peano_alloc(), gp_filter_sierra_alloc(), and gp_filter_sierra_lite_alloc().

◆ gp_filter_floyd_steinberg()

int gp_filter_floyd_steinberg ( const gp_pixmap src,
gp_pixmap dst,
gp_progress_cb callback 
)

Runs floyd_steinberg dithering from src::pixel_type to dst::pixel_type.

Returns
Zero on success, non-zero on invalid type or aborted filter.

◆ gp_filter_floyd_steinberg_alloc()

static gp_pixmap * gp_filter_floyd_steinberg_alloc ( const gp_pixmap src,
gp_pixel_type  pixel_type,
gp_progress_cb callback 
)
inlinestatic

Allocates dst and runs floyd_steinberg dithering from src->pixel_type to dst->pixel_type.

Returns
Newly allocated pixmap on success, NULL on invalid type or aborted filter.

Definition at line 168 of file gp_dither.gen.h.

References GP_DITHER_FLOYD_STEINBERG, and gp_filter_dither_alloc().

◆ gp_filter_hilbert_peano()

int gp_filter_hilbert_peano ( const gp_pixmap src,
gp_pixmap dst,
gp_progress_cb callback 
)

Runs hilbert_peano dithering from src::pixel_type to dst::pixel_type.

Returns
Zero on success, non-zero on invalid type or aborted filter.

◆ gp_filter_hilbert_peano_alloc()

static gp_pixmap * gp_filter_hilbert_peano_alloc ( const gp_pixmap src,
gp_pixel_type  pixel_type,
gp_progress_cb callback 
)
inlinestatic

Allocates dst and runs hilbert_peano dithering from src->pixel_type to dst->pixel_type.

Returns
Newly allocated pixmap on success, NULL on invalid type or aborted filter.

Definition at line 252 of file gp_dither.gen.h.

References GP_DITHER_HILBERT_PEANO, and gp_filter_dither_alloc().

◆ gp_filter_sierra()

int gp_filter_sierra ( const gp_pixmap src,
gp_pixmap dst,
gp_progress_cb callback 
)

Runs sierra dithering from src::pixel_type to dst::pixel_type.

Returns
Zero on success, non-zero on invalid type or aborted filter.

◆ gp_filter_sierra_alloc()

static gp_pixmap * gp_filter_sierra_alloc ( const gp_pixmap src,
gp_pixel_type  pixel_type,
gp_progress_cb callback 
)
inlinestatic

Allocates dst and runs sierra dithering from src->pixel_type to dst->pixel_type.

Returns
Newly allocated pixmap on success, NULL on invalid type or aborted filter.

Definition at line 210 of file gp_dither.gen.h.

References GP_DITHER_SIERRA, and gp_filter_dither_alloc().

◆ gp_filter_sierra_lite()

int gp_filter_sierra_lite ( const gp_pixmap src,
gp_pixmap dst,
gp_progress_cb callback 
)

Runs sierra_lite dithering from src::pixel_type to dst::pixel_type.

Returns
Zero on success, non-zero on invalid type or aborted filter.

◆ gp_filter_sierra_lite_alloc()

static gp_pixmap * gp_filter_sierra_lite_alloc ( const gp_pixmap src,
gp_pixel_type  pixel_type,
gp_progress_cb callback 
)
inlinestatic

Allocates dst and runs sierra_lite dithering from src->pixel_type to dst->pixel_type.

Returns
Newly allocated pixmap on success, NULL on invalid type or aborted filter.

Definition at line 231 of file gp_dither.gen.h.

References GP_DITHER_SIERRA_LITE, and gp_filter_dither_alloc().