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