freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Devel] More rounding


From: Artur Zaprzała
Subject: [Devel] More rounding
Date: Fri, 21 Mar 2003 16:38:21 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030312

Glyph rendering is very sensitive to rounding errors, so I'd like to encourage FreeType developers to provide a comment for each division/shift to make clear whether rounding, floor or ceiling is intended.

Below is a patch for freetype2/src/base/ftobjs.c describing my suggestions.

This formula:
( ( ( xxx ) / 72 ) + 32 ) & -64;
should replaced with more precise one:
( ( xxx + (36+32*72) ) / 72 ) & -64;

And here:
dim_y = ( char_height * vert_resolution ) / 72;
I guess that rounding was intended, but missing:
dim_x = ( char_width  * horz_resolution + 36 ) / 72;



--
Artur Zaprzala
--- ftobjs.c-orig       Thu Mar 20 08:04:40 2003
+++ ftobjs.c    Fri Mar 21 16:36:16 2003
@@ -1427,17 +1427,17 @@
 
     /* Compute pixel sizes in 26.6 units */
 #ifdef FT_CONFIG_CHESTER_BLUE_SCALE
-    dim_x = ( char_width  * horz_resolution ) / 72;
-    dim_y = ( char_height * vert_resolution ) / 72;
+    dim_x = ( char_width  * horz_resolution + 36 ) / 72; /* round div */
+    dim_y = ( char_height * vert_resolution + 36 ) / 72; /* round div */
 
-    metrics->x_ppem = (FT_UShort)( (dim_x+32) >> 6 );
-    metrics->y_ppem = (FT_UShort)( (dim_y+32) >> 6 );
+    metrics->x_ppem = (FT_UShort)( (dim_x+32) >> 6 ); /* round div */
+    metrics->y_ppem = (FT_UShort)( (dim_y+32) >> 6 ); /* round div */
 #else
-    dim_x = ( ( ( char_width  * horz_resolution ) / 72 ) + 32 ) & -64;
-    dim_y = ( ( ( char_height * vert_resolution ) / 72 ) + 32 ) & -64;
+    dim_x = ( ( char_width  * horz_resolution + (36+32*72) ) / 72 ) & -64; /* 
round div */
+    dim_y = ( ( char_height * vert_resolution + (36+32*72) ) / 72 ) & -64; /* 
round div */
 
-    metrics->x_ppem  = (FT_UShort)( dim_x >> 6 );
-    metrics->y_ppem  = (FT_UShort)( dim_y >> 6 );
+    metrics->x_ppem  = (FT_UShort)( dim_x >> 6 ); /* floor div, already 
rounded */
+    metrics->y_ppem  = (FT_UShort)( dim_y >> 6 ); /* floor div, already 
rounded */
 #endif
 
     metrics->x_scale = 0x10000L;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]