summary refs log tree commit diff
path: root/bin/gfx
diff options
context:
space:
mode:
authorJune McEnroe <programble@gmail.com>2018-02-14 17:03:27 -0500
committerJune McEnroe <programble@gmail.com>2018-02-14 17:03:27 -0500
commitd98463186851545c7b6d1e90ea0bdf6d89626256 (patch)
tree065861d97ca21740b1446412d091288dbdeb28ca /bin/gfx
parentWrite newlines between watch iterations (diff)
downloadsrc-d98463186851545c7b6d1e90ea0bdf6d89626256.tar.gz
src-d98463186851545c7b6d1e90ea0bdf6d89626256.zip
Write at least 1 for each component of sBIT in gfxx
PNG requires each to be 0 < x <= depth. ImageMagick actually checks.
Diffstat (limited to '')
-rw-r--r--bin/gfxx.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/bin/gfxx.c b/bin/gfxx.c
index d3d9aa99..5bff4e5c 100644
--- a/bin/gfxx.c
+++ b/bin/gfxx.c
@@ -28,9 +28,11 @@
 #include <unistd.h>
 #include <zlib.h>
 
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#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,
@@ -351,7 +353,8 @@ static void pngDump(uint32_t *src, size_t srcWidth, size_t srcHeight) {
         pngWrite(options, strlen(options));
     }
     PNG_CHUNK("sBIT", 3) {
-        pngWrite(&bits[R], 3);
+        uint8_t sbit[3] = { MAX(bits[R], 1), MAX(bits[G], 1), MAX(bits[B], 1) };
+        pngWrite(sbit, sizeof(sbit));
     }
     PNG_CHUNK("IDAT", dataSize) {
         pngWrite(data, dataSize);