From 226d807bb8bc0cdbc011b2e616ac02881e74c542 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 23 Nov 2025 21:33:38 +0100 Subject: First commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libquanta_palette_size.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 libquanta_palette_size.c (limited to 'libquanta_palette_size.c') diff --git a/libquanta_palette_size.c b/libquanta_palette_size.c new file mode 100644 index 0000000..e8b95eb --- /dev/null +++ b/libquanta_palette_size.c @@ -0,0 +1,22 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +int +libquanta_palette_size(size_t ncolours, size_t nchannels, size_t *size_out) +{ + if (!ncolours || !nchannels) { + errno = EINVAL; + return -1; + } + + if (ncolours > (SIZE_MAX - PALETTE_BASE_SIZE) / PALETTE_VALUE_SIZE / nchannels) { + errno = EOVERFLOW; + return -1; + } + + if (size_out) + *size_out = PALETTE_BASE_SIZE + ncolours * nchannels * PALETTE_VALUE_SIZE; + + return 0; +} -- cgit v1.2.3-70-g09d2