Revision: 3588
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3588&view=rev
Author: mdboom
Date: 2007-07-20 07:08:58 -0700 (Fri, 20 Jul 2007)
Log Message:
-----------
Make draw_bitmap inner loop faster and prevent segfaults if x and y
are negative.
Modified Paths:
--------------
branches/mathtext_mgd/src/ft2font.cpp
Modified: branches/mathtext_mgd/src/ft2font.cpp
===================================================================
--- branches/mathtext_mgd/src/ft2font.cpp 2007-07-20 13:46:20 UTC (rev 3587)
+++ branches/mathtext_mgd/src/ft2font.cpp 2007-07-20 14:08:58 UTC (rev 3588)
@@ -876,25 +876,28 @@
return Py::Int(- bbox.yMin);;
}
+#undef CLAMP
+#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
+
void
FT2Font::draw_bitmap( FT_Bitmap* bitmap,
FT_Int x,
FT_Int y) {
_VERBOSE("FT2Font::draw_bitmap");
FT_Int i, j, p, q;
- FT_Int x_max = x + bitmap->width;
- FT_Int y_max = y + bitmap->rows;
-
FT_Int width = (FT_Int)image.width;
FT_Int height = (FT_Int)image.height;
- for ( i = x, p = 0; i < x_max; i++, p++ )
+
+ FT_Int x1 = CLAMP(x, 0, width);
+ FT_Int y1 = CLAMP(y, 0, height);
+ FT_Int x2 = CLAMP(x + bitmap->width, 0, width);
+ FT_Int y2 = CLAMP(y + bitmap->rows, 0, height);
+
+ for ( i = x1, p = 0; i < x2; ++i, ++p )
{
- for ( j = y, q = 0; j < y_max; j++, q++ )
+ for ( j = y1, q = 0; j < y2; ++j, ++q )
{
- if ( i >= width || j >= height )
- continue;
- image.buffer[i + j*width] |= bitmap->buffer[p + q*bitmap->width];
-
+ image.buffer[i + j*width] |= bitmap->buffer[p + q*bitmap->pitch];
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|