caca_dither(3caca)
π caca_dither β libcaca bitmap dithering π
okay bestie, this one lives in libcaca (yes, the 3caca manual, part 1 of our little saga π) and it's literally the whole dithering situation β creating dither objects, tweaking how they look, and painting bitmaps onto a canvas. no cap, this page is stacked. let's get into it β¨
πΈ NAME πΈ
caca_dither β libcaca bitmap dithering
like, the entire high-level dithering API. this is the moment. π
β¨ SYNOPSIS β¨
π¦ Topics π¦
- libcaca character font handling
π Functions π
__extern caca_dither_t * caca_create_dither (int, int, int, int, uint32_t, uint32_t, uint32_t, uint32_t)β Create an internal dither object.__extern int caca_set_dither_palette (caca_dither_t *, uint32_t r[], uint32_t g[], uint32_t b[], uint32_t a[])β Set the palette of an 8bpp dither object.__extern int caca_set_dither_brightness (caca_dither_t *, float)β Set the brightness of a dither object.__extern float caca_get_dither_brightness (caca_dither_t const *)β Get the brightness of a dither object.__extern int caca_set_dither_gamma (caca_dither_t *, float)β Set the gamma of a dither object.__extern float caca_get_dither_gamma (caca_dither_t const *)β Get the gamma of a dither object.__extern int caca_set_dither_contrast (caca_dither_t *, float)β Set the contrast of a dither object.__extern float caca_get_dither_contrast (caca_dither_t const *)β Get the contrast of a dither object.__extern int caca_set_dither_antialias (caca_dither_t *, char const *)β Set dither antialiasing.__extern char const *const * caca_get_dither_antialias_list (caca_dither_t const *)β Get available antialiasing methods.__extern char const * caca_get_dither_antialias (caca_dither_t const *)β Get current antialiasing method.__extern int caca_set_dither_color (caca_dither_t *, char const *)β Choose colours used for dithering.__extern char const *const * caca_get_dither_color_list (caca_dither_t const *)β Get available colour modes.__extern char const * caca_get_dither_color (caca_dither_t const *)β Get current colour mode.__extern int caca_set_dither_charset (caca_dither_t *, char const *)β Choose characters used for dithering.__extern char const *const * caca_get_dither_charset_list (caca_dither_t const *)β Get available dither character sets.__extern char const * caca_get_dither_charset (caca_dither_t const *)β Get current character set.__extern int caca_set_dither_algorithm (caca_dither_t *, char const *)β Set dithering algorithm.__extern char const *const * caca_get_dither_algorithm_list (caca_dither_t const *)β Get dithering algorithms.__extern char const * caca_get_dither_algorithm (caca_dither_t const *)β Get current dithering algorithm.__extern int caca_dither_bitmap (caca_canvas_t *, int, int, int, int, caca_dither_t const *, void const *)β Dither a bitmap on the canvas.__extern int caca_free_dither (caca_dither_t *)β Free the memory associated with a dither.
π Detailed Description π
these functions are the high level routines for dither allocation and rendering. allocation, rendering, the whole glow-up. π«Ά
π Function Documentation π
β __extern caca_dither_t * caca_create_dither (int bpp, int w, int h, int pitch, uint32_t rmask, uint32_t gmask, uint32_t bmask, uint32_t amask) β
Create a dither structure from its coordinates β that's depth, width, height and pitch β plus the pixel mask values. iconic little constructor fr fr.
if the depth is 8 bits per pixel, the mask values are literally ignored and you should set the colour palette with the caca_set_dither_palette() function instead. for depths greater than 8 bits per pixel, a zero alpha mask causes the alpha values to be ignored. noted. π
if an error occurs, NULL is returned and errno is set accordingly:
EINVALβ Requested width, height, pitch or bits per pixel value was invalid.ENOMEMβ Not enough memory to allocate dither structure.
Parameters
bppβ Bitmap depth in bits per pixel.wβ Bitmap width in pixels.hβ Bitmap height in pixels.pitchβ Bitmap pitch in bytes.rmaskβ Bitmask for red values.gmaskβ Bitmask for green values.bmaskβ Bitmask for blue values.amaskβ Bitmask for alpha values.
Returns
Dither object upon success, NULL if an error occurred.
β __extern int caca_set_dither_palette (caca_dither_t * d, uint32_t red[], uint32_t green[], uint32_t blue[], uint32_t alpha[]) β
Set the palette of an 8 bits per pixel bitmap. values should be between 0 and 4095 (0xfff). yes, that's the range, don't come at me. π
if an error occurs, -1 is returned and errno is set accordingly:
EINVALβ Dither bits per pixel value is not 8, or one of the pixel values was outside the range 0 - 4095.
Parameters
dβ Dither object.redβ Array of 256 red values.greenβ Array of 256 green values.blueβ Array of 256 blue values.alphaβ Array of 256 alpha values.
Returns
0 in case of success, -1 if an error occurred.
β __extern int caca_set_dither_brightness (caca_dither_t * d, float brightness) β
Set the brightness of dither. glow up time β¨
if an error occurs, -1 is returned and errno is set accordingly:
EINVALβ Brightness value was out of range.
Parameters
dβ Dither object.brightnessβ brightness value.
Returns
0 in case of success, -1 if an error occurred.
β __extern float caca_get_dither_brightness (caca_dither_t const * d) β
Get the brightness of the given dither object.
this function never fails. ever. it's giving reliable main character energy. π
Parameters
dβ Dither object.
Returns
Brightness value.
β __extern int caca_set_dither_gamma (caca_dither_t * d, float gamma) β
Set the gamma of the given dither object. heads up: a negative value causes colour inversion. lowkey dramatic but okay π
if an error occurs, -1 is returned and errno is set accordingly:
EINVALβ Gamma value was out of range.
Parameters
dβ Dither object.gammaβ Gamma value.
Returns
0 in case of success, -1 if an error occurred.
β __extern float caca_get_dither_gamma (caca_dither_t const * d) β
Get the gamma of the given dither object.
this function never fails. periodt. π
Parameters
dβ Dither object.
Returns
Gamma value.
β __extern int caca_set_dither_contrast (caca_dither_t * d, float contrast) β
Set the contrast of dither.
if an error occurs, -1 is returned and errno is set accordingly:
EINVALβ Contrast value was out of range.
Parameters
dβ Dither object.contrastβ contrast value.
Returns
0 in case of success, -1 if an error occurred.
β __extern float caca_get_dither_contrast (caca_dither_t const * d) β
Get the contrast of the given dither object.
this function never fails, bestie. never. π«Ά
Parameters
dβ Dither object.
Returns
Contrast value.
β __extern int caca_set_dither_antialias (caca_dither_t * d, char const * str) β
Tell the renderer whether to antialias the dither. antialiasing smoothens the rendered image and avoids the commonly seen staircase effect. yes, the crunchy pixel stairs. we're fixing those. πͺ
"none"β no antialiasing."prefilter"or"default"β simple prefilter antialiasing. This is the default value.
if an error occurs, -1 is returned and errno is set accordingly:
EINVALβ Invalid antialiasing mode.
Parameters
dβ Dither object.strβ A string describing the antialiasing method that will be used for the dithering.
Returns
0 in case of success, -1 if an error occurred.
β __extern char const *const * caca_get_dither_antialias_list (caca_dither_t const * d) β
Return a list of available antialiasing methods for a given dither. the list is a NULL-terminated array of strings, interleaving a string containing the internal value for the antialiasing method to be used with caca_set_dither_antialias(), and a string containing the natural language description for that antialiasing method. so it's like a little menu, internal value then human-readable description, back and forth. π
this function never fails.
Parameters
dβ Dither object.
Returns
An array of strings.
β __extern char const * caca_get_dither_antialias (caca_dither_t const * d) β
Return the given dither's current antialiasing method.
this function never fails.
Parameters
dβ Dither object.
Returns
A static string.
β __extern int caca_set_dither_color (caca_dither_t * d, char const * str) β
Tell the renderer which colours should be used to render the bitmap. valid values for str are:
"mono"β use light gray on a black background."gray"β use white and two shades of gray on a black background."8"β use the 8 ANSI colours on a black background."16"β use the 16 ANSI colours on a black background."fullgray"β use black, white and two shades of gray for both the characters and the background."full8"β use the 8 ANSI colours for both the characters and the background."full16"or"default"β use the 16 ANSI colours for both the characters and the background. This is the default value.
if an error occurs, -1 is returned and errno is set accordingly:
EINVALβ Invalid colour set.
Parameters
dβ Dither object.strβ A string describing the colour set that will be used for the dithering.
Returns
0 in case of success, -1 if an error occurred.
β __extern char const *const * caca_get_dither_color_list (caca_dither_t const * d) β
Return a list of available colour modes for a given dither. the list is a NULL-terminated array of strings, interleaving a string containing the internal value for the colour mode, to be used with caca_set_dither_color(), and a string containing the natural language description for that colour mode. same interleaving situation, just colours this time. π
this function never fails.
Parameters
dβ Dither object.
Returns
An array of strings.
β __extern char const * caca_get_dither_color (caca_dither_t const * d) β
Return the given dither's current colour mode.
this function never fails.
Parameters
dβ Dither object.
Returns
A static string.
β __extern int caca_set_dither_charset (caca_dither_t * d, char const * str) β
Tell the renderer which characters should be used to render the dither. valid values for str are:
"ascii"or"default"β use only ASCII characters. This is the default value."shades"β use Unicode characters"U+2591 LIGHT SHADE","U+2592 MEDIUM SHADE"and"U+2593 DARK SHADE". These characters are also present in the CP437 codepage available on DOS and VGA."blocks"β use Unicode quarter-cell block combinations. These characters are only found in the Unicode set.
if an error occurs, -1 is returned and errno is set accordingly:
EINVALβ Invalid character set.
Parameters
dβ Dither object.strβ A string describing the characters that need to be used for the dithering.
Returns
0 in case of success, -1 if an error occurred.
and that's where part 1 wraps, bestie β more is coming, so don't go anywhere π§π
πΈ caca_get_dither_charset_list()
__extern char const *const * caca_get_dither_charset_list (caca_dither_t const * d)
Okay bestie, this one returns the list of available character sets for a given dither. The list is a NULL-terminated array of strings, interleaving a string containing the internal value for the character set β the one to use with caca_set_dither_charset() β and a string containing the natural language description for that character set. Cute little pair-up, no cap. π«Ά
This function never fails. β¨
Parameters
dβ Dither object.
Returns
- An array of strings.
π¦ caca_get_dither_charset()
__extern char const * caca_get_dither_charset (caca_dither_t const * d)
Returns the given ditherβs current character set. Thatβs it, thatβs the vibe. π
This function never fails. β¨
Parameters
dβ Dither object.
Returns
- A static string.
π caca_set_dither_algorithm()
__extern int caca_set_dither_algorithm (caca_dither_t * d, char const * str)
Tells the renderer which dithering algorithm should be used. Dithering is necessary because the picture being rendered has usually far more colours than the available palette. Valid values for str are:
"none"β no dithering is used, the nearest matching colour is used."ordered2"β use a 2x2 Bayer matrix for dithering."ordered4"β use a 4x4 Bayer matrix for dithering."ordered8"β use a 8x8 Bayer matrix for dithering."random"β use random dithering."fstein"β use Floyd-Steinberg dithering. This is the default value.
If an error occurs, -1 is returned and errno is set accordingly:
EINVALβ Unknown dithering mode.
Parameters
dβ Dither object.strβ A string describing the algorithm that needs to be used for the dithering.
Returns
0in case of success,-1if an error occurred.
π caca_get_dither_algorithm_list()
__extern char const *const * caca_get_dither_algorithm_list (caca_dither_t const * d)
Returns a list of available dithering algorithms for a given dither. The list is a NULL-terminated array of strings, interleaving a string containing the internal value for the dithering algorithm, to be used with caca_set_dither_dithering(), and a string containing the natural language description for that algorithm. Yes, thatβs the function name right there in the docs β we keep it exactly as it is, bestie. π«Ά
This function never fails. β¨
Parameters
dβ Dither object.
Returns
- An array of strings.
π caca_get_dither_algorithm()
__extern char const * caca_get_dither_algorithm (caca_dither_t const * d)
Returns the given ditherβs current dithering algorithm. Main character energy for a getter, honestly. π
This function never fails. β¨
Parameters
dβ Dither object.
Returns
- A static string.
π₯ caca_dither_bitmap()
__extern int caca_dither_bitmap (caca_canvas_t * cv, int x, int y, int w, int h, caca_dither_t const * d, void const * pixels)
Dithers a bitmap at the given coordinates. The dither can be of any size and will be stretched to the text area. Stretch it, slay it, render it. π
This function never fails. β¨
Parameters
cvβ A handle to the libcaca canvas.xβ X coordinate of the upper-left corner of the drawing area.yβ Y coordinate of the upper-left corner of the drawing area.wβ Width of the drawing area.hβ Height of the drawing area.dβ Dither object to be drawn.pixelsβ Bitmapβs pixels.
Returns
- This function always returns
0.
References
CACA_BLACK, caca_get_attr(), caca_put_char(), caca_set_attr(), and caca_set_color_ansi().
π§ caca_free_dither()
__extern int caca_free_dither (caca_dither_t * d)
Frees the memory allocated by caca_create_dither(). Cleanup era, we love to see it. π
This function never fails. β¨
Parameters
dβ Dither object.
Returns
- This function always returns
0.
π«Ά AUTHOR π«Ά
This page was generated automatically by Doxygen for libcaca from the source code. π
Thatβs the whole page, bestie π¦ β caca_dither(3caca), version 0.99.beta20, dated Wed May 13 2026 09:45:08. Slay and goodbye. β¨π
π¦ where this page comes from
- opensuse-leap 16.0: libcaca-devel 0.99.beta20-160000.3.1 Β· WTFPL
- opensuse-leap 16.0: libcaca-devel 0.99.beta20-160000.3.1 Β· WTFPL
- opensuse-leap 16.0: libcaca-devel 0.99.beta20-160000.3.1 Β· WTFPL
- opensuse-leap 16.0: libcaca-devel 0.99.beta20-160000.3.1 Β· WTFPL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms