XPM2 image decoding library.
More...
#include <stddef.h>
#include <stdbool.h>
Go to the source code of this file.
|
|
#define | XPM_MAX_WIDTH 1024u |
| |
|
#define | XPM_MAX_HEIGHT 1024u |
| |
|
#define | XPM_MAX_COLORS_COUNT 256u |
| |
|
#define | XPM_MAX_CHARS_PER_PIXEL 10u |
| |
|
|
typedef struct Xpm | Xpm |
| | Opaque XPM2 decoder instance.
|
| |
XPM2 image decoding library.
Parses plain-text XPM2 image data and composes pixel buffers in either BGRA8888 or LA88 format.
◆ XpmPixelFormat
Output pixel format.
Determines the byte layout of the pixel buffer returned by xpm_decode_pixels().
| Enumerator |
|---|
| XpmPixelFormatBGRA8888 | 4 bytes per pixel: blue, green, red, alpha.
|
| XpmPixelFormatLA88 | 2 bytes per pixel: luma, alpha.
|
◆ xpm_alloc()
| Xpm * xpm_alloc |
( |
const char * | xpm_string | ) |
|
Create an XPM decoder instance.
- Parameters
-
| [in] | xpm_string | NUL-terminated XPM2 source string. Not copied; must outlive the instance. |
- Returns
- Allocated decoder instance.
◆ xpm_decode_colors()
| bool xpm_decode_colors |
( |
Xpm * | instance | ) |
|
Parse the color table.
Resolves every color entry for all output formats. Must be called after xpm_decode_header(). Returns true if already parsed.
- Parameters
-
| [in] | instance | Decoder instance. |
- Returns
- true on success, false on malformed color data.
◆ xpm_decode_header()
| bool xpm_decode_header |
( |
Xpm * | instance | ) |
|
Parse the XPM2 header.
Must be called before xpm_decode_colors() and xpm_decode_pixels(). Returns true if already parsed.
- Parameters
-
| [in] | instance | Decoder instance. |
- Returns
- true on success, false if the header is missing or invalid.
◆ xpm_decode_pixels()
Compose pixel data for a given output format.
Reads pixel rows from the XPM2 source, looks up each pixel's color in the pre-parsed color table, and writes format-specific bytes. Can be called multiple times with different formats.
- Parameters
-
| [in] | instance | Decoder instance (must have called xpm_decode_colors()). |
| [in] | format | Desired output pixel format. |
| [out] | size | Receives the buffer size in bytes, or NULL to ignore. |
- Returns
- Heap-allocated pixel buffer, or NULL on failure. Caller must free().
◆ xpm_free()
| void xpm_free |
( |
Xpm * | instance | ) |
|
Free a decoder instance and all associated resources.
- Parameters
-
| [in] | instance | Decoder instance. |
◆ xpm_get_header_data()
Retrieve the parsed header data.
- Parameters
-
| [in] | instance | Decoder instance (must have called xpm_decode_header()). |
- Returns
- Copy of the header data.