[AD] grab_font_from_bitmap speedup patch |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
See http://www.allegro.cc/forums/thread/589885 for background information.
Essentially, the current implementation scans the entire bitmap for the
presence of an alpha channel for each character in the font - which can
slow things down pretty badly.
The attached patch (untested) only does the scan once for each call to
grab_font_from_bitmap.
Evert
Index: src/fontbmp.c
===================================================================
--- src/fontbmp.c (revision 7709)
+++ src/fontbmp.c (working copy)
@@ -24,29 +24,18 @@
/* state information for the bitmap font importer */
static int import_x = 0;
static int import_y = 0;
+static int font_outline_colour = 0;
/* splits bitmaps into sub-sprites, using regions bounded by col #255 */
static void font_find_character(BITMAP *bmp, int *x, int *y, int *w, int *h)
{
- int c;
-
- if (_bitmap_has_alpha(bmp)) {
- c = getpixel(bmp, 0, 0);
- }
- else if (bitmap_color_depth(bmp) == 8) {
- c = 255;
- }
- else {
- c = makecol_depth(bitmap_color_depth(bmp), 255, 255, 0);
- }
-
/* look for top left corner of character */
- while ((getpixel(bmp, *x, *y) != c) ||
- (getpixel(bmp, *x+1, *y) != c) ||
- (getpixel(bmp, *x, *y+1) != c) ||
- (getpixel(bmp, *x+1, *y+1) == c)) {
+ while ((getpixel(bmp, *x, *y) != font_outline_colour) ||
+ (getpixel(bmp, *x+1, *y) != font_outline_colour) ||
+ (getpixel(bmp, *x, *y+1) != font_outline_colour) ||
+ (getpixel(bmp, *x+1, *y+1) == font_outline_colour)) {
(*x)++;
if (*x >= bmp->w) {
*x = 0;
@@ -61,15 +50,15 @@
/* look for right edge of character */
*w = 0;
- while ((getpixel(bmp, *x+*w+1, *y) == c) &&
- (getpixel(bmp, *x+*w+1, *y+1) != c) &&
+ while ((getpixel(bmp, *x+*w+1, *y) == font_outline_colour) &&
+ (getpixel(bmp, *x+*w+1, *y+1) != font_outline_colour) &&
(*x+*w+1 <= bmp->w))
(*w)++;
/* look for bottom edge of character */
*h = 0;
- while ((getpixel(bmp, *x, *y+*h+1) == c) &&
- (getpixel(bmp, *x+1, *y+*h+1) != c) &&
+ while ((getpixel(bmp, *x, *y+*h+1) == font_outline_colour) &&
+ (getpixel(bmp, *x+1, *y+*h+1) != font_outline_colour) &&
(*y+*h+1 <= bmp->h))
(*h)++;
}
@@ -225,6 +214,17 @@
import_x = 0;
import_y = 0;
+ /* Find outline colour for this bitmap */
+ if (_bitmap_has_alpha(bmp)) {
+ font_outline_colour = getpixel(bmp, 0, 0);
+ }
+ else if (bitmap_color_depth(bmp) == 8) {
+ font_outline_colour = 255;
+ }
+ else {
+ font_outline_colour = makecol_depth(bitmap_color_depth(bmp), 255, 255, 0);
+ }
+
f = _AL_MALLOC(sizeof *f);
if (end == -1) end = bitmap_font_count(bmp) + begin;