13 if (!out_pixel_count) {
18 if (width == 0 || height == 0) {
23 if (height > SIZE_MAX / width) {
27 *out_pixel_count = width * height;
36 if (pixel_count == 0) {
40 if (bytes_per_pixel == 0) {
45 if (pixel_count > SIZE_MAX / bytes_per_pixel) {
50 *out_size = pixel_count * bytes_per_pixel;
84 size_t pixel_buffer_size;
91 if (pixel_buffer_size > SIZE_MAX - struct_size) {
96 *out_size = struct_size + pixel_buffer_size;
102 if (width == 0 || height == 0) {
#define SET_ERRNO(code, context_msg,...)
Set error code with custom context message and log it.
asciichat_error_t
Error and exit codes - unified status values (0-255)
#define IMAGE_MAX_WIDTH
Maximum image width (4K resolution)
#define IMAGE_MAX_PIXELS_SIZE
Maximum pixel data size in bytes.
#define IMAGE_MAX_HEIGHT
Maximum image height (4K resolution)
Application limits and constraints.
asciichat_error_t image_validate_buffer_size(size_t requested_size)
Validate buffer size against maximum allocation limit.
asciichat_error_t image_validate_dimensions(size_t width, size_t height)
Validate image dimensions (non-zero, within limits)
asciichat_error_t image_calc_pixel_buffer_size(size_t pixel_count, size_t bytes_per_pixel, size_t *out_size)
Calculate pixel buffer size with overflow checking.
asciichat_error_t image_calc_pixel_count(size_t width, size_t height, size_t *out_pixel_count)
Calculate pixel count with overflow checking.
asciichat_error_t image_calc_rgb_size(size_t width, size_t height, size_t *out_size)
Calculate total RGB buffer size from dimensions.
asciichat_error_t image_calc_total_allocation(size_t width, size_t height, size_t struct_size, size_t bytes_per_pixel, size_t *out_size)
Calculate combined size of image struct + pixel buffer.
Image Data Structures and Operations.