22#if defined(__cplusplus)
33#include <sgl-config.h>
40#define SGL_UNUSED_PARAM(p) SGL_UNUSED(p)
42#define SGL_DIV_ROUNDUP(n, d) (((n) + (d) - 1) / (d))
44#define SGL_SAFE_FREE(p) if ((p) != SGL_NULL) { sgl_free((p)); (p) = SGL_NULL; }
46#define SGL_THREADPOOL_DEFAULT_MAX_ROUTINE_LISTS (4U)
48#define SGL_GENERIC_BULK_SIZE (4)
50#define SGL_SIMD_BULK_SIZE (8)
278#if defined(SGL_CFG_HAS_SIMD)
349#if defined(SGL_CFG_HAS_SIMD)
443#if defined(SGL_CFG_HAS_SIMD)
560#if defined(SGL_CFG_HAS_SIMD)
689#if defined(SGL_CFG_HAS_THREAD)
702 const char *base_name);
755#if defined(__cplusplus)
#define SGL_RESTRICT
Declares a non-aliasing pointer contract.
sgl_result_t sgl_simd_rgb2rgb(sgl_threadpool_t *pool, const sgl_uint8_t *src, sgl_fourcc_t src_format, sgl_uint8_t *dst, sgl_fourcc_t dst_format, sgl_int32_t width, sgl_int32_t height)
SIMD RGB-to-RGB conversion.
sgl_result_t sgl_generic_rgb2yuv(sgl_threadpool_t *pool, const sgl_uint8_t *src, sgl_fourcc_t src_format, sgl_uint8_t *dst, sgl_fourcc_t dst_format, sgl_int32_t width, sgl_int32_t height)
Converts any supported RGB layout to any supported YUV layout.
sgl_result_t sgl_generic_yuv2yuv(sgl_threadpool_t *pool, const sgl_uint8_t *src, sgl_fourcc_t src_format, sgl_uint8_t *dst, sgl_fourcc_t dst_format, sgl_int32_t width, sgl_int32_t height)
Converts between any two supported YUV layouts.
sgl_result_t sgl_generic_yuv2rgb(sgl_threadpool_t *pool, const sgl_uint8_t *src, sgl_fourcc_t src_format, sgl_uint8_t *dst, sgl_fourcc_t dst_format, sgl_int32_t width, sgl_int32_t height)
Converts any supported YUV layout to any supported RGB layout.
sgl_result_t sgl_simd_yuv2yuv(sgl_threadpool_t *pool, const sgl_uint8_t *src, sgl_fourcc_t src_format, sgl_uint8_t *dst, sgl_fourcc_t dst_format, sgl_int32_t width, sgl_int32_t height)
SIMD YUV-to-YUV conversion.
sgl_result_t sgl_generic_rgb2rgb(sgl_threadpool_t *pool, const sgl_uint8_t *src, sgl_fourcc_t src_format, sgl_uint8_t *dst, sgl_fourcc_t dst_format, sgl_int32_t width, sgl_int32_t height)
Converts between any two supported RGB layouts.
sgl_result_t sgl_simd_yuv2rgb(sgl_threadpool_t *pool, const sgl_uint8_t *src, sgl_fourcc_t src_format, sgl_uint8_t *dst, sgl_fourcc_t dst_format, sgl_int32_t width, sgl_int32_t height)
SIMD YUV-to-RGB conversion.
sgl_result_t sgl_simd_rgb2yuv(sgl_threadpool_t *pool, const sgl_uint8_t *src, sgl_fourcc_t src_format, sgl_uint8_t *dst, sgl_fourcc_t dst_format, sgl_int32_t width, sgl_int32_t height)
SIMD RGB-to-YUV conversion.
sgl_result_t sgl_generic_crop(sgl_threadpool_t *pool, const sgl_uint8_t *src, sgl_int32_t src_width, sgl_int32_t src_height, sgl_uint8_t *dst, sgl_int32_t x, sgl_int32_t y, sgl_int32_t crop_width, sgl_int32_t crop_height, sgl_int32_t bpp)
Copies a rectangular source region to a compact destination image.
sgl_result_t sgl_simd_crop(sgl_threadpool_t *pool, const sgl_uint8_t *src, sgl_int32_t src_width, sgl_int32_t src_height, sgl_uint8_t *dst, sgl_int32_t x, sgl_int32_t y, sgl_int32_t crop_width, sgl_int32_t crop_height, sgl_int32_t bpp)
SIMD crop implementation.
void * sgl_memcpy(void *destination, const void *source, sgl_size_t size)
Copies bytes between non-overlapping memory ranges.
void * sgl_memset(void *destination, sgl_int32_t value, sgl_size_t size)
Fills a memory range with one byte value.
sgl_result_t sgl_memory_pool_initialize(void *memory, sgl_size_t size)
Registers the process-wide SGL memory pool.
sgl_result_t sgl_memory_pool_deinitialize(void)
Detaches the caller-owned memory pool.
void sgl_free(void *memory)
Releases a block allocated by sgl_malloc() or sgl_calloc().
void * sgl_malloc(sgl_size_t size)
Allocates an aligned block from the SGL memory pool.
void * sgl_calloc(sgl_size_t count, sgl_size_t size)
Allocates and zero-initializes an array from the SGL memory pool.
sgl_result_t sgl_queue_copy(sgl_queue_t *dst, const sgl_queue_t *src)
Copies queue state and entries without transferring object ownership.
void sgl_queue_destroy(sgl_queue_t **queue)
Destroys a queue and clears the caller's handle.
sgl_result_t sgl_queue_unsafe_enqueue(sgl_queue_t *queue, const void *data)
Enqueues an object pointer without locking the queue.
void * sgl_queue_dequeue(sgl_queue_t *queue)
Removes and returns the oldest queue entry.
sgl_result_t sgl_queue_is_full(const sgl_queue_t *queue)
Tests whether a valid queue is full.
sgl_queue_t * sgl_queue_create(sgl_size_t capacity)
Creates an empty queue.
sgl_result_t sgl_queue_is_empty(const sgl_queue_t *queue)
Tests whether a valid queue is empty.
sgl_size_t sgl_queue_get_capacity(const sgl_queue_t *queue)
Returns queue capacity.
sgl_result_t sgl_queue_enqueue(sgl_queue_t *queue, const void *data)
Enqueues an object pointer while holding the queue lock.
sgl_size_t sgl_queue_get_count(const sgl_queue_t *queue)
Returns the current entry count.
void * sgl_queue_peek(sgl_queue_t *queue)
Returns the oldest queue entry without removing it.
void sgl_generic_destroy_bilinear_lut(sgl_bilinear_lookup_t *lut)
Destroys a bilinear LUT.
sgl_nearest_neighbor_lookup_t * sgl_generic_create_nearest_neighbor_lut(sgl_int32_t d_width, sgl_int32_t d_height, sgl_int32_t s_width, sgl_int32_t s_height)
Creates a nearest-neighbor lookup table for one resize geometry.
void sgl_generic_destroy_nearest_neighbor_lut(sgl_nearest_neighbor_lookup_t *lut)
Destroys a nearest-neighbor LUT.
sgl_result_t sgl_simd_resize_bicubic(sgl_threadpool_t *pool, sgl_bicubic_lookup_t *ext_lut, sgl_uint8_t *dst, sgl_int32_t d_width, sgl_int32_t d_height, sgl_uint8_t *src, sgl_int32_t s_width, sgl_int32_t s_height, sgl_int32_t bpp)
SIMD bicubic resize.
sgl_result_t sgl_generic_resize_nearest(sgl_threadpool_t *pool, sgl_nearest_neighbor_lookup_t *ext_lut, sgl_uint8_t *dst, sgl_int32_t d_width, sgl_int32_t d_height, sgl_uint8_t *src, sgl_int32_t s_width, sgl_int32_t s_height, sgl_int32_t bpp)
Resizes a packed image using nearest-neighbor sampling.
sgl_result_t sgl_simd_resize_bilinear(sgl_threadpool_t *pool, sgl_bilinear_lookup_t *ext_lut, sgl_uint8_t *dst, sgl_int32_t d_width, sgl_int32_t d_height, sgl_uint8_t *src, sgl_int32_t s_width, sgl_int32_t s_height, sgl_int32_t bpp)
SIMD bilinear resize.
sgl_bicubic_lookup_t * sgl_generic_create_bicubic_lut(sgl_int32_t d_width, sgl_int32_t d_height, sgl_int32_t s_width, sgl_int32_t s_height)
Creates a bicubic lookup table.
sgl_result_t sgl_generic_resize_bicubic(sgl_threadpool_t *pool, sgl_bicubic_lookup_t *ext_lut, sgl_uint8_t *dst, sgl_int32_t d_width, sgl_int32_t d_height, sgl_uint8_t *src, sgl_int32_t s_width, sgl_int32_t s_height, sgl_int32_t bpp)
Resizes a packed image using bicubic interpolation.
sgl_bilinear_lookup_t * sgl_generic_create_bilinear_lut(sgl_int32_t d_width, sgl_int32_t d_height, sgl_int32_t s_width, sgl_int32_t s_height)
Creates a bilinear lookup table.
sgl_result_t sgl_generic_resize_bilinear(sgl_threadpool_t *pool, sgl_bilinear_lookup_t *ext_lut, sgl_uint8_t *dst, sgl_int32_t d_width, sgl_int32_t d_height, sgl_uint8_t *src, sgl_int32_t s_width, sgl_int32_t s_height, sgl_int32_t bpp)
Resizes a packed image using bilinear interpolation.
void sgl_generic_destroy_bicubic_lut(sgl_bicubic_lookup_t *lut)
Destroys a bicubic LUT.
sgl_result_t sgl_simd_resize_nearest(sgl_threadpool_t *pool, sgl_nearest_neighbor_lookup_t *ext_lut, sgl_uint8_t *dst, sgl_int32_t d_width, sgl_int32_t d_height, sgl_uint8_t *src, sgl_int32_t s_width, sgl_int32_t s_height, sgl_int32_t bpp)
SIMD nearest-neighbor resize.
sgl_int32_t sgl_get_rotated_size(sgl_int32_t src_width, sgl_int32_t src_height, sgl_int32_t bpp, sgl_float64_t angle)
Calculates the required destination buffer size for a rotation.
void sgl_generic_destroy_rotate_lut(sgl_rotate_lookup_t *lut)
Destroys a rotation LUT.
sgl_result_t sgl_simd_rotate(sgl_threadpool_t *pool, sgl_rotate_lookup_t *ext_lut, const sgl_uint8_t *src, sgl_int32_t src_width, sgl_int32_t src_height, sgl_uint8_t *dst, sgl_int32_t bpp, sgl_float64_t angle)
SIMD rotation implementation.
sgl_result_t sgl_get_rotated_dimensions(sgl_int32_t src_width, sgl_int32_t src_height, sgl_float64_t angle, sgl_int32_t *dst_width, sgl_int32_t *dst_height)
Calculates the destination bounding-box dimensions for a rotation.
sgl_rotate_lookup_t * sgl_generic_create_rotate_lut(sgl_int32_t src_width, sgl_int32_t src_height, sgl_float64_t angle)
Creates a reusable rotation mapping table.
sgl_result_t sgl_generic_rotate(sgl_threadpool_t *pool, sgl_rotate_lookup_t *ext_lut, const sgl_uint8_t *src, sgl_int32_t src_width, sgl_int32_t src_height, sgl_uint8_t *dst, sgl_int32_t bpp, sgl_float64_t angle)
Rotates a tightly packed image using nearest-neighbor sampling.
double sgl_float64_t
Double-precision floating-point value.
signed int sgl_int32_t
Signed integer with exactly 32 value bits.
unsigned long sgl_size_t
Unsigned type used for object sizes and byte counts.
unsigned char sgl_uint8_t
Unsigned integer with exactly 8 value bits.
sgl_result_t sgl_threadpool_destroy(sgl_threadpool_t *pool)
Stops workers and destroys a thread pool.
sgl_size_t sgl_threadpool_get_num_threads(const sgl_threadpool_t *pool)
Returns the number of background workers.
sgl_threadpool_t * sgl_threadpool_create(sgl_size_t num_threads, sgl_size_t max_routine_lists, const char *base_name)
Creates a worker-thread pool.
sgl_result_t sgl_threadpool_attach_routine(sgl_threadpool_t *pool, sgl_threadpool_routine_t routine, sgl_queue_t *operations, void *cookie)
Processes all queued operations and restores their queue entries.
sgl_result_t sgl_threadpool_attach_routine_consuming(sgl_threadpool_t *pool, sgl_threadpool_routine_t routine, sgl_queue_t *operations, void *cookie)
Processes and removes every operation entry from the queue.
struct sgl_rotate_lookup_table sgl_rotate_lookup_t
Opaque nearest-neighbor rotation lookup table.
struct sgl_bicubic_lookup_table sgl_bicubic_lookup_t
Opaque bicubic resize lookup table.
struct sgl_threadpool sgl_threadpool_t
Opaque synchronous worker-thread pool.
struct sgl_queue sgl_queue_t
Opaque fixed-capacity queue.
struct sgl_bilinear_lookup_table sgl_bilinear_lookup_t
Opaque bilinear resize lookup table.
sgl_result_t
Result codes returned by SGL operations.
void(* sgl_threadpool_routine_t)(void *current, void *cookie)
Processes one queue entry submitted to a thread pool.
struct sgl_nearest_neighbor_lookup_table sgl_nearest_neighbor_lookup_t
Opaque nearest-neighbor resize lookup table.
@ SGL_ERROR_INVALID_ARGUMENTS
One or more arguments violate the API contract.
@ SGL_QUEUE_IS_NOT_EMPTY
Queue contains at least one entry.
@ SGL_ERROR_MISSMATCHED_CAPACITY
Destination queue capacity is smaller than the source capacity.
@ SGL_QUEUE_IS_FULL
Queue has reached its fixed capacity.
@ SGL_FAILURE
Operation failed without a more specific code.
@ SGL_SUCCESS
Operation completed successfully.
@ SGL_QUEUE_IS_EMPTY
Queue contains no entries.
@ SGL_QUEUE_IS_NOT_FULL
Queue can accept another entry.
@ SGL_ERROR_NOT_SUPPORTED
Requested feature is unavailable in this build.
@ SGL_ERROR_MEMORY_ALLOCATION
The configured SGL memory pool could not satisfy an allocation.
Portable compiler attributes, branch hints, and prefetch helpers.
Standard and SGL-specific pixel-format identifiers.
sgl_uint32_t sgl_fourcc_t
32-bit pixel-format identifier created by SGL_FOURCC.
Runtime-independent scalar, pointer, size, and Boolean types.