/* 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; }