Common Buffer Rules
Resize, crop, and rotate operate on packed pixels with a caller-supplied positive byte count per pixel. Their source size is width * height * bpp. Conversion uses the FourCC-specific formulas in Pixel Formats and Buffer Sizes. All image buffers are caller-owned and source/destination ranges must not overlap.
Resize
Create one LUT when the same source and destination dimensions are used for multiple frames. The LUT does not depend on pixel channel order or bpp.
dst_width, dst_height, src_width, src_height);
}
else {
pool, lut,
dst, dst_width, dst_height,
src, src_width, src_height,
}
void sgl_generic_destroy_bilinear_lut(sgl_bilinear_lookup_t *lut)
Destroys a bilinear LUT.
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.
#define SGL_NULL
Null pointer constant for public SGL interfaces.
struct sgl_bilinear_lookup_table sgl_bilinear_lookup_t
Opaque bilinear resize lookup table.
sgl_result_t
Result codes returned by SGL operations.
@ SGL_ERROR_MEMORY_ALLOCATION
The configured SGL memory pool could not satisfy an allocation.
#define SGL_BPP32
Four bytes per pixel.
Pass SGL_NULL as the LUT for one-shot work. SGL then allocates and destroys a temporary table. Nearest-neighbor is fastest and preserves exact source pixel values; bilinear smooths a 2x2 neighborhood; bicubic uses a 4x4 neighborhood.
Crop
Crop coordinates are zero-based and the complete rectangle must fit inside the source image. The destination has no source stride or padding:
pool,
src, src_width, src_height,
dst,
crop_x, crop_y, crop_width, crop_height,
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.
Allocate at least crop_width * crop_height * bpp destination bytes.
Rotate
Query dimensions before allocating the caller-owned destination. Positive angles rotate clockwise. Output pixels outside the source footprint are zero.
src_width, src_height, angle,
&dst_width, &dst_height);
pool, rotate_lut,
src, src_width, src_height,
}
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.
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_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.
signed int sgl_int32_t
Signed integer with exactly 32 value bits.
@ SGL_SUCCESS
Operation completed successfully.
A rotation LUT can be shared by generic and SIMD calls and reused across frames only when source dimensions and normalized angle are identical.
Convert
Choose the entry point from the source and destination format categories:
pool,
width, height);
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.
Every supported source format can be converted to every supported destination format in the selected category. When adding alpha to RGB, SGL writes 255; when removing alpha or converting to YUV, it discards alpha.
Generic and SIMD Backends
Generic functions are always declared. SIMD functions are declared only when SGL_CFG_HAS_SIMD is enabled in the generated sgl-config.h. Keep portable fallback selection at compile time:
#if defined(SGL_CFG_HAS_SIMD)
result =
sgl_simd_crop(pool, src, width, height, dst, x, y, cw, ch, bpp);
#else
#endif
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.