The main function. 
  150{
  151 
  152   int i, j, k;               
  153   unsigned char inchar;       
  155   int wbmp=0; 
  156   int fatal; 
  157   int match; 
  158   int empty1, empty2; 
  159   unsigned char thischar1[16], thischar2[16]; 
  160   unsigned char thischar0[16], thischar3[16]; 
  161   int thisrow; 
  162   int tmpsum;  
  163   unsigned this_pixel;  
  164   unsigned next_pixels; 
  165   unsigned color_mask = 0x00;  
  166 
  167   unsigned char bitmap[17*32][18*32/8]; 
  168   
  169
  170
  171
  172
  173   char wide[0x200000]={0x200000 * 0};
  174 
  175   char *infile="", *outfile="";  
  176   FILE *infp, *outfp;      
  177 
  178   if (argc > 1) {
  179      for (i = 1; i < argc; i++) {
  180         if (argv[i][0] == '-') {  
  181            switch (argv[i][1]) {
  182               case 'i':  
  183                  infile = &argv[i][2];
  184                  break;
  185               case 'o':  
  186                  outfile = &argv[i][2];
  187                  break;
  188               case 'p':  
  189                  sscanf (&argv[i][2], 
"%x", &
uniplane); 
 
  191                  break;
  192               case 'w': 
  194                  break;
  195               default:   
  196                  fprintf (stderr, "\nSyntax:\n\n");
  197                  fprintf (stderr, "   %s -p<Unicode_Page> ", argv[0]);
  198                  fprintf (stderr, "-i<Input_File> -o<Output_File> -w\n\n");
  199                  fprintf (stderr, "   -w specifies .wbmp output instead of ");
  200                  fprintf (stderr, "default Windows .bmp output.\n\n");
  201                  fprintf (stderr, "   -p is followed by 1 to 6 ");
  202                  fprintf (stderr, "Unicode plane hex digits ");
  203                  fprintf (stderr, "(default is Page 0).\n\n");
  204                  fprintf (stderr, "\nExample:\n\n");
  205                  fprintf (stderr, "   %s -p83 -iunifont.hex -ou83.bmp\n\n\n",
  206                         argv[0]);
  207                  exit (1);
  208            }
  209         }
  210      }
  211   }
  212   
  213
  214
  215
  216   if (strlen (infile) > 0) {
  217      if ((infp = fopen (infile, "r")) == NULL) {
  218         fprintf (stderr, "Error: can't open %s for input.\n", infile);
  219         exit (1);
  220      }
  221   }
  222   else {
  223      infp = stdin;
  224   }
  225   if (strlen (outfile) > 0) {
  226      if ((outfp = fopen (outfile, "w")) == NULL) {
  227         fprintf (stderr, "Error: can't open %s for output.\n", outfile);
  228         exit (1);
  229      }
  230   }
  231   else {
  232      outfp = stdout;
  233   }
  234   
  235
  236
  237
  238
  239
  240
  241
  242
  243   for (i = 0x0700; i <= 0x074F; i++) wide[i] = 1; 
  244   for (i = 0x0800; i <= 0x083F; i++) wide[i] = 1; 
  245   for (i = 0x0900; i <= 0x0DFF; i++) wide[i] = 1; 
  246   for (i = 0x1000; i <= 0x109F; i++) wide[i] = 1; 
  247   for (i = 0x1100; i <= 0x11FF; i++) wide[i] = 1; 
  248   for (i = 0x1400; i <= 0x167F; i++) wide[i] = 1; 
  249   for (i = 0x1700; i <= 0x171F; i++) wide[i] = 1; 
  250   for (i = 0x1720; i <= 0x173F; i++) wide[i] = 1; 
  251   for (i = 0x1740; i <= 0x175F; i++) wide[i] = 1; 
  252   for (i = 0x1760; i <= 0x177F; i++) wide[i] = 1; 
  253   for (i = 0x1780; i <= 0x17FF; i++) wide[i] = 1; 
  254   for (i = 0x18B0; i <= 0x18FF; i++) wide[i] = 1; 
  255   for (i = 0x1800; i <= 0x18AF; i++) wide[i] = 1; 
  256   for (i = 0x1900; i <= 0x194F; i++) wide[i] = 1; 
  257
  258   for (i = 0x1A00; i <= 0x1A1F; i++) wide[i] = 1; 
  259   for (i = 0x1A20; i <= 0x1AAF; i++) wide[i] = 1; 
  260   for (i = 0x1B00; i <= 0x1B7F; i++) wide[i] = 1; 
  261   for (i = 0x1B80; i <= 0x1BBF; i++) wide[i] = 1; 
  262   for (i = 0x1BC0; i <= 0x1BFF; i++) wide[i] = 1; 
  263   for (i = 0x1C00; i <= 0x1C4F; i++) wide[i] = 1; 
  264   for (i = 0x1CC0; i <= 0x1CCF; i++) wide[i] = 1; 
  265   for (i = 0x1CD0; i <= 0x1CFF; i++) wide[i] = 1; 
  266   wide[0x2329] = wide[0x232A] = 1; 
  267   for (i = 0x2E80; i <= 0xA4CF; i++) wide[i] = 1; 
  268
  269   for (i = 0xA900; i <= 0xA92F; i++) wide[i] = 1; 
  270   for (i = 0xA930; i <= 0xA95F; i++) wide[i] = 1; 
  271   for (i = 0xA960; i <= 0xA97F; i++) wide[i] = 1; 
  272   for (i = 0xA980; i <= 0xA9DF; i++) wide[i] = 1; 
  273   for (i = 0xAA00; i <= 0xAA5F; i++) wide[i] = 1; 
  274   for (i = 0xA9E0; i <= 0xA9FF; i++) wide[i] = 1; 
  275   for (i = 0xAA00; i <= 0xAA5F; i++) wide[i] = 1; 
  276   for (i = 0xAA60; i <= 0xAA7F; i++) wide[i] = 1; 
  277   for (i = 0xAAE0; i <= 0xAAFF; i++) wide[i] = 1; 
  278   for (i = 0xABC0; i <= 0xABFF; i++) wide[i] = 1; 
  279   for (i = 0xAC00; i <= 0xD7AF; i++) wide[i] = 1; 
  280   for (i = 0xD7B0; i <= 0xD7FF; i++) wide[i] = 1; 
  281   for (i = 0xF900; i <= 0xFAFF; i++) wide[i] = 1; 
  282   for (i = 0xFE10; i <= 0xFE1F; i++) wide[i] = 1; 
  283   for (i = 0xFE30; i <= 0xFE60; i++) wide[i] = 1; 
  284   for (i = 0xFFE0; i <= 0xFFE6; i++) wide[i] = 1; 
  285 
  286   wide[0x303F] = 0; 
  287 
  288   
  289   for (i = 0x010A00; i <= 0x010A5F; i++) wide[i] = 1; 
  290   for (i = 0x011000; i <= 0x01107F; i++) wide[i] = 1; 
  291   for (i = 0x011080; i <= 0x0110CF; i++) wide[i] = 1; 
  292   for (i = 0x011100; i <= 0x01114F; i++) wide[i] = 1; 
  293   for (i = 0x011180; i <= 0x0111DF; i++) wide[i] = 1; 
  294   for (i = 0x011200; i <= 0x01124F; i++) wide[i] = 1; 
  295   for (i = 0x0112B0; i <= 0x0112FF; i++) wide[i] = 1; 
  296   for (i = 0x011300; i <= 0x01137F; i++) wide[i] = 1; 
  297   for (i = 0x011400; i <= 0x01147F; i++) wide[i] = 1; 
  298   for (i = 0x011480; i <= 0x0114DF; i++) wide[i] = 1; 
  299   for (i = 0x011580; i <= 0x0115FF; i++) wide[i] = 1; 
  300   for (i = 0x011600; i <= 0x01165F; i++) wide[i] = 1; 
  301   for (i = 0x011660; i <= 0x01167F; i++) wide[i] = 1; 
  302   for (i = 0x011680; i <= 0x0116CF; i++) wide[i] = 1; 
  303   for (i = 0x011700; i <= 0x01173F; i++) wide[i] = 1; 
  304   for (i = 0x011800; i <= 0x01184F; i++) wide[i] = 1; 
  305   for (i = 0x011900; i <= 0x01195F; i++) wide[i] = 1; 
  306   for (i = 0x0119A0; i <= 0x0119FF; i++) wide[i] = 1; 
  307   for (i = 0x011A00; i <= 0x011A4F; i++) wide[i] = 1; 
  308   for (i = 0x011A50; i <= 0x011AAF; i++) wide[i] = 1; 
  309   for (i = 0x011B00; i <= 0x011B5F; i++) wide[i] = 1; 
  310   for (i = 0x011F00; i <= 0x011F5F; i++) wide[i] = 1; 
  311   for (i = 0x011C00; i <= 0x011C6F; i++) wide[i] = 1; 
  312   for (i = 0x011C70; i <= 0x011CBF; i++) wide[i] = 1; 
  313   for (i = 0x011D00; i <= 0x011D5F; i++) wide[i] = 1; 
  314   for (i = 0x011EE0; i <= 0x011EFF; i++) wide[i] = 1; 
  315   for (i = 0x012F90; i <= 0x012FFF; i++) wide[i] = 1; 
  316   
  317   for (i = 0x016AD0; i <= 0x016AFF; i++) wide[i] = 1; 
  318   for (i = 0x016B00; i <= 0x016B8F; i++) wide[i] = 1; 
  319   for (i = 0x016F00; i <= 0x016F9F; i++) wide[i] = 1; 
  320   for (i = 0x016FE0; i <= 0x016FFF; i++) wide[i] = 1; 
  321   for (i = 0x017000; i <= 0x0187FF; i++) wide[i] = 1; 
  322   for (i = 0x018800; i <= 0x018AFF; i++) wide[i] = 1; 
  323   for (i = 0x01AFF0; i <= 0x01AFFF; i++) wide[i] = 1; 
  324   for (i = 0x01B000; i <= 0x01B0FF; i++) wide[i] = 1; 
  325   for (i = 0x01B100; i <= 0x01B12F; i++) wide[i] = 1; 
  326   for (i = 0x01B170; i <= 0x01B2FF; i++) wide[i] = 1; 
  327   for (i = 0x01CF00; i <= 0x01CFCF; i++) wide[i] = 1; 
  328   for (i = 0x01D100; i <= 0x01D1FF; i++) wide[i] = 1; 
  329   for (i = 0x01D800; i <= 0x01DAAF; i++) wide[i] = 1; 
  330   for (i = 0x01E2C0; i <= 0x01E2FF; i++) wide[i] = 1; 
  331   for (i = 0x01E800; i <= 0x01E8DF; i++) wide[i] = 1; 
  332   for (i = 0x01F200; i <= 0x01F2FF; i++) wide[i] = 1; 
  333   wide[0x01F5E7] = 1;                                 
  334 
  335   
  336
  337
  338
  339 
  340
  341
  342
  343
  344   fatal = 0;  
  345   if ((header[0] = fgetc (infp)) != EOF) {
  346      if ((header[1] = fgetc (infp)) != EOF) {
  347         if (header[0] == 'B' && header[1] == 'M') {
  348            wbmp = 0; 
  349         }
  350         else {
  351            wbmp = 1; 
  352         }
  353      }
  354      else
  355         fatal = 1;
  356   }
  357   else
  358      fatal = 1;
  359 
  360   if (fatal) {
  361      fprintf (stderr, "Fatal error; end of input file.\n\n");
  362      exit (1);
  363   }
  364   
  365
  366
  367
  368   if (wbmp) {
  369      for (i=2; i<6; i++)
  370         header[i] = fgetc (infp);
  371      
  372
  373
  374      for (i=0; i < 32*17; i++) {
  375         for (j=0; j < 32*18/8; j++) {
  376            inchar = fgetc (infp);
  377            bitmap[i][j] = ~inchar;  
  378         }
  379      }
  380   }
  381   
  382
  383
  384
  385
  386
  387
  388   else {
  389      for (i = 2; i < 54; i++)
  390         header[i] = fgetc (infp);
  391 
  394 
  396          (header[2] & 0xFF)        | ((header[3] & 0xFF) <<  8) |
  397         ((header[4] & 0xFF) << 16) | ((header[5] & 0xFF) << 24);
  398 
  399      
  400 
  402          (header[10] & 0xFF)        | ((header[11] & 0xFF) <<  8) |
  403         ((header[12] & 0xFF) << 16) | ((header[13] & 0xFF) << 24);
  404 
  406          (header[14] & 0xFF)        | ((header[15] & 0xFF) <<  8) |
  407         ((header[16] & 0xFF) << 16) | ((header[17] & 0xFF) << 24);
  408 
  410          (header[18] & 0xFF)        | ((header[19] & 0xFF) <<  8) |
  411         ((header[20] & 0xFF) << 16) | ((header[21] & 0xFF) << 24);
  412 
  414          (header[22] & 0xFF)        | ((header[23] & 0xFF) <<  8) |
  415         ((header[24] & 0xFF) << 16) | ((header[25] & 0xFF) << 24);
  416 
  418          (header[26] & 0xFF)        | ((header[27] & 0xFF) <<  8);
  419 
  421          (header[28] & 0xFF)        | ((header[29] & 0xFF) <<  8);
  422 
  424          (header[30] & 0xFF)        | ((header[31] & 0xFF) <<  8) |
  425         ((header[32] & 0xFF) << 16) | ((header[33] & 0xFF) << 24);
  426 
  428          (header[34] & 0xFF)        | ((header[35] & 0xFF) <<  8) |
  429         ((header[36] & 0xFF) << 16) | ((header[37] & 0xFF) << 24);
  430 
  432          (header[38] & 0xFF)        | ((header[39] & 0xFF) <<  8) |
  433         ((header[40] & 0xFF) << 16) | ((header[41] & 0xFF) << 24);
  434 
  436          (header[42] & 0xFF)        | ((header[43] & 0xFF) <<  8) |
  437         ((header[44] & 0xFF) << 16) | ((header[45] & 0xFF) << 24);
  438 
  440          (header[46] & 0xFF)        | ((header[47] & 0xFF) <<  8) |
  441         ((header[48] & 0xFF) << 16) | ((header[49] & 0xFF) << 24);
  442 
  444          (header[50] & 0xFF)        | ((header[51] & 0xFF) <<  8) |
  445         ((header[52] & 0xFF) << 16) | ((header[53] & 0xFF) << 24);
  446 
  449 
  450      
  457         }
  458         
  459
  460
  461
  463              < (3 * 128) ) {
  464            color_mask = 0xFF;
  465         }
  466      }
  467 
  468#ifdef DEBUG
  469 
  470      
  471
  472
  473
  474
  475      fprintf (stderr, "Filetype: '%c%c'\n",
  477      fprintf (stderr, 
"File Size: %d\n", 
bmp_header.file_size);
 
  478      fprintf (stderr, 
"Image Offset: %d\n", 
bmp_header.image_offset);
 
  479      fprintf (stderr, 
"Info Header Size: %d\n", 
bmp_header.info_size);
 
  480      fprintf (stderr, 
"Image Width: %d\n", 
bmp_header.width);
 
  481      fprintf (stderr, 
"Image Height: %d\n", 
bmp_header.height);
 
  482      fprintf (stderr, 
"Number of Planes: %d\n", 
bmp_header.nplanes);
 
  483      fprintf (stderr, 
"Bits per Pixel: %d\n", 
bmp_header.bits_per_pixel);
 
  484      fprintf (stderr, 
"Compression Method: %d\n", 
bmp_header.compression);
 
  485      fprintf (stderr, 
"Image Size: %d\n", 
bmp_header.image_size);
 
  486      fprintf (stderr, 
"X Pixels per Meter: %d\n", 
bmp_header.x_ppm);
 
  487      fprintf (stderr, 
"Y Pixels per Meter: %d\n", 
bmp_header.y_ppm);
 
  488      fprintf (stderr, 
"Number of Colors: %d\n", 
bmp_header.ncolors);
 
  489      fprintf (stderr, 
"Important Colors: %d\n", 
bmp_header.important_colors);
 
  490 
  491#endif
  492 
  493      
  494
  495
  496      for (i = 32*17-1; i >= 0; i--) {
  497         for (j=0; j < 32*18/8; j++) {
  498            next_pixels = 0x00;  
  499            
  501               next_pixels = fgetc (infp);
  502            }
  503            
  506               next_pixels = 0;
  507               for (k = 0; k < 8; k++) {  
  508                  this_pixel = (fgetc (infp) & 0xFF) +
  509                               (fgetc (infp) & 0xFF) +
  510                               (fgetc (infp) & 0xFF);
  511 
  513                     (void) fgetc (infp);  
  514                  }
  515 
  516                  
  517                  if (this_pixel >= (128 * 3))
  518                     this_pixel = 0;
  519                  else
  520                     this_pixel = 1;
  521 
  522                  
  523                  next_pixels = (next_pixels << 1) | this_pixel;
  524               }
  525            }
  527               bitmap [(32*17-1) - i] [j] = next_pixels;
  528            }
  529            else {  
  530               bitmap [i][j] = next_pixels;
  531            }
  532         }
  533      }
  534 
  535      
  536
  537
  538
  539      if (color_mask != 0x00) {
  540         for (i = 32*17-1; i >= 0; i--) {
  541            for (j=0; j < 32*18/8; j++) {
  542               bitmap [i][j] ^= color_mask;
  543            }
  544         }
  545      }
  546 
  547   }
  548 
  549   
  550
  551
  552   fclose (infp);
  553  
  554
  555
  556
  557   
  558
  559
  560
  561 
  562
  563
  565      for (i = 0x0; i <= 0xF; i++) {  
  566         for (j = 0; j < 4; j++) {
  568               ((unsigned)bitmap[32 * (i+1) + 4 * j + 8    ][6] << 24 ) |
  569               ((unsigned)bitmap[32 * (i+1) + 4 * j + 8 + 1][6] << 16 ) |
  570               ((unsigned)bitmap[32 * (i+1) + 4 * j + 8 + 2][6] <<  8 ) |
  571               ((unsigned)bitmap[32 * (i+1) + 4 * j + 8 + 3][6]       );
  572         }
  573      }
  574      
  575
  576
  577
  578      for (i = 0; i < 4; i++) {
  579         for (j = 0; j < 4; j++) {
  581               ((unsigned)bitmap[32 * 0 + 4 * j + 8 + 1][i + 3] << 24 ) |
  582               ((unsigned)bitmap[32 * 0 + 4 * j + 8 + 2][i + 3] << 16 ) |
  583               ((unsigned)bitmap[32 * 0 + 4 * j + 8 + 3][i + 3] <<  8 ) |
  584               ((unsigned)bitmap[32 * 0 + 4 * j + 8 + 4][i + 3]       );
  585         }
  586      }
  587   
  588      tmpsum = 0;
  589      for (i = 4; i < 6; i++) {
  590         for (j = 0; j < 4; j++) {
  592               ((unsigned)bitmap[32 * 1 + 4 * j + 8    ][i] << 24 ) |
  593               ((unsigned)bitmap[32 * 1 + 4 * j + 8 + 1][i] << 16 ) |
  594               ((unsigned)bitmap[32 * 1 + 4 * j + 8 + 2][i] <<  8 ) |
  595               ((unsigned)bitmap[32 * 1 + 4 * j + 8 + 3][i]       );
  597         }
  598      }
  599      if (tmpsum == 0) {  
  601         
  602
  603
  604
  605
  606         for (i = 0x08; i < 0x18; i++) {
  607            bitmap[i][7] = (bitmap[i][8] << 4) | ((bitmap[i][ 9] >> 4) & 0xf);
  608            bitmap[i][8] = (bitmap[i][9] << 4) | ((bitmap[i][10] >> 4) & 0xf);
  609         }
  610         for (i = 4; i < 6; i++) {
  611            for (j = 0; j < 4; j++) {
  613                  ((unsigned)bitmap[4 * j + 8 + 1][i + 3] << 24 ) |
  614                  ((unsigned)bitmap[4 * j + 8 + 2][i + 3] << 16 ) |
  615                  ((unsigned)bitmap[4 * j + 8 + 3][i + 3] <<  8 ) |
  616                  ((unsigned)bitmap[4 * j + 8 + 4][i + 3]       );
  617            }
  618         }
  619      }
  620   
  621      
  622
  623
  624
  626      for (i=0; i<6; i++) { 
  627         match = 0; 
  628         for (j = 0x0; !match && j <= 0xF; j++) {
  634               match = 1;
  635            }
  636         }
  638      }
  640   }
  641   
  642
  643
  644   for (i = 0x0; i <= 0xf; i++) {
  645      for (j = 0x0; j <= 0xf; j++) {
  646         for (k = 0; k < 16; k++) {
  648               thischar0[k] = bitmap[32*(j+1) + k + 7][4 * (i+2)    ];
  649               thischar1[k] = bitmap[32*(j+1) + k + 7][4 * (i+2) + 1];
  650               thischar2[k] = bitmap[32*(j+1) + k + 7][4 * (i+2) + 2];
  651               thischar3[k] = bitmap[32*(j+1) + k + 7][4 * (i+2) + 3];
  652            }
  653            else {
  654               thischar0[k] = bitmap[32*(i+1) + k + 7][4 * (j+2)    ];
  655               thischar1[k] = bitmap[32*(i+1) + k + 7][4 * (j+2) + 1];
  656               thischar2[k] = bitmap[32*(i+1) + k + 7][4 * (j+2) + 2];
  657               thischar3[k] = bitmap[32*(i+1) + k + 7][4 * (j+2) + 3];
  658            }
  659         }
  660         
  661
  662
  663
  664         empty1 = empty2 = 1;
  665         for (k=0; (empty1 || empty2) && k < 16; k++) {
  666            if (thischar1[k] != 0) empty1 = 0;
  667            if (thischar2[k] != 0) empty2 = 0;
  668            }
  669         
  670
  671
  672         if (!empty1 || !empty2) {
  673            
  674
  675
  676
  677            
  678
  679
  680
  681 
  682
  683
  684
  685
  686
  688               fprintf (outfp, 
"%04X%X%X:", 
uniplane, i, j); 
 
  689            else
  690               fprintf (outfp, 
"%02X%X%X:", 
uniplane, i, j); 
 
  691            for (thisrow=0; thisrow<16; thisrow++) {
  692               
  693
  694
  695
  697                   empty2 && !wide[(
uniplane << 8) | (i << 4) | j]) {
 
  698                  fprintf (outfp,
  699                          "%02X",
  700                          thischar1[thisrow]);
  701               }
  702               else if (wide[(
uniplane << 8) | (i << 4) | j] == 4) {
 
  703                  
  704                  fprintf (outfp,
  705                          "%02X%02X%02X%02X",
  706                          thischar0[thisrow], thischar1[thisrow],
  707                          thischar2[thisrow], thischar3[thisrow] & 0xFE);
  708               }
  709               else { 
  710                  fprintf (outfp,
  711                          "%02X%02X",
  712                          thischar1[thisrow], thischar2[thisrow]);
  713               }
  714            }
  715            fprintf (outfp, "\n");
  716         }
  717      }
  718   }
  719   exit (0);
  720}
unsigned planeset
=1: use plane specified with -p parameter
unsigned uniplane
Unicode plane number, 0..0xff ff ff.
unsigned forcewide
=1 to set each glyph to 16 pixels wide
unsigned hexdigit[16][4]
32 bit representation of 16x8 0..F bitmap
unsigned char color_table[256][4]
#define MAXBUF
Maximum input file line length - 1.
unsigned flip
=1 if we're transposing glyph matrix