summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rw-r--r--bin/gfxx.c55
1 files changed, 18 insertions, 37 deletions
diff --git a/bin/gfxx.c b/bin/gfxx.c
index 39f99ad2..23c71e3a 100644
--- a/bin/gfxx.c
+++ b/bin/gfxx.c
@@ -17,6 +17,7 @@
 #include <arpa/inet.h>
 #include <err.h>
 #include <fcntl.h>
+#include <math.h>
 #include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -43,41 +44,7 @@ static enum {
     COLOR__COUNT,
 } space = COLOR_RGB;
 static const char *COLOR__STR[COLOR__COUNT] = { "indexed", "grayscale", "rgb" };
-
-static uint32_t palette[256] = {
-    0xFF0000, 0xFF0600, 0xFF0C00, 0xFF1200, 0xFF1800, 0xFF1E00, 0xFF2400, 0xFF2A00,
-    0xFF3000, 0xFF3600, 0xFF3C00, 0xFF4200, 0xFF4800, 0xFF4E00, 0xFF5400, 0xFF5A00,
-    0xFF6000, 0xFF6600, 0xFF6C00, 0xFF7200, 0xFF7800, 0xFF7E00, 0xFF8300, 0xFF8900,
-    0xFF8F00, 0xFF9500, 0xFF9B00, 0xFFA100, 0xFFA700, 0xFFAD00, 0xFFB300, 0xFFB900,
-    0xFFBF00, 0xFFC500, 0xFFCB00, 0xFFD100, 0xFFD700, 0xFFDD00, 0xFFE300, 0xFFE900,
-    0xFFEF00, 0xFFF500, 0xFFFB00, 0xFDFF00, 0xF7FF00, 0xF1FF00, 0xEBFF00, 0xE5FF00,
-    0xDFFF00, 0xD9FF00, 0xD3FF00, 0xCDFF00, 0xC7FF00, 0xC1FF00, 0xBBFF00, 0xB5FF00,
-    0xAFFF00, 0xA9FF00, 0xA3FF00, 0x9DFF00, 0x97FF00, 0x91FF00, 0x8BFF00, 0x85FF00,
-    0x80FF00, 0x7AFF00, 0x74FF00, 0x6EFF00, 0x68FF00, 0x62FF00, 0x5CFF00, 0x56FF00,
-    0x50FF00, 0x4AFF00, 0x44FF00, 0x3EFF00, 0x38FF00, 0x32FF00, 0x2CFF00, 0x26FF00,
-    0x20FF00, 0x1AFF00, 0x14FF00, 0x0EFF00, 0x08FF00, 0x02FF00, 0x00FF04, 0x00FF0A,
-    0x00FF10, 0x00FF16, 0x00FF1C, 0x00FF22, 0x00FF28, 0x00FF2E, 0x00FF34, 0x00FF3A,
-    0x00FF40, 0x00FF46, 0x00FF4C, 0x00FF52, 0x00FF58, 0x00FF5E, 0x00FF64, 0x00FF6A,
-    0x00FF70, 0x00FF76, 0x00FF7C, 0x00FF81, 0x00FF87, 0x00FF8D, 0x00FF93, 0x00FF99,
-    0x00FF9F, 0x00FFA5, 0x00FFAB, 0x00FFB1, 0x00FFB7, 0x00FFBD, 0x00FFC3, 0x00FFC9,
-    0x00FFCF, 0x00FFD5, 0x00FFDB, 0x00FFE1, 0x00FFE7, 0x00FFED, 0x00FFF3, 0x00FFF9,
-    0x00FFFF, 0x00F9FF, 0x00F3FF, 0x00EDFF, 0x00E7FF, 0x00E1FF, 0x00DBFF, 0x00D5FF,
-    0x00CFFF, 0x00C9FF, 0x00C3FF, 0x00BDFF, 0x00B7FF, 0x00B1FF, 0x00ABFF, 0x00A5FF,
-    0x009FFF, 0x0099FF, 0x0093FF, 0x008DFF, 0x0087FF, 0x0081FF, 0x007CFF, 0x0076FF,
-    0x0070FF, 0x006AFF, 0x0064FF, 0x005EFF, 0x0058FF, 0x0052FF, 0x004CFF, 0x0046FF,
-    0x0040FF, 0x003AFF, 0x0034FF, 0x002EFF, 0x0028FF, 0x0022FF, 0x001CFF, 0x0016FF,
-    0x0010FF, 0x000AFF, 0x0004FF, 0x0200FF, 0x0800FF, 0x0E00FF, 0x1400FF, 0x1A00FF,
-    0x2000FF, 0x2600FF, 0x2C00FF, 0x3200FF, 0x3800FF, 0x3E00FF, 0x4400FF, 0x4A00FF,
-    0x5000FF, 0x5600FF, 0x5C00FF, 0x6200FF, 0x6800FF, 0x6E00FF, 0x7400FF, 0x7A00FF,
-    0x7F00FF, 0x8500FF, 0x8B00FF, 0x9100FF, 0x9700FF, 0x9D00FF, 0xA300FF, 0xA900FF,
-    0xAF00FF, 0xB500FF, 0xBB00FF, 0xC100FF, 0xC700FF, 0xCD00FF, 0xD300FF, 0xD900FF,
-    0xDF00FF, 0xE500FF, 0xEB00FF, 0xF100FF, 0xF700FF, 0xFD00FF, 0xFF00FB, 0xFF00F5,
-    0xFF00EF, 0xFF00E9, 0xFF00E3, 0xFF00DD, 0xFF00D7, 0xFF00D1, 0xFF00CB, 0xFF00C5,
-    0xFF00BF, 0xFF00B9, 0xFF00B3, 0xFF00AD, 0xFF00A7, 0xFF00A1, 0xFF009B, 0xFF0095,
-    0xFF008F, 0xFF0089, 0xFF0083, 0xFF007E, 0xFF0078, 0xFF0072, 0xFF006C, 0xFF0066,
-    0xFF0060, 0xFF005A, 0xFF0054, 0xFF004E, 0xFF0048, 0xFF0042, 0xFF003C, 0xFF0036,
-    0xFF0030, 0xFF002A, 0xFF0024, 0xFF001E, 0xFF0018, 0xFF0012, 0xFF000C, 0xFF0006,
-};
+static uint32_t palette[256];
 
 static enum {
     ENDIAN_LITTLE,
@@ -145,11 +112,25 @@ int init(int argc, char *argv[]) {
     if (pal) {
         FILE *file = fopen(pal, "r");
         if (!file) err(EX_NOINPUT, "%s", pal);
-
         fread(palette, 4, 256, file);
         if (ferror(file)) err(EX_IOERR, "%s", pal);
-
         fclose(file);
+    } else {
+        for (int i = 0; i < 256; ++i) {
+            double h = i * 360.0 / 256.0 / 60.0, s = 1.0, l = 0.5;
+            double c = (1.0 - fabs(2.0 * l - 1.0)) * s;
+            double x = c * (1.0 - fabs(fmod(h, 2.0) - 1.0));
+            double m = (l - c / 2.0);
+            double r = m, g = m, b = m;
+            if (h <= 1.0)      { r += c; g += x; }
+            else if (h <= 2.0) { r += x; g += c; }
+            else if (h <= 3.0) { g += c; b += x; }
+            else if (h <= 4.0) { g += x; b += c; }
+            else if (h <= 5.0) { r += x; b += c; }
+            else if (h <= 6.0) { r += c; b += x; }
+            r *= 255.0; g *= 255.0; b *= 255.0;
+            palette[i] = (uint32_t)r << 16 | (uint32_t)g << 8 | (uint32_t)b;
+        }
     }
 
     if (path) {