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