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 <sjg@chromium.org>
This commit is contained in:
Simon Glass 2016-01-10 19:58:23 -07:00
parent fc8b649466
commit 4ef7d07a44

View File

@ -403,6 +403,11 @@ int main(int arg, char **argv)
#define STBTT_sqrt(x) sqrt(x) #define STBTT_sqrt(x) sqrt(x)
#endif #endif
#ifndef STBTT_fabs
#include <math.h>
#define STBTT_fabs(x) fabs(x)
#endif
// #define your own functions "STBTT_malloc" / "STBTT_free" to avoid malloc.h // #define your own functions "STBTT_malloc" / "STBTT_free" to avoid malloc.h
#ifndef STBTT_malloc #ifndef STBTT_malloc
#include <stdlib.h> #include <stdlib.h>
@ -1986,7 +1991,7 @@ static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill,
} }
y_crossing += dy * (x2 - (x1+1)); 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); 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; int m;
sum += scanline2[i]; sum += scanline2[i];
k = scanline[i] + sum; k = scanline[i] + sum;
k = (float) fabs(k)*255 + 0.5f; k = (float) STBTT_fabs(k)*255 + 0.5f;
m = (int) k; m = (int) k;
if (m > 255) m = 255; if (m > 255) m = 255;
result->pixels[j*result->stride + i] = (unsigned char) m; result->pixels[j*result->stride + i] = (unsigned char) m;