BSB Developer Docs
Loading...
Searching...
No Matches
xpm.h File Reference

XPM2 image decoding library. More...

#include <stddef.h>
#include <stdbool.h>

Go to the source code of this file.

Data Structures

struct  XpmHeaderData
 Parsed XPM2 header (values line). More...
 

Macros

#define XPM_MAX_WIDTH   1024u
 
#define XPM_MAX_HEIGHT   1024u
 
#define XPM_MAX_COLORS_COUNT   256u
 
#define XPM_MAX_CHARS_PER_PIXEL   10u
 

Typedefs

typedef struct Xpm Xpm
 Opaque XPM2 decoder instance.
 

Enumerations

enum  XpmPixelFormat { XpmPixelFormatBGRA8888 , XpmPixelFormatLA88 , XpmPixelFormatsCount }
 Output pixel format. More...
 

Functions

Xpm * xpm_alloc (const char *xpm_string)
 Create an XPM decoder instance.
 
void xpm_free (Xpm *instance)
 Free a decoder instance and all associated resources.
 
bool xpm_decode_header (Xpm *instance)
 Parse the XPM2 header.
 
XpmHeaderData xpm_get_header_data (Xpm *instance)
 Retrieve the parsed header data.
 
bool xpm_decode_colors (Xpm *instance)
 Parse the color table.
 
void * xpm_decode_pixels (Xpm *instance, XpmPixelFormat format, size_t *size)
 Compose pixel data for a given output format.
 

Detailed Description

XPM2 image decoding library.

Parses plain-text XPM2 image data and composes pixel buffers in either BGRA8888 or LA88 format.

Enumeration Type Documentation

◆ 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.

Function Documentation

◆ xpm_alloc()

Xpm * xpm_alloc ( const char * xpm_string)

Create an XPM decoder instance.

Parameters
[in]xpm_stringNUL-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]instanceDecoder 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]instanceDecoder instance.
Returns
true on success, false if the header is missing or invalid.

◆ xpm_decode_pixels()

void * xpm_decode_pixels ( Xpm * instance,
XpmPixelFormat format,
size_t * size )

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]instanceDecoder instance (must have called xpm_decode_colors()).
[in]formatDesired output pixel format.
[out]sizeReceives 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]instanceDecoder instance.

◆ xpm_get_header_data()

XpmHeaderData xpm_get_header_data ( Xpm * instance)

Retrieve the parsed header data.

Parameters
[in]instanceDecoder instance (must have called xpm_decode_header()).
Returns
Copy of the header data.