diff tools/libgfx.c @ 2100:81fb21dd3265

Add dmGetNPlanesFromNColors() and use it.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 05 Mar 2019 15:09:18 +0200
parents e38705223ce4
children da886b8cbb09
line wrap: on
line diff
--- a/tools/libgfx.c	Tue Mar 05 14:51:02 2019 +0200
+++ b/tools/libgfx.c	Tue Mar 05 15:09:18 2019 +0200
@@ -91,6 +91,23 @@
 }
 
 
+int dmGetNPlanesFromNColors(const int ncolors)
+{
+    if (ncolors <= 0)
+        return -1;
+
+    for (int n = 8; n >= 0;)
+    {
+        if ((ncolors - 1) & (1 << n))
+            return n + 1;
+        else
+            n--;
+    }
+
+    return -2;
+}
+
+
 BOOL dmCompareColor(const DMColor *c1, const DMColor *c2, const BOOL alpha)
 {
     if (c1->r == c2->r &&