Browse Source

Compress PNG data in image

kcgi never enables compression for FastCGI.
master
Causal Agent 10 months ago
parent
commit
b9551af817
Signed by: Curtis McEnroe <june@causal.agency> GPG Key ID: CEA2F97ADCFCD77C
4 changed files with 17 additions and 4 deletions
  1. 1
    1
      Makefile
  2. 8
    1
      image.c
  3. 1
    1
      kcgi.mk
  4. 7
    1
      png.h

+ 1
- 1
Makefile View File

@@ -3,7 +3,7 @@ CHROOT_GROUP = $(CHROOT_USER)

CFLAGS += -std=c11 -Wall -Wextra -Wpedantic
LDFLAGS = -static
LDLIBS = -lcursesw -lutil
LDLIBS = -lcursesw -lutil -lz

-include config.mk


+ 8
- 1
image.c View File

@@ -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");

+ 1
- 1
kcgi.mk View File

@@ -1,3 +1,3 @@
CFLAGS += -DHAVE_KCGI -I/usr/local/include
LDFLAGS += -L/usr/local/lib
LDLIBS += -lkcgi -lz
LDLIBS := -lkcgi $(LDLIBS)

+ 7
- 1
png.h View File

@@ -1,4 +1,4 @@
/* Copyright (C) 2018 Curtis McEnroe <june@causal.agency>
/* Copyright (C) 2018, 2019 C. McEnroe <june@causal.agency>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@@ -102,6 +102,12 @@ static inline void pngData(FILE *file, const uint8_t *data, uint32_t len) {
pngInt32(file, ~pngCRC);
}

static inline void pngDeflated(FILE *file, const uint8_t *data, uint32_t len) {
pngChunk(file, "IDAT", len);
pngWrite(file, data, len);
pngInt32(file, ~pngCRC);
}

static inline void pngTail(FILE *file) {
pngChunk(file, "IEND", 0);
pngInt32(file, ~pngCRC);

Loading…
Cancel
Save