summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--bin/gfxx.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/bin/gfxx.c b/bin/gfxx.c
index 6ad57e0a..184699b8 100644
--- a/bin/gfxx.c
+++ b/bin/gfxx.c
@@ -29,7 +29,6 @@
 #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 SCALE(b,n) ((b) ? (uint8_t)(255 * (uint32_t)(n) / MASK(b)) : 0)
 
 static enum {
     COLOR_INDEXED,
@@ -201,6 +200,12 @@ static void put(const struct Iter *it, uint32_t p) {
     }
 }
 
+static uint8_t interp(uint8_t b, uint32_t n) {
+    if (b == 8) return n;
+    if (b == 0) return 0;
+    return n * MASK(8) / MASK(b);
+}
+
 static uint32_t interpolate(uint32_t n) {
     uint32_t r, g, b;
     if (bitOrder == ENDIAN_LITTLE) {
@@ -212,7 +217,7 @@ static uint32_t interpolate(uint32_t n) {
         g = (n >>= bits[1]) & MASK(bits[2]);
         b = (n >>= bits[2]) & MASK(bits[3]);
     }
-    return RGB(SCALE(bits[1], r), SCALE(bits[2], g), SCALE(bits[3], b));
+    return RGB(interp(bits[1], r), interp(bits[2], g), interp(bits[3], b));
 }
 
 static void drawBits(struct Iter *it) {
@@ -227,7 +232,7 @@ static void drawBits(struct Iter *it) {
             if (space == COLOR_INDEXED) {
                 put(it, palette[n]);
             } else if (space == COLOR_GRAYSCALE) {
-                put(it, GRAY(SCALE(BITS_COLOR, n)));
+                put(it, GRAY(interp(BITS_COLOR, n & MASK(BITS_COLOR))));
             } else if (space == COLOR_RGB) {
                 put(it, interpolate(n));
             }
@@ -247,7 +252,7 @@ static void drawBytes(struct Iter *it) {
         if (space == COLOR_INDEXED) {
             put(it, palette[n & 0xFF]);
         } else if (space == COLOR_GRAYSCALE) {
-            put(it, GRAY(SCALE(BITS_COLOR, n & MASK(BITS_COLOR))));
+            put(it, GRAY(interp(BITS_COLOR, n & MASK(BITS_COLOR))));
         } else if (space == COLOR_RGB) {
             put(it, interpolate(n));
         }
/commit/bin/scheme.c?id=84d8034b9eb4301a5391ab771cd12b2f14405b18&follow=1'>Increase dark white brightness slightlyJune McEnroe 2021-01-13Add hilex example to htagml manualJune McEnroe 2021-01-12Style causal.agency like bin HTMLJune McEnroe 2021-01-12Avoid matching tag text inside HTML elementsJune McEnroe 2021-01-12Use hilex for up -hJune McEnroe 2021-01-12Use hilex for bin HTMLJune McEnroe 2021-01-12Don't output a pre in hilex by defaultJune McEnroe 2021-01-12Move hilex out of hilex directoryJune McEnroe 2021-01-12Consolidate hilex formatters into hilex.cJune McEnroe 2021-01-12Remove hacky tagging from hilexJune McEnroe 2021-01-12Add htagml -iJune McEnroe 2021-01-12Render tag index in HTMLJune McEnroe 2021-01-12Add htagml -xJune McEnroe 2021-01-12Prevent matching the same tag twiceJune McEnroe 2021-01-12Process htagml file line by lineJune McEnroe 2021-01-12Split fields by tab onlyJune McEnroe 2021-01-12List both Makefile and html.sh under README.7June McEnroe 2021-01-12Add htagml exampleJune McEnroe 2021-01-12Use mandoc and htagml for bin htmlJune McEnroe 2021-01-12Add htagmlJune McEnroe 2021-01-12Replace causal.agency with a simple mdoc pageJune McEnroe 2021-01-11Publish "Using vi"June McEnroe 2021-01-11Enable diff.colorMovedJune McEnroe 2021-01-10Set less search case-insensitiveJune McEnroe 2021-01-10Set EXINITJune McEnroe 2021-01-09Add c -t flag to print expression typeJune McEnroe 2021-01-05Update taglineJune McEnroe