diff options
Diffstat (limited to '')
| -rw-r--r-- | libquanta_palette_size.c | 22 |
1 files changed, 22 insertions, 0 deletions
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; +} |
