Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

convbdf: Replace magic number with #define shared with main code

Change-Id: Id46d5f2fe88fdaac94d00b1a4810ab161baad35b

+45 -44
+45 -44
tools/convbdf.c
··· 37 37 #define BITMAP_TESTBIT(m) ((m) & BITMAP_FIRSTBIT) 38 38 #define BITMAP_SHIFTBIT(m) ((bitmap_t) ((m) << 1)) 39 39 40 + #define MAX_FONTSIZE_FOR_16_BIT_OFFSETS 0xFFDB 40 41 41 42 /* builtin C-based proportional/fixed font structure */ 42 43 /* based on The Microwindows Project http://microwindows.org */ ··· 52 53 unsigned char* width; /* character widths or NULL if fixed */ 53 54 int defaultchar; /* default char (not glyph index) */ 54 55 int bits_size; /* # words of bitmap_t bits */ 55 - 56 + 56 57 /* unused by runtime system, read in by convbdf */ 57 58 int nchars; /* number of different glyphs */ 58 59 int nchars_declared; /* number of glyphs as declared in the header */ ··· 70 71 71 72 /* Max 'overflow' of a char's ascent (descent) over the font's one */ 72 73 int max_over_ascent, max_over_descent; 73 - 74 + 74 75 /* The number of clipped ascents/descents/total */ 75 76 int num_clipped_ascent, num_clipped_descent, num_clipped; 76 77 ··· 182 183 char buf[256]; 183 184 char *p; 184 185 strcpy(buf, val); 185 - 186 + 186 187 opt->force = 0; 187 188 opt->percent = 0; 188 189 p = buf + strlen(buf); ··· 209 210 char *p; 210 211 char **av; 211 212 int ac; 212 - 213 + 213 214 ac = *pac; 214 215 av = *pav; 215 216 while (ac > 0 && av[0][0] == '-') { 216 - p = &av[0][1]; 217 + p = &av[0][1]; 217 218 while( *p) 218 219 switch(*p++) { 219 220 case ' ': /* multiple -args on av[] */ ··· 385 386 pf = bdf_read_font(path); 386 387 if (!pf) 387 388 exit(1); 388 - 389 + 389 390 if (gen_c) { 390 391 if (!oflag) { 391 392 strcpy(outfile, basename(path)); ··· 393 394 } 394 395 ret |= gen_c_source(pf, outfile); 395 396 } 396 - 397 + 397 398 if (gen_h) { 398 399 if (!oflag) { 399 400 strcpy(outfile, basename(path)); ··· 432 433 exit(1); 433 434 } 434 435 } 435 - 436 + 436 437 while (ac > 0) { 437 438 ret |= convbdf(av[0]); 438 439 ++av; --ac; 439 440 } 440 - 441 + 441 442 exit(ret); 442 443 } 443 444 ··· 472 473 print_error("Error opening file: %s\n", path); 473 474 return NULL; 474 475 } 475 - 476 + 476 477 pf = (struct font*)calloc(1, sizeof(struct font)); 477 478 if (!pf) 478 479 goto errout; 479 480 memset(pf, 0, sizeof(struct font)); 480 - 481 + 481 482 pf->name = strdup(basename(path)); 482 483 483 484 if (!bdf_read_header(fp, pf)) { ··· 492 493 } 493 494 print_trace("Analyzed font, nchars=%d, maxwidth=%d, asc_over=%d, desc_over=%d\n", 494 495 pf->nchars, pf->maxwidth, pf->max_over_ascent, pf->max_over_descent); 495 - 496 + 496 497 if (pf->nchars != pf->nchars_declared) { 497 498 print_warning(VL_MISC, "The declared number of chars (%d) " 498 499 "does not match the real number (%d)\n", 499 500 pf->nchars_declared, pf->nchars); 500 501 } 501 - 502 + 502 503 /* Correct ascent/descent if necessary */ 503 504 pf->ascent = adjust_ascent(pf->ascent_declared, pf->max_over_ascent, &stretch_ascent); 504 505 if (pf->ascent != pf->ascent_declared) { ··· 514 515 if (pf->height != pf->ascent_declared + pf->descent_declared) { 515 516 print_warning(VL_CLIP_FONT, "Generated font's height: %d\n", pf->height); 516 517 } 517 - 518 + 518 519 if (pf->ascent > pf->max_char_ascent) { 519 520 print_trace("Font's ascent could be reduced by %d to %d without clipping\n", 520 521 (pf->ascent - pf->max_char_ascent), pf->max_char_ascent); ··· 523 524 print_trace("Font's descent could be reduced by %d to %d without clipping\n", 524 525 (pf->descent - pf->max_char_descent), pf->max_char_descent); 525 526 } 526 - 527 - 527 + 528 + 528 529 /* Alocate memory */ 529 530 pf->bits_size = pf->size * BITMAP_WORDS(pf->maxwidth) * pf->height; 530 531 pf->bits = (bitmap_t *)malloc(pf->bits_size * sizeof(bitmap_t)); 531 532 pf->offset = (int *)malloc(pf->size * sizeof(int)); 532 533 pf->offrot = (unsigned int *)malloc(pf->size * sizeof(unsigned int)); 533 534 pf->width = (unsigned char *)malloc(pf->size * sizeof(unsigned char)); 534 - 535 + 535 536 if (!pf->bits || !pf->offset || !pf->offrot || !pf->width) { 536 537 print_error("no memory for font load\n"); 537 538 goto errout; ··· 545 546 goto errout; 546 547 } 547 548 print_trace("Read bitmaps\n"); 548 - 549 + 549 550 if (pf->num_clipped > 0) { 550 551 print_warning(VL_CLIP_FONT, "%d character(s) out of %d were clipped " 551 552 "(%d at ascent, %d at descent)\n", ··· 664 665 return 0; 665 666 } 666 667 if (encoding >= 0 && 667 - encoding <= limit_char && 668 + encoding <= limit_char && 668 669 encoding >= start_char) { 669 670 670 671 if (firstchar > encoding) ··· 686 687 pf->height = pf->ascent + pf->descent; 687 688 688 689 /* calc default char */ 689 - if (pf->defaultchar < 0 || 690 - pf->defaultchar < firstchar || 690 + if (pf->defaultchar < 0 || 691 + pf->defaultchar < firstchar || 691 692 pf->defaultchar > limit_char || 692 693 pf->defaultchar > lastchar) 693 694 pf->defaultchar = firstchar; ··· 826 827 } 827 828 828 829 y = bby_orig + bbh_orig; /* 0-based y within the char */ 829 - 830 + 830 831 /* read bitmaps */ 831 832 for (i=0; ; ++i) { 832 833 int hexnibbles; ··· 838 839 } 839 840 if (isprefix(buf, "ENDCHAR")) 840 841 break; 841 - 842 + 842 843 y--; 843 844 if ((y >= pf->ascent) || (y < -pf->descent)) { 844 845 /* We're beyond the area that Rockbox can render -> clip */ ··· 851 852 int ndx = k * BITMAP_NIBBLES; 852 853 int padnibbles = hexnibbles - ndx; 853 854 bitmap_t value; 854 - 855 + 855 856 if (padnibbles <= 0) 856 857 break; 857 858 if (padnibbles >= (int)BITMAP_NIBBLES) ··· 981 982 982 983 /* reset file pointer */ 983 984 fseek(fp, 0L, SEEK_SET); 984 - 985 + 985 986 pf->maxwidth = 0; 986 987 pf->nchars = 0; 987 988 pf->max_char_ascent = pf->max_char_descent = 0; 988 989 pf->max_over_ascent = pf->max_over_descent = 0; 989 990 990 991 for (;;) { 991 - 992 + 992 993 if (!bdf_getline(fp, buf, sizeof(buf))) { 993 994 print_error("EOF on file\n"); 994 995 return 0; ··· 1082 1083 if (stretch->percent) { 1083 1084 px = ascent * px / 100; 1084 1085 } 1085 - 1086 + 1086 1087 if (stretch->force) { 1087 1088 result = ascent + px; 1088 1089 } ··· 1104 1105 c = buf[i]; 1105 1106 if (c >= '0' && c <= '9') 1106 1107 c -= '0'; 1107 - else 1108 + else 1108 1109 if (c >= 'A' && c <= 'F') 1109 1110 c = c - 'A' + 10; 1110 - else 1111 + else 1111 1112 if (c >= 'a' && c <= 'f') 1112 1113 c = c - 'a' + 10; 1113 - else 1114 + else 1114 1115 c = 0; 1115 1116 val = (val << 4) | c; 1116 1117 } ··· 1141 1142 unsigned int src_words; /* # words of input image */ 1142 1143 unsigned int dst_mask; /* bit mask for destination */ 1143 1144 bitmap_t src_mask; /* bit mask for source */ 1144 - 1145 + 1145 1146 /* How large the buffer should be to hold the rotated bitmap 1146 1147 of a glyph of size (width x height) */ 1147 1148 unsigned int needed_size = ((height + 7) / 8) * width; ··· 1155 1156 1156 1157 /* calc words of input image */ 1157 1158 src_words = BITMAP_WORDS(width) * height; 1158 - 1159 + 1159 1160 /* clear background */ 1160 1161 memset(dst, 0, needed_size); 1161 1162 ··· 1165 1166 1166 1167 /* calc src input bit */ 1167 1168 src_mask = 1 << (sizeof (bitmap_t) * 8 - 1); 1168 - 1169 + 1169 1170 /* for each input column... */ 1170 1171 for(j=0; j < width; j++) { 1171 1172 ··· 1243 1244 strcpy(buf, ctime(&t)); 1244 1245 buf[strlen(buf)-1] = 0; 1245 1246 1246 - fprintf(ofp, hdr1, buf, 1247 + fprintf(ofp, hdr1, buf, 1247 1248 pf->name, 1248 1249 pf->facename? pf->facename: "", 1249 1250 pf->maxwidth, pf->height, ··· 1312 1313 { 1313 1314 unsigned char bytemap[ROTATION_BUF_SIZE]; 1314 1315 int y8, ix=0; 1315 - 1316 + 1316 1317 int size = rotleft(bytemap, sizeof(bytemap), bits, width, 1317 1318 pf->height, char_code); 1318 1319 if (size < 0) { 1319 1320 return -1; 1320 1321 } 1321 - 1322 + 1322 1323 for (y8=0; y8<pf->height; y8+=8) /* column rows */ 1323 1324 { 1324 1325 for (x=0; x<width; x++) { ··· 1347 1348 if (pf->offset) { 1348 1349 /* output offset table */ 1349 1350 fprintf(ofp, "/* Character->glyph mapping. */\n" 1350 - "static const unsigned %s _sysfont_offset[] = {\n", pf->bits_size > 0xffdb ? "long" : "short"); 1351 + "static const unsigned %s _sysfont_offset[] = {\n", pf->bits_size > MAX_FONTSIZE_FOR_16_BIT_OFFSETS ? "long" : "short"); 1351 1352 1352 1353 for (i=0; i<pf->size; ++i) { 1353 1354 int offset = pf->offset[i]; ··· 1356 1357 offset = pf->offset[pf->defaultchar - pf->firstchar]; 1357 1358 offrot = pf->offrot[pf->defaultchar - pf->firstchar]; 1358 1359 } 1359 - fprintf(ofp, " %d,\t/* (0x%02x) */\n", 1360 + fprintf(ofp, " %d,\t/* (0x%02x) */\n", 1360 1361 #ifdef ROTATE 1361 1362 offrot, i+pf->firstchar); 1362 1363 #else ··· 1372 1373 "static const unsigned char _sysfont_width[] = {\n"); 1373 1374 1374 1375 for (i=0; i<pf->size; ++i) 1375 - fprintf(ofp, " %d,\t/* (0x%02x) */\n", 1376 + fprintf(ofp, " %d,\t/* (0x%02x) */\n", 1376 1377 pf->width[i], i+pf->firstchar); 1377 1378 fprintf(ofp, "};\n\n"); 1378 1379 } ··· 1410 1411 pf->defaultchar, 1411 1412 pf->bits_size 1412 1413 ); 1413 - 1414 + 1414 1415 fprintf(ofp, " -1, /* font fd */\n" 1415 1416 " -1, /* font fd width */\n" 1416 1417 " -1, /* font fd offset */\n" ··· 1475 1476 pf->ascent, 1476 1477 pf->depth); 1477 1478 1478 - fprintf(ofp, hdr2, 1479 + fprintf(ofp, hdr2, 1479 1480 pf->descent, 1480 1481 pf->firstchar, 1481 1482 pf->firstchar+pf->size-1, ··· 1592 1593 ofr += size; 1593 1594 } 1594 1595 1595 - if ( pf->bits_size < 0xFFDB ) 1596 + if ( pf->bits_size < MAX_FONTSIZE_FOR_16_BIT_OFFSETS ) 1596 1597 { 1597 1598 /* bitmap offset is small enough, use unsigned short for offset */ 1598 1599 if (ftell(ofp) & 1) ··· 1600 1601 } 1601 1602 else 1602 1603 { 1603 - /* bitmap offset is large then 64K, use unsigned int for offset */ 1604 + /* bitmap offset is larger then 64K, use unsigned int for offset */ 1604 1605 while (ftell(ofp) & 3) 1605 1606 writebyte(ofp, 0); /* pad to 32-bit boundary */ 1606 1607 } ··· 1613 1614 if (pf->offset[i] == -1) { 1614 1615 offrot = pf->offrot[pf->defaultchar - pf->firstchar]; 1615 1616 } 1616 - if ( pf->bits_size < 0xFFDB ) 1617 + if ( pf->bits_size < MAX_FONTSIZE_FOR_16_BIT_OFFSETS ) 1617 1618 writeshort(ofp, offrot); 1618 1619 else 1619 1620 writeint(ofp, offrot);