diff options
author | June McEnroe <june@causal.agency> | 2019-01-07 01:11:20 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2019-01-07 01:11:20 -0500 |
commit | 42fcb6656dd9b6c735b09ce61f8ce4e875329c43 (patch) | |
tree | 2c97aa115e449633218fea5d5be051530fe82f2c /image.c | |
parent | madvise MADV_NOCORE in image (diff) | |
download | torus-42fcb6656dd9b6c735b09ce61f8ce4e875329c43.tar.gz torus-42fcb6656dd9b6c735b09ce61f8ce4e875329c43.zip |
Compress PNG data in image
kcgi never enables compression for FastCGI.
Diffstat (limited to '')
-rw-r--r-- | image.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/image.c b/image.c index ef77906..38cd7cd 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"); |