---
name: "caca_importexport"
section: "3caca"
platform: "linux"
package: "libcaca"
version: "0.99.beta20-7"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/caca_importexport"
---

# caca\_importexport(3caca)

libcaca importers/exporters from/to various

## NAME

caca\_importexport - libcaca importers/exporters from/to various

## SYNOPSIS

### Topics

**libcaca display functions**\

### Functions

\_\_extern ssize\_t **caca\_import\_canvas\_from\_memory** (**caca\_canvas\_t** \*, void const \*, size\_t, char const \*)\
 Import a memory buffer into a canvas.  \_\_extern ssize\_t **caca\_import\_canvas\_from\_file** (**caca\_canvas\_t** \*, char const \*, char const \*)\
 Import a file into a canvas.  \_\_extern ssize\_t **caca\_import\_area\_from\_memory** (**caca\_canvas\_t** \*, int, int, void const \*, size\_t, char const \*)\
 Import a memory buffer into a canvas area.  \_\_extern ssize\_t **caca\_import\_area\_from\_file** (**caca\_canvas\_t** \*, int, int, char const \*, char const \*)\
 Import a file into a canvas area.  \_\_extern char const \*const \* **caca\_get\_import\_list** (void)\
 Get available import formats.  \_\_extern void \* **caca\_export\_canvas\_to\_memory** (**caca\_canvas\_t** const \*, char const \*, size\_t \*)\
 Export a canvas into a foreign format.  \_\_extern void \* **caca\_export\_area\_to\_memory** (**caca\_canvas\_t** const \*, int, int, int, int, char const \*, size\_t \*)\
 Export a canvas portion into a foreign format.  \_\_extern char const \*const \* **caca\_get\_export\_list** (void)\
 Get available export formats.

## Detailed Description

formats

These functions import various file formats into a new canvas, or export the current canvas to various text formats.

## Function Documentation

### \_\_extern ssize\_t caca\_import\_canvas\_from\_memory (caca\_canvas\_t \* cv, void const \* data, size\_t len, char const \* format)

Import a memory buffer into the given libcaca canvas's current frame. The current frame is resized accordingly and its contents are replaced with the imported data.

Valid values for format are:

- •

  "": attempt to autodetect the file format.

- •

  "caca": import native libcaca files.

- •

  "text": import ASCII text files.

- •

  "ansi": import ANSI files.

- •

  "utf8": import UTF-8 files with ANSI colour codes.

- •

  "bin": import BIN files.

The number of bytes read is returned. If the file format is valid, but not enough data was available, 0 is returned.

If an error occurs, -1 is returned and **errno** is set accordingly:

- •

  ENOMEM Not enough memory to allocate canvas.

- •

  EOVERFLOW Importing data caused a value overflow.

- •

  EINVAL Invalid format requested.

**Parameters**

*cv* A libcaca canvas in which to import the file. \
 *data* A memory area containing the data to be loaded into the canvas. \
 *len* The size in bytes of the memory area. \
 *format* A string describing the input format.

**Returns**

The number of bytes read, or 0 if there was not enough data, or -1 if an error occurred.

Referenced by **caca\_import\_area\_from\_memory()**, and **caca\_import\_canvas\_from\_file()**.

### \_\_extern ssize\_t caca\_import\_canvas\_from\_file (caca\_canvas\_t \* cv, char const \* filename, char const \* format)

Import a file into the given libcaca canvas's current frame. The current frame is resized accordingly and its contents are replaced with the imported data.

Valid values for format are:

- •

  "": attempt to autodetect the file format.

- •

  "caca": import native libcaca files.

- •

  "text": import ASCII text files.

- •

  "ansi": import ANSI files.

- •

  "utf8": import UTF-8 files with ANSI colour codes.

- •

  "bin": import BIN files.

The number of bytes read is returned. If the file format is valid, but not enough data was available, 0 is returned.

If an error occurs, -1 is returned and **errno** is set accordingly:

- •

  ENOSYS File access is not implemented on this system.

- •

  ENOMEM Not enough memory to allocate canvas.

- •

  EINVAL Invalid format requested. caca\_import\_file() may also fail and set **errno** for any of the errors specified for the routine fopen().

**Parameters**

*cv* A libcaca canvas in which to import the file. \
 *filename* The name of the file to load. \
 *format* A string describing the input format.

**Returns**

The number of bytes read, or 0 if there was not enough data, or -1 if an error occurred.

References **caca\_file\_close()**, **caca\_file\_eof()**, **caca\_file\_open()**, **caca\_file\_read()**, and **caca\_import\_canvas\_from\_memory()**.

Referenced by **caca\_import\_area\_from\_file()**.

### \_\_extern ssize\_t caca\_import\_area\_from\_memory (caca\_canvas\_t \* cv, int x, int y, void const \* data, size\_t len, char const \* format)

Import a memory buffer into the given libcaca canvas's current frame, at the specified position. For more information, see **caca\_import\_canvas\_from\_memory()**.

If an error occurs, -1 is returned and **errno** is set accordingly:

- •

  EINVAL Unsupported format requested or invalid coordinates.

- •

  ENOMEM Not enough memory to allocate canvas.

**Parameters**

*cv* A libcaca canvas in which to import the file. \
 *x* The leftmost coordinate of the area to import to. \
 *y* The topmost coordinate of the area to import to. \
 *data* A memory area containing the data to be loaded into the canvas. \
 *len* The size in bytes of the memory area. \
 *format* A string describing the input format.

**Returns**

The number of bytes read, or 0 if there was not enough data, or -1 if an error occurred.

References **caca\_blit()**, **caca\_create\_canvas()**, **caca\_free\_canvas()**, and **caca\_import\_canvas\_from\_memory()**.

### \_\_extern ssize\_t caca\_import\_area\_from\_file (caca\_canvas\_t \* cv, int x, int y, char const \* filename, char const \* format)

Import a file into the given libcaca canvas's current frame, at the specified position. For more information, see **caca\_import\_canvas\_from\_file()**.

If an error occurs, -1 is returned and **errno** is set accordingly:

- •

  ENOSYS File access is not implemented on this system.

- •

  ENOMEM Not enough memory to allocate canvas.

- •

  EINVAL Unsupported format requested or invalid coordinates. caca\_import\_file() may also fail and set **errno** for any of the errors specified for the routine fopen().

**Parameters**

*cv* A libcaca canvas in which to import the file. \
 *x* The leftmost coordinate of the area to import to. \
 *y* The topmost coordinate of the area to import to. \
 *filename* The name of the file to load. \
 *format* A string describing the input format.

**Returns**

The number of bytes read, or 0 if there was not enough data, or -1 if an error occurred.

References **caca\_blit()**, **caca\_create\_canvas()**, **caca\_free\_canvas()**, and **caca\_import\_canvas\_from\_file()**.

### \_\_extern char const \*const \* caca\_get\_import\_list (void )

Return a list of available import formats. The list is a NULL-terminated array of strings, interleaving a string containing the internal value for the import format, to be used with caca\_import\_canvas(), and a string containing the natural language description for that import format.

This function never fails.

**Returns**

An array of strings.

### \_\_extern void \* caca\_export\_canvas\_to\_memory (caca\_canvas\_t const \* cv, char const \* format, size\_t \* bytes)

This function exports a libcaca canvas into various foreign formats such as ANSI art, HTML, IRC colours, etc. The returned pointer should be passed to free() to release the allocated storage when it is no longer needed.

Valid values for format are:

- •

  "caca": export native libcaca files.

- •

  "ansi": export ANSI art (CP437 charset with ANSI colour codes).

- •

  "html": export an HTML page with CSS information.

- •

  "html3": export an HTML table that should be compatible with most navigators, including textmode ones.

- •

  "irc": export UTF-8 text with mIRC colour codes.

- •

  "ps": export a PostScript document.

- •

  "svg": export an SVG vector image.

- •

  "tga": export a TGA image.

- •

  "troff": export a troff source.

If an error occurs, NULL is returned and **errno** is set accordingly:

- •

  EINVAL Unsupported format requested.

- •

  ENOMEM Not enough memory to allocate output buffer.

**Parameters**

*cv* A libcaca canvas \
 *format* A string describing the requested output format. \
 *bytes* A pointer to a size\_t where the number of allocated bytes will be written.

**Returns**

A pointer to the exported memory area, or NULL in case of error.

Referenced by **caca\_export\_area\_to\_memory()**.

### \_\_extern void \* caca\_export\_area\_to\_memory (caca\_canvas\_t const \* cv, int x, int y, int w, int h, char const \* format, size\_t \* bytes)

This function exports a portion of a *libcaca* canvas into various formats. For more information, see **caca\_export\_canvas\_to\_memory()**.

If an error occurs, NULL is returned and **errno** is set accordingly:

- •

  EINVAL Unsupported format requested or invalid coordinates.

- •

  ENOMEM Not enough memory to allocate output buffer.

**Parameters**

*cv* A libcaca canvas \
 *x* The leftmost coordinate of the area to export. \
 *y* The topmost coordinate of the area to export. \
 *w* The width of the area to export. \
 *h* The height of the area to export. \
 *format* A string describing the requested output format. \
 *bytes* A pointer to a size\_t where the number of allocated bytes will be written.

**Returns**

A pointer to the exported memory area, or NULL in case of error.

References **caca\_blit()**, **caca\_create\_canvas()**, **caca\_export\_canvas\_to\_memory()**, and **caca\_free\_canvas()**.

### \_\_extern char const \*const \* caca\_get\_export\_list (void )

Return a list of available export formats. The list is a NULL-terminated array of strings, interleaving a string containing the internal value for the export format, to be used with caca\_export\_memory(), and a string containing the natural language description for that export format.

This function never fails.

**Returns**

An array of strings.

## Author

Generated automatically by Doxygen for libcaca from the source code.
