commit 92ca84cdf5c13181a2d54b3514d021d090cbc39e
parent 0672eddc1d4c16fff3d63e7f6e30b8a71029c2f8
Author: Pollux <pollux@pollux.codes>
Date: Sat, 19 Jul 2025 16:31:35 -0500
feat: Generate larger palette
Signed-off-by: Pollux <pollux@pollux.codes>
Diffstat:
M | morph.c | | | 36 | +++++++++++++++++++++++++++++++++--- |
1 file changed, 33 insertions(+), 3 deletions(-)
diff --git a/morph.c b/morph.c
@@ -8,6 +8,8 @@
#include <Imlib2.h>
+#define PRIMARY_COLOR_COUNT 32
+
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
@@ -283,6 +285,21 @@ cluster_image_colors(col_lab_t *colors, int color_count, int cluster_count) {
return cluster_colors;
}
+col_lab_t
+hue_shift(col_lab_t in, float angle) {
+
+ col_lab_t out;
+
+ float cos = cosf(angle);
+ float sin = sinf(angle);
+
+ out.l = in.l;
+ out.a = cos * in.a - sin * in.b;
+ out.b = sin * in.a + cos * in.b;
+
+ return out;
+}
+
int
main(int argc, char **argv) {
@@ -300,9 +317,22 @@ main(int argc, char **argv) {
}
col_lab_t *primary_colors =
- cluster_image_colors(image_pixels_lab, pixel_count, 128);
-
- // TODO: Combine primary colors with copies rotated in hue.
+ cluster_image_colors(image_pixels_lab, pixel_count,
+ PRIMARY_COLOR_COUNT);
+
+ col_lab_t palette[PRIMARY_COLOR_COUNT * 4];
+ float palette_weights[PRIMARY_COLOR_COUNT * 4];
+
+ for(int c = 0; c < PRIMARY_COLOR_COUNT; c++) {
+ palette[4 * c] = primary_colors[c];
+ palette_weights[4 * c] = 1;
+ palette[4 * c + 1] = hue_shift(primary_colors[c], M_PI);
+ palette_weights[4 * c] = 0.5;
+ palette[4 * c + 2] = hue_shift(primary_colors[c], M_PI / 6);
+ palette_weights[4 * c] = 0.3;
+ palette[4 * c + 3] = hue_shift(primary_colors[c], -M_PI / 6);
+ palette_weights[4 * c] = 0.3;
+ }
// TODO: Match colors with target colors