From 4ef7d07a442cb7b3277a3f3405a12042e1feb2c4 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 10 Jan 2016 19:58:23 -0700 Subject: [PATCH] ttf: Correct direct use of fabs() Add a macro to allow fabs() to be provided by the user, as with the other maths functions. Update the implementation code to use it instead of fasb(). Signed-off-by: Simon Glass --- stb_truetype.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/stb_truetype.h b/stb_truetype.h index 00d22eb..d3ba508 100644 --- a/stb_truetype.h +++ b/stb_truetype.h @@ -403,6 +403,11 @@ int main(int arg, char **argv) #define STBTT_sqrt(x) sqrt(x) #endif + #ifndef STBTT_fabs + #include + #define STBTT_fabs(x) fabs(x) + #endif + // #define your own functions "STBTT_malloc" / "STBTT_free" to avoid malloc.h #ifndef STBTT_malloc #include @@ -1986,7 +1991,7 @@ static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill, } y_crossing += dy * (x2 - (x1+1)); - STBTT_assert(fabs(area) <= 1.01f); + STBTT_assert(STBTT_fabs(area) <= 1.01f); scanline[x2] += area + sign * (1-((x2-x2)+(x_bottom-x2))/2) * (sy1-y_crossing); @@ -2120,7 +2125,7 @@ static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e, int m; sum += scanline2[i]; k = scanline[i] + sum; - k = (float) fabs(k)*255 + 0.5f; + k = (float) STBTT_fabs(k)*255 + 0.5f; m = (int) k; if (m > 255) m = 255; result->pixels[j*result->stride + i] = (unsigned char) m;