From: Mikko Rasa Date: Fri, 4 May 2018 19:15:07 +0000 (+0300) Subject: Improve distance field accuracy X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=1fb6f37cfa76c47b65331b6fe8217f8973f35885;p=ttf2png.git Improve distance field accuracy A better initial guess allows the square root function to deal with larger numbers. --- diff --git a/ttf2png.c b/ttf2png.c index 5e6e351..bf9f8d2 100644 --- a/ttf2png.c +++ b/ttf2png.c @@ -694,15 +694,9 @@ int copy_bitmap(const FT_Bitmap *bmp, Image *image) unsigned sqrti(unsigned num) { - unsigned result = num; - while(result*result>num) - { - unsigned diff = result*result-num; - if(diff0xFFFF ? 0xFFFF : 0x100); + while(result && result*result>=result+num) + result -= (result*result+result-num)/(result*2); return result; } @@ -740,7 +734,7 @@ unsigned find_distance_to_edge(const Image *image, int origin_x, int origin_y, u } } - return sqrti(closest)*0x7F/range; + return sqrti(closest*0x3F01)/range; } int create_distance_field(const FT_Bitmap *bmp, Image *image, unsigned scale, unsigned margin)