aboutsummaryrefslogtreecommitdiffstats
path: root/libquanta_palette_size.c
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2025-11-23 21:33:38 +0100
committerMattias Andrée <m@maandree.se>2025-11-23 21:33:38 +0100
commit226d807bb8bc0cdbc011b2e616ac02881e74c542 (patch)
treee35bcc0f0b2bad8abfbb5da6db5580a813ca48bc /libquanta_palette_size.c
downloadlibquanta-226d807bb8bc0cdbc011b2e616ac02881e74c542.tar.gz
libquanta-226d807bb8bc0cdbc011b2e616ac02881e74c542.tar.bz2
libquanta-226d807bb8bc0cdbc011b2e616ac02881e74c542.tar.xz
First commit
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'libquanta_palette_size.c')
-rw-r--r--libquanta_palette_size.c22
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;
+}