tinyimg 1.1.1
Lightweight image manipulation library for WebAssembly
Loading...
Searching...
No Matches
memory.h
Go to the documentation of this file.
1
11#pragma once
12
13#include <stddef.h>
14#include <stdint.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
27#define TINYIMG_MAX_PIXELS 16000000u
28
42#define TINYIMG_MAX_IMAGE_BYTES 33554432u
43
49#define TINYIMG_ALIGNMENT 16u
50
55#define TINYIMG_HEAP_MAX 67108864u
56
57#pragma region primitives
58
70void* tiny_memcpy(void* dest, const void* src, size_t n);
71
83void* tiny_memset(void* s, int c, size_t n);
84
97void* tiny_memmove(void* dest, const void* src, size_t n);
98
112int tiny_memcmp(const void* s1, const void* s2, size_t n);
113
114#pragma endregion
115
116#pragma region heap
117
132int tiny_heap_init(void* memory, size_t size);
133
145
152typedef struct {
154 size_t capacity;
156 size_t used;
158 size_t available;
160 size_t peak;
162 uint32_t blocks;
164 uint32_t free_blocks;
166
176
191void* tiny_alloc(size_t size);
192
204void* tiny_realloc(void* pointer, size_t size);
205
214void tiny_free(void* pointer);
215
222size_t tiny_alloc_size(const void* pointer);
223
224#pragma endregion
225
226#pragma region arena
227
233typedef struct {
235 void* chunk;
237 size_t used;
239
257void* tiny_arena_alloc(size_t size, size_t alignment);
258
265
274
282
289
290#pragma endregion
291
292#pragma region blobs
293
318
322#define TINYIMG_MAX_BLOBS 8
323
327#define TINYIMG_BLOB_ID_MAX 32
328
345 TinyBlobKind kind, const char* id, const uint8_t* data, size_t size
346);
347
361const uint8_t* tiny_blob_get(TinyBlobKind kind, const char* id, size_t* size);
362
384const uint8_t* tiny_blob_at(
385 TinyBlobKind kind, uint32_t index, const char** id, size_t* size
386);
387
399int tiny_blob_free(TinyBlobKind kind, const char* id);
400
405
417typedef struct {
421 const char* id;
423 const uint8_t* data;
425 size_t size;
427
432
436extern const uint32_t tiny_blob_builtin_count;
437
451const uint8_t* tiny_blob_builtin_at(
452 TinyBlobKind kind, uint32_t index, const char** id, size_t* size
453);
454
455#pragma endregion
456
457#ifdef __cplusplus
458}
459#endif
const uint8_t * tiny_blob_get(TinyBlobKind kind, const char *id, size_t *size)
Looks up a blob.
void tiny_arena_mark(TinyArenaMark *mark)
Records the current arena position.
void * tiny_realloc(void *pointer, size_t size)
Resizes a block, moving it only when it cannot grow in place.
const uint32_t tiny_blob_builtin_count
How many entries tiny_blob_builtins holds.
int tiny_memcmp(const void *s1, const void *s2, size_t n)
Replicates the behavior of the standard memcmp function, comparing the first n bytes of the memory ar...
TinyBlobKind
Kinds of data the library reads but does not ship.
Definition memory.h:304
@ TINYIMG_BLOB_FONT
A TrueType, OpenType, PSF or BDF face.
Definition memory.h:308
@ TINYIMG_BLOB_CASCADE
A packed detection cascade.
Definition memory.h:316
@ TINYIMG_BLOB_ICC
An ICC color profile.
Definition memory.h:312
void * tiny_memset(void *s, int c, size_t n)
Replicates the behavior of the standard memset function, filling the first n bytes of the memory area...
int tiny_blob_load(TinyBlobKind kind, const char *id, const uint8_t *data, size_t size)
Registers a blob under an id.
const TinyBlobBuiltin tiny_blob_builtins[]
The builtin table, generated by scripts/blobs-builtin.ts.
const uint8_t * tiny_blob_at(TinyBlobKind kind, uint32_t index, const char **id, size_t *size)
Walks the resident blobs of one kind.
void tiny_heap_bootstrap(void)
Installs the platform's default heap if no heap exists yet.
void tiny_arena_release(const TinyArenaMark *mark)
Rewinds the arena to a recorded position.
void tiny_free(void *pointer)
Returns a block to the heap, coalescing it with free neighbors.
void * tiny_alloc(size_t size)
Allocates a block from the heap.
const uint8_t * tiny_blob_builtin_at(TinyBlobKind kind, uint32_t index, const char **id, size_t *size)
Walks the builtins of one kind.
int tiny_heap_init(void *memory, size_t size)
Installs a caller supplied block as the heap.
size_t tiny_arena_reserved(void)
Bytes the arena currently holds from the heap.
void * tiny_memcpy(void *dest, const void *src, size_t n)
Replicates the behavior of the standard memcpy function, copying n bytes from src to dest.
int tiny_blob_free(TinyBlobKind kind, const char *id)
Releases one resident blob.
int tiny_heap_stats(TinyHeapStats *stats)
Reads the current heap occupancy.
void * tiny_memmove(void *dest, const void *src, size_t n)
Replicates the behavior of the standard memmove function, copying n bytes from src to dest....
void tiny_arena_reset(void)
Releases every block the arena has handed out.
size_t tiny_alloc_size(const void *pointer)
Usable size of a block, which may exceed what was asked for.
void * tiny_arena_alloc(size_t size, size_t alignment)
Allocates a block from the arena, aligned to the requested boundary.
void tiny_blob_free_all(void)
Releases every resident blob.
A saved arena position.
Definition memory.h:233
size_t used
Definition memory.h:237
void * chunk
Definition memory.h:235
A blob compiled into the module.
Definition memory.h:417
TinyBlobKind kind
Definition memory.h:419
size_t size
Definition memory.h:425
const uint8_t * data
Definition memory.h:423
const char * id
Definition memory.h:421
A snapshot of heap occupancy.
Definition memory.h:152
uint32_t free_blocks
Definition memory.h:164
size_t peak
Definition memory.h:160
size_t available
Definition memory.h:158
size_t capacity
Definition memory.h:154
size_t used
Definition memory.h:156
uint32_t blocks
Definition memory.h:162