diff --git a/20190128/gen-pbm-3.c b/20190128/gen-pbm-3.c new file mode 100644 index 0000000000000000000000000000000000000000..91c3193f06770efe8c928e46dadcef84e6d56b2e --- /dev/null +++ b/20190128/gen-pbm-3.c @@ -0,0 +1,21 @@ +#include <stdio.h> +#include <stdint.h> + +int main (void) +{ + int width = 16; + int height = 16; + FILE *f = fopen ("test.pbm", "w"); + fprintf (f, "P4\n%d %d\n", width, height); + + uint16_t data = 1; + for (int i = 0; i < 16; i++) + { + uint8_t right_half = data & 0x00ff; + uint8_t left_half = (data & 0xff00) >> 8; + fprintf (f, "%c%c", left_half, right_half); + data <<= 1; + } + + return 0; +} diff --git a/20190128/molpy-right.pbm b/20190128/molpy-right.pbm new file mode 100644 index 0000000000000000000000000000000000000000..ff1e9709d11c362c93230f19a194d87cfb43dfcb Binary files /dev/null and b/20190128/molpy-right.pbm differ diff --git a/20190128/show-pbm-1.c b/20190128/show-pbm-1.c new file mode 100644 index 0000000000000000000000000000000000000000..166b249e220c371467d1c9ec81324ba9330c1487 --- /dev/null +++ b/20190128/show-pbm-1.c @@ -0,0 +1,14 @@ +#include <stdio.h> + +int main (void) +{ + FILE *f = fopen ("test.pbm", "r"); + char id[42]; + int width, height; + fscanf (f, "%s", id); // should be "P4" + printf ("%s\n", id); + fscanf (f, "%d", &width); + fscanf (f, "%d", &height); + printf ("%d %d\n", width, height); + return 0; +} diff --git a/20190128/show-pbm-2.c b/20190128/show-pbm-2.c new file mode 100644 index 0000000000000000000000000000000000000000..0a268fb0e5f79c7fb5c91ddad48be3625e03983a --- /dev/null +++ b/20190128/show-pbm-2.c @@ -0,0 +1,29 @@ +#include <stdio.h> +#include <stdint.h> + +int main (void) +{ + FILE *f = fopen ("test.pbm", "r"); + char id[42]; + int width, height; + fscanf (f, "%s", id); // should be "P4" + fscanf (f, "%d", &width); + fscanf (f, "%d", &height); + + for (int y = 0; y < height; y++) + { + for (int x = 0; x < (width + 7) / 8; x++) + { + uint8_t data; + fscanf (f, "%c", &data); + for (int i = 0; i < 7; i++) + if (data & (1 << i)) + printf ("*"); + else + printf (" "); + } + printf ("\n"); + } + + return 0; +} diff --git a/20190128/show-pbm-3.c b/20190128/show-pbm-3.c new file mode 100644 index 0000000000000000000000000000000000000000..dc0547b3e0751ab71dd6e3b6db6f29a4ffa86a6e --- /dev/null +++ b/20190128/show-pbm-3.c @@ -0,0 +1,31 @@ +#include <stdio.h> +#include <stdint.h> + +int main (void) +{ + FILE *f = fopen ("test.pbm", "r"); + char id[42]; + int width, height; + fscanf (f, "%s", id); // should be "P4" + fscanf (f, "%d", &width); + fscanf (f, "%d", &height); + uint8_t dummy; + fscanf (f, "%c", &dummy); + + for (int y = 0; y < height; y++) + { + for (int x = 0; x < (width + 7) / 8; x++) + { + uint8_t data; + fscanf (f, "%c", &data); + for (int i = 0; i < 7; i++) + if (data & (1 << i)) + printf ("*"); + else + printf (" "); + } + printf ("\n"); + } + + return 0; +} diff --git a/20190128/show-pbm-4.c b/20190128/show-pbm-4.c new file mode 100644 index 0000000000000000000000000000000000000000..900896c1af6faf9327d98f0af34f14b653e0990d --- /dev/null +++ b/20190128/show-pbm-4.c @@ -0,0 +1,31 @@ +#include <stdio.h> +#include <stdint.h> + +int main (void) +{ + FILE *f = fopen ("test.pbm", "r"); + char id[42]; + int width, height; + fscanf (f, "%s", id); // should be "P4" + fscanf (f, "%d", &width); + fscanf (f, "%d", &height); + uint8_t dummy; + fscanf (f, "%c", &dummy); + + for (int y = 0; y < height; y++) + { + for (int x = 0; x < (width + 7) / 8; x++) + { + uint8_t data; + fscanf (f, "%c", &data); + for (int i = 7; i >= 0; i--) + if (data & (1 << i)) + printf ("*"); + else + printf (" "); + } + printf ("\n"); + } + + return 0; +} diff --git a/20190128/show-pbm-5.c b/20190128/show-pbm-5.c new file mode 100644 index 0000000000000000000000000000000000000000..593bb3643c5ca8cf2898dc674dc5097514f449af --- /dev/null +++ b/20190128/show-pbm-5.c @@ -0,0 +1,31 @@ +#include <stdio.h> +#include <stdint.h> + +int main (void) +{ + FILE *f = fopen ("molpy-right.pbm", "r"); + char id[42]; + int width, height; + fscanf (f, "%s", id); // should be "P4" + fscanf (f, "%d", &width); + fscanf (f, "%d", &height); + uint8_t dummy; + fscanf (f, "%c", &dummy); + + for (int y = 0; y < height; y++) + { + for (int x = 0; x < (width + 7) / 8; x++) + { + uint8_t data; + fscanf (f, "%c", &data); + for (int i = 7; i >= 0; i--) + if (data & (1 << i)) + printf ("*"); + else + printf (" "); + } + printf ("\n"); + } + + return 0; +} diff --git a/20190128/test.pbm b/20190128/test.pbm new file mode 100644 index 0000000000000000000000000000000000000000..6e2a28648e9a83bf66fef6d223f211540f835c81 Binary files /dev/null and b/20190128/test.pbm differ diff --git a/20190128/test.png b/20190128/test.png new file mode 100644 index 0000000000000000000000000000000000000000..aebf57c05ebe33327383a3d68d76cbdec22df883 Binary files /dev/null and b/20190128/test.png differ