From ee1f6c47e1eff920068f4bceaf604f9535a2e8a9 Mon Sep 17 00:00:00 2001 From: Wojciech Kosior Date: Tue, 1 Sep 2020 10:54:59 +0200 Subject: start anew --- tools/VGAdump2ppm.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tools/VGAdump2ppm.c (limited to 'tools') diff --git a/tools/VGAdump2ppm.c b/tools/VGAdump2ppm.c new file mode 100644 index 0000000..0c91891 --- /dev/null +++ b/tools/VGAdump2ppm.c @@ -0,0 +1,45 @@ +#include +#include + +int main(int argc, char **argv) +{ + uint8_t color_value = 0; + uint8_t bits_read = 0; + uint8_t channels_read = 0; + int pixels_processed = 0; + int input; + + /* http://netpbm.sourceforge.net/doc/ppm.html */ + puts("P3"); + puts("640 480"); + puts("7"); + + while (1) { + input = getchar(); + + if (input == EOF) + break; + + if (input != '1' && input != '0') + continue; + + if (input == '1') + color_value |= 1 << (2 - bits_read); + + if (++bits_read == 3) { + printf(" %d", color_value); + + color_value = 0; + bits_read = 0; + + if (++channels_read == 3) { + channels_read = 0; + + putchar(++pixels_processed % 8 == 0 ? + '\n' : ' '); + } + } + } + + return 0; +} -- cgit v1.2.3