93main (
int argc, 
char **argv)
 
  107   int plane_array[0x10000][16];
 
  109   void gethex     (
char *instring, 
int plane_array[0x10000][16], 
int plane);
 
  110   void genlongbmp (
int plane_array[0x10000][16], 
int dpi, 
int tinynum,
 
  112   void genwidebmp (
int plane_array[0x10000][16], 
int dpi, 
int tinynum,
 
  116      for (i = 1; i < argc; i++) {
 
  117         if (strncmp (argv[i],
"-l",2) == 0) { 
 
  120         else if (strncmp (argv[i],
"-d",2) == 0) {
 
  121            dpi = atoi (&argv[i][2]); 
 
  123         else if (strncmp (argv[i],
"-t",2) == 0) {
 
  126         else if (strncmp (argv[i],
"-P",2) == 0) {
 
  128            for (j = 2; argv[i][j] != 
'\0'; j++) {
 
  129               if (argv[i][j] < 
'0' || argv[i][j] > 
'9') {
 
  131                           "ERROR: Specify Unicode plane as decimal number.\n\n");
 
  135            plane = atoi (&argv[i][2]); 
 
  136            if (plane < 0 || plane > 17) {
 
  138                        "ERROR: Plane out of Unicode range [0,17].\n\n");
 
  149   for (i = 0; i < 128; i++) {
 
  152      for (j = 0; j < 16; j++) 
ascii_bits[i][j] = plane_array[i][j];
 
  159   memset ((
void *)plane_array, 0, 0x10000 * 16 * 
sizeof (
int));
 
  160   while (fgets (instring, 
MAXSTRING, stdin) != NULL) {
 
  161      gethex (instring, plane_array, plane); 
 
  169      genwidebmp (plane_array, dpi, tinynum, plane);
 
  172      genlongbmp (plane_array, dpi, tinynum, plane);
 
  188   putchar ( thisword        & 0xFF);
 
  189   putchar ((thisword >>  8) & 0xFF);
 
  190   putchar ((thisword >> 16) & 0xFF);
 
  191   putchar ((thisword >> 24) & 0xFF);
 
  206   putchar ( thisword       & 0xFF);
 
  207   putchar ((thisword >> 8) & 0xFF);
 
  224gethex (
char *instring, 
int plane_array[0x10000][16], 
int plane)
 
  239   sscanf (instring, 
"%X", &codept);
 
  240   glyph_plane = codept >> 16;
 
  241   if (glyph_plane == plane) {
 
  244      for (i = 0; (i < 9) && (instring[i] != 
':'); i++);
 
  246      bitstring = &instring[i];
 
  247      ndigits = strlen (bitstring);
 
  249      if (bitstring[ndigits - 1] == 
'\n') ndigits--;
 
  250      bytespl = ndigits >> 5;  
 
  252      if (bytespl >= 1 && bytespl <= 4) {
 
  253         for (i = 0; i < 16; i++) { 
 
  256               case 1: sscanf (bitstring, 
"%2X", &temprow);
 
  260               case 2: sscanf (bitstring, 
"%4X", &temprow);
 
  264               case 3: sscanf (bitstring, 
"%6X", &temprow);
 
  268               case 4: sscanf (bitstring, 
"%8X", &temprow);
 
  276               for (bitmask = 0xC0000000; bitmask != 0; bitmask >>= 2) {
 
  278                  if ((temprow & bitmask) != 0) newrow |= 1;
 
  282            plane_array[codept][i] = temprow;  
 
  303genlongbmp (
int plane_array[0x10000][16], 
int dpi, 
int tinynum, 
int plane)
 
  312   unsigned leftcol[0x1000][16]; 
 
  316   unsigned toprow[16][16];      
 
  322   int DataOffset = 14 + 40 + 8; 
 
  342   ImageSize = Height * (Width / 8); 
 
  344   FileSize = DataOffset + ImageSize;
 
  347   if (dpi == 0) dpi = 96;
 
  348   ppm = (int)((
double)dpi * 100.0 / 2.54 + 0.5);
 
  388   memset ((
void *)header, 0, 16 * 16 * 
sizeof (
int)); 
 
  389   memset ((
void *)header_string, 
' ', 32 * 
sizeof (
char)); 
 
  390   header_string[32] = 
'\0';  
 
  392   hdrlen = strlen (raw_header);
 
  393   if (hdrlen > 32) hdrlen = 32;        
 
  394   startcol = 16 - ((hdrlen + 1) >> 1); 
 
  396   memcpy (&header_string[startcol], raw_header, hdrlen);
 
  400   for (j = 0; j < 16; j++) {
 
  401      for (i = 0; i < 16; i++) {
 
  403            (
ascii_bits[header_string[j+j  ] & 0x7F][i] & 0xFF00) |
 
  404            (
ascii_bits[header_string[j+j+1] & 0x7F][i] >> 8);
 
  411   memset ((
void *)leftcol, 0, 4096 * 16 * 
sizeof (
unsigned));
 
  413   for (codept = 0x0000; codept < 0x10000; codept += 0x10) {
 
  414      d1 = (codept >> 12) & 0xF; 
 
  415      d2 = (codept >>  8) & 0xF;
 
  416      d3 = (codept >>  4) & 0xF;
 
  418      thisrow = codept >> 4; 
 
  421      for (digitrow = 0; digitrow < 5; digitrow++) {
 
  422         leftcol[thisrow][2 + digitrow] =
 
  428      for (digitrow = 0; digitrow < 5; digitrow++) {
 
  429         leftcol[thisrow][9 + digitrow] = 
hexdigit[d3][digitrow] << 10;
 
  431      leftcol[thisrow][9 + 4] |= 0xF << 4; 
 
  433      for (i = 0; i < 15; i ++) {
 
  434         leftcol[thisrow][i] |= 0x00000002;      
 
  437      leftcol[thisrow][15] = 0x0000FFFE;        
 
  440         leftcol[thisrow][15] |= 0x00FF0000;  
 
  443      if ((thisrow % 0x40) == 0x3F) {    
 
  444         leftcol[thisrow][15] |= 0xFFFF0000; 
 
  451   memset ((
void *)toprow, 0, 16 * 16 * 
sizeof (
unsigned));
 
  453   for (codept = 0x0; codept <= 0xF; codept++) {
 
  454      d1 = (codept >> 12) & 0xF; 
 
  455      d2 = (codept >>  8) & 0xF;
 
  456      d3 = (codept >>  4) & 0xF;
 
  460      for (digitrow = 0; digitrow < 5; digitrow++) {
 
  461         toprow[6 + digitrow][codept] = 
hexdigit[d4][digitrow] << 6;
 
  465   for (j = 0; j < 16; j++) {
 
  467      toprow[15][j] = 0x0000;
 
  471   for (j = 0; j < 16; j++) {
 
  472      toprow[14][j] |= 0xFFFF;
 
  476   for (i = 13; i >= 0; i--) {
 
  477      for (j = 0; j < 16; j++) {
 
  478         toprow[i][j] |= 0x0001;
 
  489   for (i = 0xFFF0; i >= 0; i -= 0x10) {
 
  491      for (j = 15; j >= 0; j--) {
 
  493         putchar ((~leftcol[thisrow][j] >> 24) & 0xFF);
 
  494         putchar ((~leftcol[thisrow][j] >> 16) & 0xFF);
 
  495         putchar ((~leftcol[thisrow][j] >>  8) & 0xFF);
 
  496         putchar ( ~leftcol[thisrow][j]        & 0xFF);
 
  498         for (k = 0; k < 16; k++) {
 
  499            bytesout = ~plane_array[i+k][j] & 0xFFFF;
 
  500            putchar ((bytesout >> 8) & 0xFF);
 
  501            putchar ( bytesout       & 0xFF);
 
  515   for (j = 0; j < 16; j++) {
 
  516      putchar ((~toprow[15][j] >> 8) & 0xFF);
 
  517      putchar ( ~toprow[15][j]       & 0xFF);
 
  524   for (j = 0; j < 16; j++) {
 
  525      putchar ((~toprow[14][j] >> 8) & 0xFF);
 
  526      putchar ( ~toprow[14][j]       & 0xFF);
 
  529   for (i = 13; i >= 0; i--) {
 
  534      for (j = 0; j < 16; j++) {
 
  535         putchar ((~toprow[i][j] >> 8) & 0xFF);
 
  536         putchar ( ~toprow[i][j]       & 0xFF);
 
  545   for (i = 7; i >= 0; i--) {
 
  546      for (j = 0; j < 18; j++) {
 
  552   for (i = 15; i >= 0; i--) {
 
  559      for (j = 0; j < 16; j++) {
 
  560         bytesout = ~header[i][j] & 0xFFFF;
 
  561         putchar ((bytesout >> 8) & 0xFF);
 
  562         putchar ( bytesout       & 0xFF);
 
  567   for (i = 7; i >= 0; i--) {
 
  568      for (j = 0; j < 18; j++) {
 
  590genwidebmp (
int plane_array[0x10000][16], 
int dpi, 
int tinynum, 
int plane)
 
  593   char header_string[257];
 
  599   unsigned leftcol[0x100][16]; 
 
  603   unsigned toprow[32][256];    
 
  605   int hexalpha1, hexalpha2;    
 
  610   int DataOffset = 14 + 40 + 8; 
 
  630   ImageSize = Height * (Width / 8); 
 
  632   FileSize = DataOffset + ImageSize;
 
  635   if (dpi == 0) dpi = 96;
 
  636   ppm = (int)((
double)dpi * 100.0 / 2.54 + 0.5);
 
  674   memset ((
void *)header, 0, 256 * 16 * 
sizeof (
int)); 
 
  675   memset ((
void *)header_string, 
' ', 256 * 
sizeof (
char)); 
 
  676   header_string[256] = 
'\0';  
 
  678   hdrlen = strlen (raw_header);
 
  680   if (hdrlen > 32) hdrlen = 32;
 
  681   startcol = 127 - ((hdrlen - 1) >> 1);  
 
  683   memcpy (&header_string[startcol], raw_header, hdrlen);
 
  686   for (j = 0; j < 256; j++) {
 
  687      for (i = 0; i < 16; i++) {
 
  688         header[i][j] = 
ascii_bits[header_string[j] & 0x7F][i];
 
  695   memset ((
void *)leftcol, 0, 256 * 16 * 
sizeof (
unsigned));
 
  697   for (codept = 0x0000; codept < 0x10000; codept += 0x100) {
 
  698      d1 = (codept >> 12) & 0xF; 
 
  699      d2 = (codept >>  8) & 0xF;
 
  701      thisrow = codept >> 8; 
 
  706         for (digitrow = 0; digitrow < 5; digitrow++) {
 
  707            leftcol[thisrow][6 + digitrow] =
 
  714         hexalpha1 = d1 < 0xA ? 
'0' + d1 : 
'A' + d1 - 0xA;
 
  715         hexalpha2 = d2 < 0xA ? 
'0' + d2 : 
'A' + d2 - 0xA;
 
  717         for (i = 0 ; i < 16; i++) {
 
  718            leftcol[thisrow][i] =
 
  724      for (i = 0; i < 15; i ++) {
 
  725         leftcol[thisrow][i] |= 0x00000002;      
 
  728      leftcol[thisrow][15] = 0x0000FFFE;        
 
  731         leftcol[thisrow][15] |= 0x00FF0000;  
 
  734      if ((thisrow % 0x40) == 0x3F) {    
 
  735         leftcol[thisrow][15] |= 0xFFFF0000; 
 
  742   memset ((
void *)toprow, 0, 32 * 256 * 
sizeof (
unsigned));
 
  744   for (codept = 0x00; codept <= 0xFF; codept++) {
 
  745      d3 = (codept >>  4) & 0xF;
 
  749         for (digitrow = 0; digitrow < 5; digitrow++) {
 
  750            toprow[16 + 6 + digitrow][codept] =
 
  757         hexalpha1 = d3 < 0xA ? 
'0' + d3 : 
'A' + d3 - 0xA;
 
  758         hexalpha2 = d4 < 0xA ? 
'0' + d4 : 
'A' + d4 - 0xA;
 
  759         for (i = 0 ; i < 16; i++) {
 
  760            toprow[14 + i][codept] =
 
  767   for (j = 0; j < 256; j++) {
 
  769      toprow[16 + 15][j] = 0x0000;
 
  773   for (j = 0; j < 256; j++) {
 
  774      toprow[16 + 14][j] |= 0xFFFF;
 
  778   for (i = 13; i >= 0; i--) {
 
  779      for (j = 0; j < 256; j++) {
 
  780         toprow[16 + i][j] |= 0x0001;
 
  785   for (i = 8; i < 16; i++) {
 
  786      for (j = 0x0F; j < 0x100; j += 0x10) {
 
  787         toprow[i][j] |= 0x0001;
 
  798   for (i = 0xFF00; i >= 0; i -= 0x100) {
 
  800      for (j = 15; j >= 0; j--) {
 
  802         putchar ((~leftcol[thisrow][j] >> 24) & 0xFF);
 
  803         putchar ((~leftcol[thisrow][j] >> 16) & 0xFF);
 
  804         putchar ((~leftcol[thisrow][j] >>  8) & 0xFF);
 
  805         putchar ( ~leftcol[thisrow][j]        & 0xFF);
 
  807         for (k = 0x00; k < 0x100; k++) {
 
  808            bytesout = ~plane_array[i+k][j] & 0xFFFF;
 
  809            putchar ((bytesout >> 8) & 0xFF);
 
  810            putchar ( bytesout       & 0xFF);
 
  824   for (j = 0; j < 256; j++) {
 
  825      putchar ((~toprow[16 + 15][j] >> 8) & 0xFF);
 
  826      putchar ( ~toprow[16 + 15][j]       & 0xFF);
 
  833   for (j = 0; j < 256; j++) {
 
  834      putchar ((~toprow[16 + 14][j] >> 8) & 0xFF);
 
  835      putchar ( ~toprow[16 + 14][j]       & 0xFF);
 
  838   for (i = 16 + 13; i >= 0; i--) {
 
  851      for (j = 0; j < 256; j++) {
 
  852         putchar ((~toprow[i][j] >> 8) & 0xFF);
 
  853         putchar ( ~toprow[i][j]       & 0xFF);
 
  862   for (i = 7; i >= 0; i--) {
 
  863      for (j = 0; j < 258; j++) {
 
  869   for (i = 15; i >= 0; i--) {
 
  876      for (j = 0; j < 256; j++) {
 
  877         bytesout = ~header[i][j] & 0xFFFF;
 
  878         putchar ((bytesout >> 8) & 0xFF);
 
  879         putchar ( bytesout       & 0xFF);
 
  884   for (i = 7; i >= 0; i--) {
 
  885      for (j = 0; j < 258; j++) {
 
int main()
The main function.
unsigned hexdigit[16][4]
32 bit representation of 16x8 0..F bitmap
void gethex(char *instring, int plane_array[0x10000][16], int plane)
Read a Unifont .hex-format input file from stdin.
void genwidebmp(int plane_array[0x10000][16], int dpi, int tinynum, int plane)
Generate the BMP output file in wide format.
void output4(int thisword)
Output a 4-byte integer in little-endian order.
void output2(int thisword)
Output a 2-byte integer in little-endian order.
void genlongbmp(int plane_array[0x10000][16], int dpi, int tinynum, int plane)
Generate the BMP output file in long format.
unifontpic.h - Header file for unifontpic.c
#define HEADER_STRING
To be printed as chart title.
int ascii_bits[128][16]
Array to hold ASCII bitmaps for chart title.
const char * ascii_hex[128]
Array of Unifont ASCII glyphs for chart row & column headings.