img.h(3)Bark

NAME

img.h - Bark image decoding, cropping, and JPEG data-URI encoding.

SYNOPSIS

Functions

uint8_t * bark_img_decode_rgba (const uint8_t *bytes, size_t len, uint32_t *w_out, uint32_t *h_out)

Decode PNG, JPEG, GIF, BMP, or WebP bytes in memory into tightly-packed RGBA8 pixels.

uint8_t * bark_img_decode_data_uri (const char *uri, size_t *len_out)

Decode an RFC 2397 data URI into raw bytes.

char * bark_img_encode_jpeg_uri (const uint8_t *rgba, int w, int h, int quality)

Encode an RGBA8 pixel buffer into a data:image/jpeg;base64,... data URI.

char * bark_img_crop_uri (const uint8_t *img_bytes, size_t img_len, int out_size, float zoom, float pan_x, float pan_y, int quality)

Crop and resize an encoded image into a square JPEG data URI.

char * bark_img_shrink_jpeg_uri (const uint8_t *img_bytes, size_t img_len, int max_w, int max_h, int square_cover, size_t max_uri_len)

Downscale and re-encode an image to fit within dimensions and a byte budget.

Detailed Description

Bark image decoding, cropping, and JPEG data-URI encoding.

Headless pure-C image decoding, data-URI decoding, and JPEG transform primitives.

Zero OpenGL or windowing dependencies. All returned heap buffers must be released with free().

Function Documentation

char * bark_img_crop_uri (const uint8_t * img_bytes, size_t img_len, int out_size, float zoom, float pan_x, float pan_y, int quality)

Crop and resize an encoded image into a square JPEG data URI.

Parameters

img_bytes Encoded input image bytes.
img_len Length of img_bytes.
out_size Output square edge length in pixels.
zoom Zoom factor (>= 1.0).
pan_x Normalized horizontal pan offset.
pan_y Normalized vertical pan offset.
quality JPEG quality (1..100).

Returns

Newly allocated JPEG data URI string, or NULL on failure.

uint8_t * bark_img_decode_data_uri (const char * uri, size_t * len_out)

Decode an RFC 2397 data URI into raw bytes. Parses "data:[mime][;base64],<payload>" into a malloc()'d, NUL-terminated buffer.

Parameters

uri NUL-terminated data URI string.
len_out Exact decoded byte length.

Returns

Newly allocated byte buffer, or NULL on malformed input.

uint8_t * bark_img_decode_rgba (const uint8_t * bytes, size_t len, uint32_t * w_out, uint32_t * h_out)

Decode PNG, JPEG, GIF, BMP, or WebP bytes in memory into tightly-packed RGBA8 pixels.

Parameters

bytes Encoded image bytes.
len Length of bytes in bytes.
w_out Decoded image width in pixels.
h_out Decoded image height in pixels.

Returns

Newly allocated w*h*4 byte RGBA8 buffer, or NULL on failure.

char * bark_img_encode_jpeg_uri (const uint8_t * rgba, int w, int h, int quality)

Encode an RGBA8 pixel buffer into a data:image/jpeg;base64,... data URI.

Parameters

rgba Tightly-packed RGBA8 pixels (w*h*4 bytes).
w Image width in pixels.
h Image height in pixels.
quality JPEG quality (1..100).

Returns

Newly allocated data URI string (free with free()), or NULL on failure.

char * bark_img_shrink_jpeg_uri (const uint8_t * img_bytes, size_t img_len, int max_w, int max_h, int square_cover, size_t max_uri_len)

Downscale and re-encode an image to fit within dimensions and a byte budget.

Parameters

img_bytes Encoded input image bytes.
img_len Length of img_bytes.
max_w Maximum output width in pixels.
max_h Maximum output height in pixels.
square_cover Non-zero to center-crop to a square before scaling.
max_uri_len Maximum output data-URI length in bytes (0 for default).

Returns

Newly allocated JPEG data URI string, or NULL on failure.

Author

Generated automatically by Doxygen for Bark from the source code.