Made program to create gray50 bitmaps.
authorviric@llimona
Mon, 16 Oct 2006 00:49:43 +0200
changeset 0 2b12eedda295
child 1 c36976fd28f3
Made program to create gray50 bitmaps.
Makefile
gamma.tk
make-gray50.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile	Mon Oct 16 00:49:43 2006 +0200
@@ -0,0 +1,5 @@
+gray50.xbm: make-gray50
+	./make-gray50 400 400 > gray50.xbm
+
+make-gray50: make-gray50.o
+make-gray50.o: make-gray50.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gamma.tk	Mon Oct 16 00:49:43 2006 +0200
@@ -0,0 +1,16 @@
+#!/bin/wish
+
+frame .leftcol
+label .leftcol.c -height 100 -width 50 -bg #12f -bitmap @gray50.xbm
+pack .leftcol.c
+frame .centercol
+button .centercol.b -height 100 -width 50 -bg #f21 -fg #f21 -bitmap gray50
+pack .centercol.b
+frame .rightcol
+label .rightcol.c -height 100 -width 50 -bg #5f6 -bitmap @gray50.xbm
+pack .rightcol.c
+
+pack .leftcol -side left
+pack .centercol -side left
+pack .rightcol -side left
+
--- /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;
+}