summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-02-05 11:35:25 -0500
committerJune McEnroe <june@causal.agency>2018-02-05 11:35:25 -0500
commitfb5abc356be3cc6726101bd5879e16180bd04064 (patch)
treec3040217b5c5bfc383db059a34c7046dbde30a8e /bin
parentFix gfxx draw stop condition (diff)
downloadsrc-fb5abc356be3cc6726101bd5879e16180bd04064.tar.gz
src-fb5abc356be3cc6726101bd5879e16180bd04064.zip
Remove gfxx reverse option
Diffstat (limited to 'bin')
-rw-r--r--bin/gfxx.c40
1 files changed, 14 insertions, 26 deletions
diff --git a/bin/gfxx.c b/bin/gfxx.c
index 840c0e9b..cb0341aa 100644
--- a/bin/gfxx.c
+++ b/bin/gfxx.c
@@ -43,7 +43,6 @@ static uint32_t palette[256] = {
 #undef X
 };
 
-static bool reverse;
 static size_t offset;
 
 static size_t width = 16;
@@ -53,14 +52,6 @@ static size_t scale = 1;
 static size_t size = 1024 * 1024; // max from pipe.
 static uint8_t *data;
 
-static uint8_t get(size_t i) {
-    if (reverse) {
-        return data[size - i - 1];
-    } else {
-        return data[i];
-    }
-}
-
 extern int init(int argc, char *argv[]) {
     const char *path = NULL;
     const char *palPath = NULL;
@@ -77,7 +68,6 @@ extern int init(int argc, char *argv[]) {
             case 'p': palPath  = optarg; break;
             case 'b': bits     = strtoul(optarg, NULL, 0); break;
             case 'e': endian  ^= true; break;
-            case 'r': reverse ^= true; break;
             case 'n': offset   = strtoul(optarg, NULL, 0); break;
             case 'w': width    = strtoul(optarg, NULL, 0); break;
             case 'm': mirror  ^= true; break;
@@ -121,11 +111,10 @@ extern int init(int argc, char *argv[]) {
 
 static void printOpts(void) {
     printf(
-        "gfxx -c %c -b %hhu %s%s-n %#zx -w %zu %s-z %zu\n",
+        "gfxx -c %c -b %hhu %s-n %#zx -w %zu %s-z %zu\n",
         "gpr"[space],
         bits,
         endian ? "-e " : "",
-        reverse ? "-r " : "",
         offset,
         width,
         mirror ? "-m " : "",
@@ -184,7 +173,7 @@ static void put(const struct Pos *pos, uint32_t p) {
 static void drawBits(struct Pos *pos) {
     for (size_t i = offset; i < size; ++i) {
         for (int s = 0; s < 8; s += bits) {
-            uint8_t n = get(i) >> (endian ? 8 - bits - s : s) & MASK(bits);
+            uint8_t n = data[i] >> (endian ? 8 - bits - s : s) & MASK(bits);
             if (space == COLOR_PALETTE) {
                 put(pos, palette[n]);
             } else if (space == COLOR_RGB && bits == 4) {
@@ -200,13 +189,13 @@ static void drawBits(struct Pos *pos) {
 static void draw8(struct Pos *pos) {
     for (size_t i = offset; i < size; ++i) {
         if (space == COLOR_GRAYSCALE) {
-            put(pos, GRAY(get(i)));
+            put(pos, GRAY(data[i]));
         } else if (space == COLOR_PALETTE) {
-            put(pos, palette[get(i)]);
+            put(pos, palette[data[i]]);
         } else {
-            uint32_t r = (endian ? get(i) >> 5 : get(i) >> 0) & MASK(3);
-            uint32_t g = (endian ? get(i) >> 2 : get(i) >> 3) & MASK(3);
-            uint32_t b = (endian ? get(i) >> 0 : get(i) >> 6) & MASK(2);
+            uint32_t r = (endian ? data[i] >> 5 : data[i] >> 0) & MASK(3);
+            uint32_t g = (endian ? data[i] >> 2 : data[i] >> 3) & MASK(3);
+            uint32_t b = (endian ? data[i] >> 0 : data[i] >> 6) & MASK(2);
             put(pos, RGB(SCALE(3, r), SCALE(3, g), SCALE(2, b)));
         }
         if (!next(pos)) break;
@@ -216,8 +205,8 @@ static void draw8(struct Pos *pos) {
 static void draw16(struct Pos *pos) {
     for (size_t i = offset; i + 1 < size; i += 2) {
         uint16_t n = (endian)
-            ? (uint16_t)get(i+0) << 8 | (uint16_t)get(i+1)
-            : (uint16_t)get(i+1) << 8 | (uint16_t)get(i+0);
+            ? (uint16_t)data[i+0] << 8 | (uint16_t)data[i+1]
+            : (uint16_t)data[i+1] << 8 | (uint16_t)data[i+0];
         uint32_t r = n >> 11 & MASK(5);
         uint32_t g = n >>  5 & MASK(6);
         uint32_t b = n >>  0 & MASK(5);
@@ -229,9 +218,9 @@ static void draw16(struct Pos *pos) {
 static void draw24(struct Pos *pos) {
     for (size_t i = offset; i + 2 < size; i += 3) {
         if (endian) {
-            put(pos, RGB(get(i + 0), get(i + 1), get(i + 2)));
+            put(pos, RGB(data[i + 0], data[i + 1], data[i + 2]));
         } else {
-            put(pos, RGB(get(i + 2), get(i + 1), get(i + 0)));
+            put(pos, RGB(data[i + 2], data[i + 1], data[i + 0]));
         }
         if (!next(pos)) break;
     }
@@ -240,9 +229,9 @@ static void draw24(struct Pos *pos) {
 static void draw32(struct Pos *pos) {
     for (size_t i = offset; i + 3 < size; i += 4) {
         if (endian) {
-            put(pos, RGB(get(i + 1), get(i + 2), get(i + 3)));
+            put(pos, RGB(data[i + 1], data[i + 2], data[i + 3]));
         } else {
-            put(pos, RGB(get(i + 2), get(i + 1), get(i + 0)));
+            put(pos, RGB(data[i + 2], data[i + 1], data[i + 0]));
         }
         if (!next(pos)) break;
     }
@@ -277,13 +266,13 @@ extern void input(char in) {
     size_t row = width * bits / 8;
     switch (in) {
         case 'q': printOpts(); exit(EX_OK);
+        break; case 'o': printOpts();
         break; case '[': if (!space--) space = COLOR__MAX - 1;
         break; case ']': if (++space == COLOR__MAX) space = 0;
         break; case 'p': samplePalette();
         break; case '{': if (bits > 16) bits -= 8; else bits = (bits + 1) / 2;
         break; case '}': if (bits < 16) bits *= 2; else if (bits < 32) bits += 8;
         break; case 'e': endian ^= true;
-        break; case 'r': reverse ^= true;
         break; case 'h': if (offset) offset--;
         break; case 'j': offset += pixel;
         break; case 'k': if (offset >= pixel) offset -= pixel;
@@ -300,5 +289,4 @@ extern void input(char in) {
         break; case '+': scale++;
         break; case '-': if (scale > 1) scale--;
     }
-    printOpts();
 }