summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--bin/gfxx.c57
1 files changed, 26 insertions, 31 deletions
diff --git a/bin/gfxx.c b/bin/gfxx.c
index 50de64c9..4674c82f 100644
--- a/bin/gfxx.c
+++ b/bin/gfxx.c
@@ -28,9 +28,9 @@
 #include <unistd.h>
 #include <zlib.h>
 
-#define RGB(r,g,b) ((uint32_t)(r) << 16 | (uint32_t)(g) << 8 | (uint32_t)(b))
-#define GRAY(n)    RGB(n, n, n)
-#define MASK(b)    ((1 << (b)) - 1)
+#define RGB(r, g, b) ((uint32_t)(r) << 16 | (uint32_t)(g) << 8 | (uint32_t)(b))
+#define GRAY(n) RGB(n, n, n)
+#define MASK(b) ((1 << (b)) - 1)
 
 static enum {
     COLOR_INDEXED,
@@ -302,11 +302,12 @@ static void pngUint32(uint32_t data) {
     uint32_t net = htonl(data);
     pngWrite(&net, 4);
 }
-static void pngChunk(const char *type, uint32_t size) {
-    pngUint32(size);
-    crc = crc32(0, Z_NULL, 0);
-    pngWrite(type, 4);
-}
+
+#define ONCE(before, after) for (int _once = ((before), 1); _once; (after), --_once)
+#define PNG_CHUNK(type, size) ONCE( \
+    (pngUint32((size)), crc = crc32(0, Z_NULL, 0), pngWrite((type), 4)), \
+    pngUint32(crc) \
+)
 
 static void pngDump(uint32_t *src, size_t srcWidth, size_t srcHeight) {
     int error;
@@ -337,31 +338,25 @@ static void pngDump(uint32_t *src, size_t srcWidth, size_t srcHeight) {
     const uint8_t HEADER[] = { 8, 2, 0, 0, 0 }; // 8-bit RGB
     const char SOFTWARE[] = "Software";
 
-    size_t count = fwrite(SIGNATURE, sizeof(SIGNATURE), 1, png);
-    if (count < 1) err(EX_IOERR, "%s", pngPath);
-
-    pngChunk("IHDR", 4 + 4 + sizeof(HEADER));
-    pngUint32(srcWidth);
-    pngUint32(srcHeight);
-    pngWrite(HEADER, sizeof(HEADER));
-    pngUint32(crc);
-
     formatOptions();
-    pngChunk("tEXt", sizeof(SOFTWARE) + strlen(options));
-    pngWrite(SOFTWARE, sizeof(SOFTWARE));
-    pngWrite(options, strlen(options));
-    pngUint32(crc);
-
-    pngChunk("sBIT", 3);
-    pngWrite(&bits[R], 3);
-    pngUint32(crc);
 
-    pngChunk("IDAT", dataSize);
-    pngWrite(data, dataSize);
-    pngUint32(crc);
-
-    pngChunk("IEND", 0);
-    pngUint32(crc);
+    pngWrite(SIGNATURE, sizeof(SIGNATURE));
+    PNG_CHUNK("IHDR", 4 + 4 + sizeof(HEADER)) {
+        pngUint32(srcWidth);
+        pngUint32(srcHeight);
+        pngWrite(HEADER, sizeof(HEADER));
+    }
+    PNG_CHUNK("tEXt", sizeof(SOFTWARE) + strlen(options)) {
+        pngWrite(SOFTWARE, sizeof(SOFTWARE));
+        pngWrite(options, strlen(options));
+    }
+    PNG_CHUNK("sBIT", 3) {
+        pngWrite(&bits[R], 3);
+    }
+    PNG_CHUNK("IDAT", dataSize) {
+        pngWrite(data, dataSize);
+    }
+    PNG_CHUNK("IEND", 0);
 
     error = fclose(png);
     if (error) err(EX_IOERR, "%s", pngPath);
td class='logsubject'>Remove wiki scriptJune McEnroe Wikipedia seems to have removed the one-sentence extracts from the opensearch results. Too bad. It's not a wiki script, what we need is a command that fetches single-sentence summaries of articles on Wikipedia. 2020-02-19Add The Obelisk GateJune McEnroe 2020-02-17Add Four Tet — HandsJune McEnroe One from the cafe that caught my attention. 2020-02-12Simplify macOS notify-sendJune McEnroe 2020-02-12Add imbox and notemap to pageJune McEnroe 2020-02-12Collapse simple linksJune McEnroe 2020-02-12Move catgirl up the pageJune McEnroe 2020-02-12Update catgirl pty grabJune McEnroe 2020-02-12Link to cgit /about pages where appropriateJune McEnroe 2020-02-11Separate LINKS from BINS for html to workJune McEnroe 2020-02-11Add margin to Bl-bullet itemsJune McEnroe 2020-02-10Match URLs inside parens or with paired parens insideJune McEnroe 2020-02-10Duplicate effective URL before passing it back to curlJune McEnroe Apparently sometimes it didn't like receiving its own internal storage to parse again. Understandable. 2020-02-09Add To Be Taught, If FortunateJune McEnroe 2020-02-04Add The Future of Another TimelineJune McEnroe Wow. One of the best I've read. 2020-01-31Reorganize the Makefile for the umpteenth timeJune McEnroe Broke out LDLIBS for each bin, and made everything more uniform. 2020-01-28Change scout sensitivity to 1.4June McEnroe idk it seems to work. 2020-01-28Import shows.txtJune McEnroe