summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-10-02 12:19:48 -0400
committerJune McEnroe <june@causal.agency>2018-10-02 12:19:48 -0400
commiteee7dfd3c97e9e6a8193e4ff54235bc813abb3bc (patch)
treee0509ed9bd602cb5533e952f87d31592d98aa2a9
parentAdd some '80s music notes (diff)
downloadsrc-eee7dfd3c97e9e6a8193e4ff54235bc813abb3bc.tar.gz
src-eee7dfd3c97e9e6a8193e4ff54235bc813abb3bc.zip
Allow setting colors in psf2png
-rw-r--r--bin/man/psf2png.114
-rw-r--r--bin/psf2png.c15
2 files changed, 26 insertions, 3 deletions
diff --git a/bin/man/psf2png.1 b/bin/man/psf2png.1
index bbabd484..288834dc 100644
--- a/bin/man/psf2png.1
+++ b/bin/man/psf2png.1
@@ -8,7 +8,9 @@
 .
 .Sh SYNOPSIS
 .Nm
+.Op Fl b Ar bg
 .Op Fl c Ar cols
+.Op Fl f Ar fg
 .Op Fl s Ar str
 .Op Ar file
 .
@@ -23,11 +25,23 @@ on standard output.
 .Pp
 The arguments are as follows:
 .Bl -tag -width Ds
+.It Fl b Ar bg
+Use
+.Ar bg
+(hexadecimal RGB)
+as background color.
+The default background color is black.
 .It Fl c Ar cols
 Arrange glyphs in
 .Ar cols
 columns.
 The default number of columns is 32.
+.It Fl f Ar fg
+Use
+.Ar fg
+(hexadecimal RGB)
+as foreground color.
+The default foreground color is white.
 .It Fl s Ar str
 Render glyphs for string
 .Ar str
diff --git a/bin/psf2png.c b/bin/psf2png.c
index eee4e1a9..0ff3c9ac 100644
--- a/bin/psf2png.c
+++ b/bin/psf2png.c
@@ -43,11 +43,15 @@ static void pngChunk(const char *type, uint32_t size) {
 int main(int argc, char *argv[]) {
 	uint32_t cols = 32;
 	const char *str = NULL;
+	uint32_t fg = 0xFFFFFF;
+	uint32_t bg = 0x000000;
 
 	int opt;
-	while (0 < (opt = getopt(argc, argv, "c:s:"))) {
+	while (0 < (opt = getopt(argc, argv, "b:c:f:s:"))) {
 		switch (opt) {
+			break; case 'b': bg = strtoul(optarg, NULL, 16);
 			break; case 'c': cols = strtoul(optarg, NULL, 0);
+			break; case 'f': fg = strtoul(optarg, NULL, 16);
 			break; case 's': str = optarg;
 			break; default:  return EX_USAGE;
 		}
@@ -97,7 +101,12 @@ int main(int argc, char *argv[]) {
 	pngChunk("IHDR", 13);
 	pngInt(width);
 	pngInt(height);
-	pngWrite("\x08\x00\x00\x00\x00", 5);
+	pngWrite("\x08\x03\x00\x00\x00", 5);
+	pngInt(crc);
+
+	pngChunk("PLTE", 6);
+	pngWrite((uint8_t[]) { bg >> 16, bg >> 8, bg }, 3);
+	pngWrite((uint8_t[]) { fg >> 16, fg >> 8, fg }, 3);
 	pngInt(crc);
 
 	uint8_t data[height][1 + width];
@@ -110,7 +119,7 @@ int main(int argc, char *argv[]) {
 		for (uint32_t y = 0; y < header.glyph.height; ++y) {
 			for (uint32_t x = 0; x < header.glyph.width; ++x) {
 				uint8_t bit = glyphs[g][y][x / 8] >> (7 - x % 8) & 1;
-				data[row + y][col + x] = -bit;
+				data[row + y][col + x] = bit;
 			}
 		}
 	}