Browse Source

Clean up scheme

Causal Agent 2 months ago
parent
commit
24476ead15
Signed by: Curtis McEnroe <june@causal.agency> GPG Key ID: CEA2F97ADCFCD77C
1 changed files with 33 additions and 29 deletions
  1. 33
    29
      bin/scheme.c

+ 33
- 29
bin/scheme.c View File

@@ -27,7 +27,11 @@
27 27
 typedef unsigned uint;
28 28
 typedef unsigned char byte;
29 29
 
30
-static const struct HSV { double h, s, v; }
30
+struct HSV {
31
+	double h, s, v;
32
+};
33
+
34
+static const struct HSV
31 35
 	R = {   0.0, 1.0, 1.0 },
32 36
 	Y = {  60.0, 1.0, 1.0 },
33 37
 	G = { 120.0, 1.0, 1.0 },
@@ -35,7 +39,11 @@ static const struct HSV { double h, s, v; }
35 39
 	B = { 240.0, 1.0, 1.0 },
36 40
 	M = { 300.0, 1.0, 1.0 };
37 41
 
38
-static struct RGB { byte r, g, b; } toRGB(struct HSV hsv) {
42
+struct RGB {
43
+	byte r, g, b;
44
+};
45
+
46
+static struct RGB rgb(struct HSV hsv) {
39 47
 	double c = hsv.v * hsv.s;
40 48
 	double h = hsv.h / 60.0;
41 49
 	double x = c * (1.0 - fabs(fmod(h, 2.0) - 1.0));
@@ -59,21 +67,9 @@ static struct HSV x(struct HSV o, double hd, double sf, double vf) {
59 67
 }
60 68
 
61 69
 enum {
62
-	Black,
63
-	Red,
64
-	Green,
65
-	Yellow,
66
-	Blue,
67
-	Magenta,
68
-	Cyan,
69
-	White,
70
-	Dark = 0,
71
-	Light = 8,
72
-	Background = 16,
73
-	Foreground,
74
-	Bold,
75
-	Selection,
76
-	Cursor,
70
+	Black, Red, Green, Yellow, Blue, Magenta, Cyan, White,
71
+	Dark = 0, Light = 8,
72
+	Background = 16, Foreground, Bold, Selection, Cursor,
77 73
 	SchemeLen,
78 74
 };
79 75
 static struct HSV scheme[SchemeLen];
@@ -117,8 +113,10 @@ static void printHSV(uint n) {
117 113
 }
118 114
 
119 115
 static void printRGB(uint n) {
120
-	struct RGB rgb = toRGB(scheme[n]);
121
-	printf("%02hhX%02hhX%02hhX\n", rgb.r, rgb.g, rgb.b);
116
+	printf(
117
+		"%02hhX%02hhX%02hhX\n",
118
+		rgb(scheme[n]).r, rgb(scheme[n]).g, rgb(scheme[n]).b
119
+	);
122 120
 }
123 121
 
124 122
 static const char *CNames[SchemeLen] = {
@@ -148,16 +146,20 @@ static void printCHead(void) {
148 146
 	printf("enum {\n");
149 147
 }
150 148
 static void printC(uint n) {
151
-	struct RGB rgb = toRGB(scheme[n]);
152
-	printf("\t%s = 0x%02hhX%02hhX%02hhX,\n", CNames[n], rgb.r, rgb.g, rgb.b);
149
+	printf(
150
+		"\t%s = 0x%02hhX%02hhX%02hhX,\n",
151
+		CNames[n], rgb(scheme[n]).r, rgb(scheme[n]).g, rgb(scheme[n]).b
152
+	);
153 153
 }
154 154
 static void printCTail(void) {
155 155
 	printf("};\n");
156 156
 }
157 157
 
158 158
 static void printLinux(uint n) {
159
-	struct RGB rgb = toRGB(scheme[n]);
160
-	printf("\x1B]P%X%02hhX%02hhX%02hhX", n, rgb.r, rgb.g, rgb.b);
159
+	printf(
160
+		"\x1B]P%X%02hhX%02hhX%02hhX",
161
+		n, rgb(scheme[n]).r, rgb(scheme[n]).g, rgb(scheme[n]).b
162
+	);
161 163
 }
162 164
 
163 165
 static const char *MinttyNames[SchemeLen] = {
@@ -183,8 +185,10 @@ static const char *MinttyNames[SchemeLen] = {
183 185
 };
184 186
 static void printMintty(uint n) {
185 187
 	if (!MinttyNames[n]) return;
186
-	struct RGB rgb = toRGB(scheme[n]);
187
-	printf("%s=%hhd,%hhd,%hhd\n", MinttyNames[n], rgb.r, rgb.g, rgb.b);
188
+	printf(
189
+		"%s=%hhu,%hhu,%hhu\n",
190
+		MinttyNames[n], rgb(scheme[n]).r, rgb(scheme[n]).g, rgb(scheme[n]).b
191
+	);
188 192
 }
189 193
 
190 194
 static void png(uint at, uint to) {
@@ -200,11 +204,11 @@ static void png(uint at, uint to) {
200 204
 
201 205
 	pngHead(stdout, width, height, 8, PNGIndexed);
202 206
 
203
-	struct RGB rgb[len];
207
+	struct RGB pal[len];
204 208
 	for (uint i = 0; i < len; ++i) {
205
-		rgb[i] = toRGB(scheme[at + i]);
209
+		pal[i] = rgb(scheme[at + i]);
206 210
 	}
207
-	pngPalette(stdout, (byte *)rgb, sizeof(rgb));
211
+	pngPalette(stdout, (byte *)pal, sizeof(pal));
208 212
 
209 213
 	uint8_t data[height][1 + width];
210 214
 	memset(data, 0, sizeof(data));
@@ -222,7 +226,7 @@ static void png(uint at, uint to) {
222 226
 	pngTail(stdout);
223 227
 }
224 228
 
225
-static void print(void (*fn)(uint), uint at, uint to) {
229
+static void print(void fn(uint), uint at, uint to) {
226 230
 	for (uint i = at; i < to; ++i) {
227 231
 		fn(i);
228 232
 	}

Loading…
Cancel
Save