about summary refs log tree commit diff homepage
path: root/image.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-01-07 01:11:20 -0500
committerJune McEnroe <june@causal.agency>2019-01-07 01:11:20 -0500
commitb9551af817e9a2ba90289d9c7de0e4a34f92287d (patch)
tree53f6c362880a641d028dba50d53a5959e9cd9b96 /image.c
parentmadvise MADV_NOCORE in image (diff)
downloadtorus-b9551af817e9a2ba90289d9c7de0e4a34f92287d.tar.gz
torus-b9551af817e9a2ba90289d9c7de0e4a34f92287d.zip
Compress PNG data in image
kcgi never enables compression for FastCGI.
Diffstat (limited to '')
-rw-r--r--image.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/image.c b/image.c
index de27349..80bb2de 100644
--- a/image.c
+++ b/image.c
@@ -25,6 +25,7 @@
 #include <sys/stat.h>
 #include <sysexits.h>
 #include <unistd.h>
+#include <zlib.h>
 
 #ifdef __FreeBSD__
 #include <sys/capsicum.h>
@@ -158,7 +159,12 @@ static void render(FILE *stream, uint32_t tileX, uint32_t tileY) {
 		}
 	}
 
-	pngData(stream, (uint8_t *)data, sizeof(data));
+	uLong zlen = compressBound(sizeof(data));
+	uint8_t zdata[zlen];
+	int error = compress(zdata, &zlen, (uint8_t *)data, sizeof(data));
+	if (error) errx(EX_SOFTWARE, "compress: %d", error);
+
+	pngDeflated(stream, zdata, (size_t)zlen);
 	pngTail(stream);
 }
 
@@ -229,6 +235,7 @@ static void worker(void) {
 		if (error == KCGI_HUP) goto next;
 		if (error) errkcgi(EX_IOERR, error, "khttp_head");
 
+		// XXX: kcgi never enables compression for FastCGI.
 		error = khttp_body(&req);
 		if (error == KCGI_HUP) goto next;
 		if (error) errkcgi(EX_IOERR, error, "khttp_body");