summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/convbdf.c68
1 files changed, 48 insertions, 20 deletions
diff --git a/tools/convbdf.c b/tools/convbdf.c
index d530c6145f..9b181a4f82 100644
--- a/tools/convbdf.c
+++ b/tools/convbdf.c
@@ -88,6 +88,10 @@ struct stretch {
88#define MAX(a,b) ((a) > (b) ? (a) : (b)) 88#define MAX(a,b) ((a) > (b) ? (a) : (b))
89#define MIN(a,b) ((a) < (b) ? (a) : (b)) 89#define MIN(a,b) ((a) < (b) ? (a) : (b))
90 90
91#ifdef ROTATE
92#define ROTATION_BUF_SIZE 2048
93#endif
94
91/* Depending on the verbosity level some warnings are printed or not */ 95/* Depending on the verbosity level some warnings are printed or not */
92int verbosity_level = 0; 96int verbosity_level = 0;
93int trace = 0; 97int trace = 0;
@@ -1084,6 +1088,9 @@ bitmap_t bdf_hexval(unsigned char *buf, int ndx1, int ndx2)
1084 return val; 1088 return val;
1085} 1089}
1086 1090
1091
1092#ifdef ROTATE
1093
1087/* 1094/*
1088 * Take an bitmap_t bitmap and convert to Rockbox format. 1095 * Take an bitmap_t bitmap and convert to Rockbox format.
1089 * Used for converting font glyphs for the time being. 1096 * Used for converting font glyphs for the time being.
@@ -1092,28 +1099,36 @@ bitmap_t bdf_hexval(unsigned char *buf, int ndx1, int ndx2)
1092 * 1099 *
1093 * Doing it this way keeps fonts in standard formats, 1100 * Doing it this way keeps fonts in standard formats,
1094 * as well as keeping Rockbox hw bitmap format. 1101 * as well as keeping Rockbox hw bitmap format.
1102 *
1103 * Returns the size of the rotated glyph (in bytes) or a
1104 * negative value if the glyph could not be rotated.
1095 */ 1105 */
1096int rotleft(unsigned char *dst, /* output buffer */ 1106int rotleft(unsigned char *dst, /* output buffer */
1097 size_t dstlen, /* buffer size */ 1107 size_t dstlen, /* buffer size */
1098 bitmap_t *src, unsigned int width, unsigned int height) 1108 bitmap_t *src, unsigned int width, unsigned int height,
1109 int char_code)
1099{ 1110{
1100 unsigned int i,j; 1111 unsigned int i,j;
1101 unsigned int src_words; /* # words of input image */ 1112 unsigned int src_words; /* # words of input image */
1102 unsigned int dst_mask; /* bit mask for destination */ 1113 unsigned int dst_mask; /* bit mask for destination */
1103 bitmap_t src_mask; /* bit mask for source */ 1114 bitmap_t src_mask; /* bit mask for source */
1115
1116 /* How large the buffer should be to hold the rotated bitmap
1117 of a glyph of size (width x height) */
1118 unsigned int needed_size = ((height + 7) / 8) * width;
1119
1120 if (needed_size > dstlen) {
1121 print_error("Character %d: Glyph of size %d x %d can't be rotated "
1122 "(buffer size is %lu, needs %u)\n",
1123 char_code, width, height, (unsigned long)dstlen, needed_size);
1124 return -1;
1125 }
1104 1126
1105 /* calc words of input image*/ 1127 /* calc words of input image*/
1106 src_words = BITMAP_WORDS(width) * height; 1128 src_words = BITMAP_WORDS(width) * height;
1107
1108 if(((height + 7) / 8) * width > dstlen) {
1109 print_error("%s:%d %d x %d overflows %ld bytes buffer, needs %d\n",
1110 __FILE__, __LINE__, width, height, (unsigned long)dstlen,
1111 ((height + 7) / 8) * width );
1112 return 0;
1113 }
1114 1129
1115 /* clear background*/ 1130 /* clear background*/
1116 memset(dst, 0, ((height + 7) / 8) * width); 1131 memset(dst, 0, needed_size);
1117 1132
1118 dst_mask = 1; 1133 dst_mask = 1;
1119 1134
@@ -1145,17 +1160,21 @@ int rotleft(unsigned char *dst, /* output buffer */
1145 dst += width; /* next output byte row */ 1160 dst += width; /* next output byte row */
1146 } 1161 }
1147 } 1162 }
1148 return ((height + 7) / 8) * width; /* return result size in bytes */ 1163 return needed_size; /* return result size in bytes */
1149} 1164}
1150 1165
1166#endif /* ROTATE */
1167
1151 1168
1152/* generate C source from in-core font*/ 1169/* generate C source from in-core font*/
1153int gen_c_source(struct font* pf, char *path) 1170int gen_c_source(struct font* pf, char *path)
1154{ 1171{
1155 FILE *ofp; 1172 FILE *ofp;
1156 int i, ofr = 0; 1173 int i;
1157 time_t t = time(0); 1174 time_t t = time(0);
1158#ifndef ROTATE 1175#ifdef ROTATE
1176 int ofr = 0;
1177#else
1159 int did_syncmsg = 0; 1178 int did_syncmsg = 0;
1160 bitmap_t *ofs = pf->bits; 1179 bitmap_t *ofs = pf->bits;
1161#endif 1180#endif
@@ -1211,6 +1230,7 @@ int gen_c_source(struct font* pf, char *path)
1211 int bitcount = 0; 1230 int bitcount = 0;
1212 int width = pf->width ? pf->width[i] : pf->maxwidth; 1231 int width = pf->width ? pf->width[i] : pf->maxwidth;
1213 int height = pf->height; 1232 int height = pf->height;
1233 int char_code = pf->firstchar + i;
1214 bitmap_t *bits; 1234 bitmap_t *bits;
1215 bitmap_t bitvalue=0; 1235 bitmap_t bitvalue=0;
1216 1236
@@ -1221,7 +1241,7 @@ int gen_c_source(struct font* pf, char *path)
1221 bits = pf->bits + (pf->offset? (int)pf->offset[i]: (pf->height * i)); 1241 bits = pf->bits + (pf->offset? (int)pf->offset[i]: (pf->height * i));
1222 1242
1223 fprintf(ofp, "\n/* Character %d (0x%02x):\n width %d", 1243 fprintf(ofp, "\n/* Character %d (0x%02x):\n width %d",
1224 i+pf->firstchar, i+pf->firstchar, width); 1244 char_code, char_code, width);
1225 1245
1226 if (gen_map) { 1246 if (gen_map) {
1227 fprintf(ofp, "\n +"); 1247 fprintf(ofp, "\n +");
@@ -1259,11 +1279,15 @@ int gen_c_source(struct font* pf, char *path)
1259 bits = pf->bits + (pf->offset? (int)pf->offset[i]: (pf->height * i)); 1279 bits = pf->bits + (pf->offset? (int)pf->offset[i]: (pf->height * i));
1260#ifdef ROTATE /* pre-rotated into Rockbox bitmap format */ 1280#ifdef ROTATE /* pre-rotated into Rockbox bitmap format */
1261 { 1281 {
1262 unsigned char bytemap[512]; 1282 unsigned char bytemap[ROTATION_BUF_SIZE];
1263 int y8, ix=0; 1283 int y8, ix=0;
1264 1284
1265 int size = rotleft(bytemap, sizeof(bytemap), bits, width, 1285 int size = rotleft(bytemap, sizeof(bytemap), bits, width,
1266 pf->height); 1286 pf->height, char_code);
1287 if (size < 0) {
1288 return -1;
1289 }
1290
1267 for (y8=0; y8<pf->height; y8+=8) /* column rows */ 1291 for (y8=0; y8<pf->height; y8+=8) /* column rows */
1268 { 1292 {
1269 for (x=0; x<width; x++) { 1293 for (x=0; x<width; x++) {
@@ -1442,7 +1466,7 @@ static int writestr(FILE *fp, char *str, int count)
1442#ifndef ROTATE 1466#ifndef ROTATE
1443static int writestrpad(FILE *fp, char *str, int totlen) 1467static int writestrpad(FILE *fp, char *str, int totlen)
1444{ 1468{
1445 int ret; 1469 int ret = EOF;
1446 1470
1447 while (str && *str && totlen > 0) { 1471 while (str && *str && totlen > 0) {
1448 if (*str) { 1472 if (*str) {
@@ -1499,8 +1523,9 @@ int gen_fnt_file(struct font* pf, char *path)
1499 { 1523 {
1500 bitmap_t* bits; 1524 bitmap_t* bits;
1501 int width = pf->width ? pf->width[i] : pf->maxwidth; 1525 int width = pf->width ? pf->width[i] : pf->maxwidth;
1502 int size; 1526 int size;
1503 unsigned char bytemap[512]; 1527 int char_code = pf->firstchar + i;
1528 unsigned char bytemap[ROTATION_BUF_SIZE];
1504 1529
1505 /* Skip missing glyphs */ 1530 /* Skip missing glyphs */
1506 if (pf->offset && (pf->offset[i] == -1)) 1531 if (pf->offset && (pf->offset[i] == -1))
@@ -1508,7 +1533,10 @@ int gen_fnt_file(struct font* pf, char *path)
1508 1533
1509 bits = pf->bits + (pf->offset? (int)pf->offset[i]: (pf->height * i)); 1534 bits = pf->bits + (pf->offset? (int)pf->offset[i]: (pf->height * i));
1510 1535
1511 size = rotleft(bytemap, sizeof(bytemap), bits, width, pf->height); 1536 size = rotleft(bytemap, sizeof(bytemap), bits, width, pf->height, char_code);
1537 if (size < 0) {
1538 return -1;
1539 }
1512 writestr(ofp, (char *)bytemap, size); 1540 writestr(ofp, (char *)bytemap, size);
1513 1541
1514 /* update offrot since bits are now in sorted order */ 1542 /* update offrot since bits are now in sorted order */
@@ -1554,7 +1582,7 @@ int gen_fnt_file(struct font* pf, char *path)
1554 1582
1555 if (pf->offset) 1583 if (pf->offset)
1556 for (i=0; i<pf->size; ++i) { 1584 for (i=0; i<pf->size; ++i) {
1557 if (pf->offset[i] == (unsigned int)-1) { 1585 if (pf->offset[i] == -1) {
1558 pf->offset[i] = pf->offset[pf->defaultchar - pf->firstchar]; 1586 pf->offset[i] = pf->offset[pf->defaultchar - pf->firstchar];
1559 } 1587 }
1560 writeint(ofp, pf->offset[i]); 1588 writeint(ofp, pf->offset[i]);