#! /usr/bin/perl

while (<>) {
	if (/(\d+) (\d+) 1 .*image/) {
		$width = $1;
		$height = $2;
		last;
	}
}

printf "#define x_width %d\n", $width;
printf "#define x_height %d\n", $height;
printf "static unsigned char x_bits[] = {\n";

@bitconv = (0x00, 0x08, 0x04, 0x0c,
            0x02, 0x0a, 0x06, 0x0e,
            0x01, 0x09, 0x05, 0x0d,
            0x03, 0x0b, 0x07, 0x0f);

$n = 0;
while (<>) {
	chop;
	s/\015//g;
	if (/^showpage/) {
		print "};\n";
		last;
	}
	for ($i = 0; $i < length; $i += 2) {
		$bit = 0x00ff - hex(substr($_, $i, 2));
		$hi = $bitconv[$bit / 16];
		$lo = $bitconv[$bit % 16];
		printf "0x%1x", $lo;
		printf "%1x, ", $hi;
		if (++$n >= 8) {
			print "\n";
			$n = 0;
		}
	}
}
