Navigation C API Pages Python bindings Applications

Dithering

Currently there are two dithering algorithms implemented. Both takes an RGB888 24bit image as input and are able to produce any RGB or Grayscale image. This filters doesn’t work in-place as the result has different pixel type.

Floyd-Steinberg

Classical Floyd-Steinberg. Produces good results and is a little faster than the Hilbert-Peano dithering.

The error is distributed to neighbor pixels as follows:

X

7/16

3/16

5/16

1/16

And is throwed away at the image borders.

#include <GP.h>
/* or */
#include <filters/GP_Dither.h>

int GP_FilterFloydSteinberg(const GP_Context *src, GP_Context *dst,
                            GP_ProgressCallback *callback);

Renders Floyd Steinberg dithering directly into passed context. The destination must be at least as large as source.

If operation was aborted by a callback, non-zero is returned.

Not all pixel types all supported. If particular combination is not supported the function returns non-zero and sets errno to ENOSYS.

#include <GP.h>
/* or */
#include <filters/GP_Dither.h>

GP_Context *GP_FilterFloydSteinbergAlloc(const GP_Context *src,
                                         GP_PixelType pixel_type,
                                         GP_ProgressCallback *callback);

Returns pointer to allocated context of given pixel_type.

If malloc(2) has failed, or operation was aborted by a callback NULL is returned.

Not all pixel types all supported. If particular combination is not supported the function returns NULL and sets errno to ENOSYS.

Hilbert-Peano

Hilbert-Peano space filling curve based dithering.

The error value is distributed around the Hilbert curve.

The result is a little more noisy, but doesn’t create repeating patterns like Floyd-Steinberg which looks generally better to human eye. On the other hand edges tend to be less sharp.

#include <GP.h>
/* or */
#include <filters/GP_Dither.h>

int GP_FilterHilbertPeano(const GP_Context *src, GP_Context *dst,
                          GP_ProgressCallback *callback);

Renders Hilbert Peano dithering directly into passed context. The destination must be at least as large as source.

If operation was aborted by a callback, non-zero is returned.

Not all pixel types all supported. If particular combination is not supported the function returns NULL and sets errno to ENOSYS.

#include <GP.h>
/* or */
#include <filters/GP_Dither.h>

GP_Context *GP_FilterHilbertPeanoAlloc(const GP_Context *src,
                                       GP_PixelType pixel_type,
                                       GP_ProgressCallback *callback);

Returns pointer to allocated context of given pixel_type.

If malloc(2) has failed, or operation was aborted by a callback NULL is returned.

Not all pixel types all supported. If particular combination is not supported the function returns NULL and sets errno to ENOSYS.

Original Image; Simple Conversion: RGB332, G8, G4, G2, G1

Original Image RGB332 G8 G4 G2 G1

Original Image; Floyd Steinberg Dithering: RGB332, G8, G4, G2, G1

Original Image RGB332 G8 G4 G2 G1

Original Image; Hilbert Peano Dithering: RGB332, G8, G4, G2, G1

Original Image RGB332 G8 G4 G2 G1