--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/make-gray50.c Mon Oct 16 00:49:43 2006 +0200
@@ -0,0 +1,125 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+
+static int width, height;
+static char bname[50] = "noname";
+static int perline = 13;
+
+static char mask[9] = { 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff };
+static char imask[9] = { 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff };
+
+void
+parameters(const int argn, char **argc)
+{
+ if (argn != 3)
+ {
+ fprintf(stderr, "usage: %s <width> <height>\n", argc[0]);
+ exit(1);
+ }
+
+ width = atoi(argc[1]);
+ height = atoi(argc[2]);
+}
+
+void
+writesize(int w, int h)
+{
+ printf("#define %s_width %i\n", bname, w);
+ printf("#define %s_height %i\n", bname, h);
+}
+
+char
+cstart(int p, int n)
+{
+ char c;
+
+ if (p==0)
+ c=0xaa;
+ else
+ c=0x55;
+
+ return c & mask[n];
+}
+
+char
+cend(int p, int n)
+{
+ char c;
+
+ if (p==0)
+ c=0xaa;
+ else
+ c=0x55;
+
+ return c & imask[n];
+}
+
+void
+writebits(int w, int h)
+{
+ int column;
+ int i;
+ int bits;
+ unsigned char c;
+ int pair; /* boolean */
+ int leftline;
+
+ printf("static char %s_bits[] = {\n", bname);
+
+ bits=w*h;
+ leftline=w;
+ i=0;
+ column=0;
+ pair=0;
+ while(i < bits)
+ {
+ if(column == 0)
+ putchar(' ');
+
+ /*fprintf(stderr, "leftline=%i\n", leftline);*/
+ if (leftline >= 8)
+ {
+ c = cstart(pair, 8);
+ printf("0x%2x", (unsigned int) c);
+ column++;
+ leftline -= 8;
+ i += 8;
+ }
+ else if (leftline > 0)
+ {
+ c = cend(pair, leftline);
+ pair ^= 1; /* 1->0, 0->1 */
+ c |= cstart(pair, 8 - leftline);
+ printf("0x%2x", (unsigned int) c);
+ i += leftline;
+ leftline = w;
+ column++;
+ }
+ else if (leftline == 0)
+ {
+ leftline = w;
+ pair ^= 1; /* 1->0, 0->1 */
+ }
+
+ if(i < bits && leftline != 0)
+ putchar(',');
+
+ if (column > perline && leftline != 0)
+ {
+ putchar('\n');
+ column = 0;
+ }
+
+ }
+
+ printf("};\n");
+}
+
+int main(int argn, char **argc)
+{
+ parameters(argn, argc);
+ writesize(width, height);
+ writebits(width, height);
+ return 0;
+}