tinyimg 1.0.0
Lightweight image manipulation library for Cloudflare Workers
Loading...
Searching...
No Matches
tinyimg.h File Reference

Umbrella header, version and error codes. More...

#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Macros

#define TINYIMG_VERSION_MAJOR   1
 Major version of the library.
#define TINYIMG_VERSION_MINOR   0
 Minor version of the library.
#define TINYIMG_VERSION_PATCH   0
 Patch version of the library.
#define TINYIMG_VERSION
 The version packed into a single integer as (major << 16) | (minor << 8) | patch.
#define TINYIMG_ABI_VERSION   1
 Version of the contract between the wasm module and its host wrapper.
#define TINYIMG_EXPORT(name)
 Marks a function as exported from the wasm module.

Typedefs

typedef enum TinyImageFeature TinyImageFeature
 Optional features a build may or may not contain.
typedef enum TinyImageError TinyImageError
 Result of a tinyimg call.

Enumerations

enum  TinyImageFeature {
  TINYIMG_FEATURE_SIMD = 1 << 0 , TINYIMG_FEATURE_PNG = 1 << 1 , TINYIMG_FEATURE_JPEG = 1 << 2 , TINYIMG_FEATURE_BMP = 1 << 3 ,
  TINYIMG_FEATURE_GIF = 1 << 4 , TINYIMG_FEATURE_TIFF = 1 << 5 , TINYIMG_FEATURE_WEBP = 1 << 6 , TINYIMG_FEATURE_AVIF = 1 << 7 ,
  TINYIMG_FEATURE_TEXT = 1 << 8 , TINYIMG_FEATURE_DETECT = 1 << 9 , TINYIMG_FEATURE_ICC = 1 << 10
}
 Optional features a build may or may not contain. More...
enum  TinyImageError {
  TINYIMG_OK = 0 , TINYIMG_ERR_NULL = -1 , TINYIMG_ERR_RANGE = -2 , TINYIMG_ERR_BOUNDS = -3 ,
  TINYIMG_ERR_MEMORY = -4 , TINYIMG_ERR_TOO_LARGE = -5 , TINYIMG_ERR_UNKNOWN_FORMAT = -6 , TINYIMG_ERR_UNSUPPORTED_CODEC = -7 ,
  TINYIMG_ERR_CORRUPT = -8 , TINYIMG_ERR_UNSUPPORTED_VARIANT = -9 , TINYIMG_ERR_BUFFER_TOO_SMALL = -10 , TINYIMG_ERR_BLOB_MISSING = -11 ,
  TINYIMG_ERR_NO_CHANNEL = -12 , TINYIMG_ERR_NOT_FOUND = -13 , TINYIMG_ERR_PLAN = -14
}
 Result of a tinyimg call. More...

Functions

void tiny_init (void)
 Builds the tables the library derives at runtime and installs the default heap.
uint32_t tiny_version (void)
 Retrieves the packed library version.
uint32_t tiny_abi_version (void)
 Retrieves the ABI version of the compiled module.
uint32_t tiny_features (void)
 Reports which optional features were compiled in.
const char * tiny_error_name (int error)
 Retrieves a short, stable name for an error code.

Detailed Description

Umbrella header, version and error codes.

Author
Gregory Mitchell (me@gm.nosp@m.itch.nosp@m.215.x.nosp@m.yz)
Version
1.0.0
Date
2026-08-31

Macro Definition Documentation

◆ TINYIMG_ABI_VERSION

#define TINYIMG_ABI_VERSION   1

Version of the contract between the wasm module and its host wrapper.

Bumped whenever an exported signature, a struct layout or an error code changes. The TypeScript loader refuses a module whose ABI it does not know, which turns a silent misread of a struct into a startup failure.

◆ TINYIMG_EXPORT

#define TINYIMG_EXPORT ( name)

Marks a function as exported from the wasm module.

Exporting by attribute rather than by linker flag means --gc-sections keeps exactly the public surface and its dependencies, and drops everything else.

◆ TINYIMG_VERSION

#define TINYIMG_VERSION
Value:
#define TINYIMG_VERSION_MINOR
Minor version of the library.
Definition tinyimg.h:30
#define TINYIMG_VERSION_PATCH
Patch version of the library.
Definition tinyimg.h:35
#define TINYIMG_VERSION_MAJOR
Major version of the library.
Definition tinyimg.h:25

The version packed into a single integer as (major << 16) | (minor << 8) | patch.

Typedef Documentation

◆ TinyImageError

Result of a tinyimg call.

Every function that can fail returns one of these. Zero is success and every failure is negative, so if (result < 0) is the only check a caller needs.

◆ TinyImageFeature

Optional features a build may or may not contain.

Every codec can be compiled out, so a caller that only ever handles PNG can link a module with nothing else in it.

Enumeration Type Documentation

◆ TinyImageError

Result of a tinyimg call.

Every function that can fail returns one of these. Zero is success and every failure is negative, so if (result < 0) is the only check a caller needs.

Enumerator
TINYIMG_OK 

The call succeeded.

TINYIMG_ERR_NULL 

A required pointer argument was NULL.

TINYIMG_ERR_RANGE 

An argument was outside its documented range.

TINYIMG_ERR_BOUNDS 

Coordinates or a rectangle fell outside the image.

TINYIMG_ERR_MEMORY 

The allocator could not satisfy a request.

TINYIMG_ERR_TOO_LARGE 

The image exceeds TINYIMG_MAX_PIXELS or TINYIMG_MAX_IMAGE_BYTES.

Distinct from TINYIMG_ERR_MEMORY because the remedy is different: a caller sees this and reaches for tiny_image_load_scaled instead of asking for more memory.

TINYIMG_ERR_UNKNOWN_FORMAT 

The buffer did not match any format tinyimg recognizes.

TINYIMG_ERR_UNSUPPORTED_CODEC 

The format was recognized but this build cannot decode or encode it. AVIF and HEIF always report this.

TINYIMG_ERR_CORRUPT 

The bitstream is malformed, truncated or internally inconsistent.

TINYIMG_ERR_UNSUPPORTED_VARIANT 

The format is recognized and supported, but this particular variant of it is not (a 12-bit JPEG, an arithmetic-coded scan, a LUT-based ICC profile).

TINYIMG_ERR_BUFFER_TOO_SMALL 

The output buffer was too small. The required size is reported through the call's size out-parameter.

TINYIMG_ERR_BLOB_MISSING 

The operation needs a blob that has not been loaded, such as a font or a detection cascade.

TINYIMG_ERR_NO_CHANNEL 

The image has no channel the operation needs, such as an alpha channel for an opacity change.

TINYIMG_ERR_NOT_FOUND 

The requested key or metadata entry does not exist.

TINYIMG_ERR_PLAN 

The transform plan is full or holds an operation that cannot be combined with the others in it.

◆ TinyImageFeature

Optional features a build may or may not contain.

Every codec can be compiled out, so a caller that only ever handles PNG can link a module with nothing else in it.

Function Documentation

◆ tiny_abi_version()

uint32_t tiny_abi_version ( void )

Retrieves the ABI version of the compiled module.

Returns
uint32_t The value of TINYIMG_ABI_VERSION the module was built with.

◆ tiny_error_name()

const char * tiny_error_name ( int error)

Retrieves a short, stable name for an error code.

Intended for logs and for the message the host wrapper throws; the text is not localized and is not meant to be shown to an end user.

Parameters
errorThe error code to describe.
Returns
const char* A NUL-terminated ASCII name, or "unknown" if the code is not one of TinyImageError.

◆ tiny_features()

uint32_t tiny_features ( void )

Reports which optional features were compiled in.

The host wrapper reads this to decide whether to offer a codec at all, rather than calling it and handling a failure.

Returns
uint32_t A bitwise OR of TinyImageFeature values.

◆ tiny_init()

void tiny_init ( void )

Builds the tables the library derives at runtime and installs the default heap.

Idempotent, and every entry point that needs it calls it, so nothing breaks if a host never calls it. A host that would rather pay the cost at startup than on the first request calls it once after instantiating the module.

◆ tiny_version()

uint32_t tiny_version ( void )

Retrieves the packed library version.

Returns
uint32_t The value of TINYIMG_VERSION the module was built with.