freetype-commit
[Top][All Lists]
Advanced

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

[freetype2] gsoc-anurag-2022 9c5a54bed 3/3: Fixed point: converted drawl


From: Werner Lemberg
Subject: [freetype2] gsoc-anurag-2022 9c5a54bed 3/3: Fixed point: converted drawline to fixed
Date: Mon, 3 Oct 2022 17:45:43 -0400 (EDT)

branch: gsoc-anurag-2022
commit 9c5a54bede62b2e3ae55b160bb448ccba9698174
Author: Anurag Thakur <anurag105csec21@bpitindia.edu.in>
Commit: Anurag Thakur <anurag105csec21@bpitindia.edu.in>

    Fixed point: converted drawline to fixed
---
 src/dense/ftdense.c | 146 +++++++++++++++++++++++++++++++++-------------------
 src/dense/ftdense.h |   2 +-
 2 files changed, 94 insertions(+), 54 deletions(-)

diff --git a/src/dense/ftdense.c b/src/dense/ftdense.c
index 3bf94377e..c9bf807ba 100644
--- a/src/dense/ftdense.c
+++ b/src/dense/ftdense.c
@@ -88,69 +88,81 @@ dense_render_line( dense_worker* worker, TPos tox, TPos toy 
)
 {
   // printf("line from: %d, %d to %d, %d\n", worker->prev_x, worker->prev_y,
   // to_x, to_y);
-  float from_x = worker->prev_x;
-  float from_y = worker->prev_y;
+  FT26D6 from_x = worker->prev_x;
+  FT26D6 from_y = worker->prev_y;
+
   if ( from_y == toy )
     return;
 
-  // aP0.m_x -= worker->m_origin_x;
-  // aP0.m_y -= worker->m_origin_y;
-  // aP1.m_x -= worker->m_origin_x;
-  // aP1.m_y -= worker->m_origin_y;
-
-  // from_x = TRUNC( (int)from_x );
-  // from_y = TRUNC( (int)from_y );
-  // to_x   = TRUNC( (int)to_x );
-  // to_y   = TRUNC( (int)to_y );
 
-  from_x /= 256.0;
-  from_y /= 256.0;
-  float to_x = tox / 256.0;
-  float to_y = toy / 256.0;
+  from_x >>= 2;
+  from_y >>= 2;
+  FT26D6 to_x = tox >> 2;
+  FT26D6 to_y = toy >> 2;
 
 
-  //printf("line from: %f, %f to %f, %f\n", from_x, from_y, to_x, to_y);
+  //printf("line from: %d, %d to %d, %d\n", from_x, from_y, to_x, to_y);
 
-  float dir;
-  if ( from_y < to_y )
-    dir = 1;
-  else
-  {
-    dir = -1;
+  FT26D6 dir = 1;
+  if ( from_y >= to_y ){
+    dir = -dir;
     swap( &from_x, &to_x );
     swap( &from_y, &to_y );
   }
 
+
   // Clip to the height.
-  if ( from_y >= worker->m_h || to_y <= 0 )
+  if ( (from_y>>6) >= worker->m_h || to_y <= 0 )
     return;
 
-  float dxdy = ( to_x - from_x ) / (float)( to_y - from_y );
+  //float dxdy = ( to_x - from_x ) / (float)( to_y - from_y );
+  FT26D6 deltax = to_x - from_x;
+  FT26D6 deltay = to_y - from_y;
+
   if ( from_y < 0 )
   {
-    from_x -= from_y * dxdy;
+    from_x -= from_y * deltax/deltay;
     from_y = 0;
   }
-  if ( to_y > worker->m_h )
+
+  if ( (to_y>>6) > worker->m_h )
   {
-    to_x -= ( to_y - worker->m_h ) * dxdy;
-    to_y = (float)worker->m_h;
+    to_x -= ( to_y - (worker->m_h<<6) ) * deltax/deltay;
+    to_y = worker->m_h<<6;
   }
 
-  float  x       = from_x;
-  int    y0      = (int)from_y;
-  int    y_limit = (int)ceil( to_y );
-  float* m_a     = worker->m_a;
+  //float  x       = from_x;
+  FT26D6 x = from_x;
+
+  // int    y0      = (int)from_y;
+  // int    y_limit = (int)ceil( to_y );
+  int    y0      = from_y>>6;
+  int    y_limit = ( to_y + 0x3f)>>6;
+
+ // printf("y0, ylimit: %d, %d\n", y0, y_limit);
+
+  if(y_limit > worker->m_h){
+    y_limit = worker->m_h;
+    
+  }
+
+  FT20D12* m_a     = worker->m_a;
 
   for ( int y = y0; y < y_limit; y++ )
   {
    // printf("y is %d\n", y);
     int   linestart = y * worker->m_w;
-    float dy        = fmin( y + 1.0f, to_y ) - fmax( (float)y, from_y );
-    float xnext     = x + dxdy * dy;
-    float d         = dy * dir;
+    //float dy        = fmin( y + 1.0f, to_y ) - fmax( (float)y, from_y );
+    FT26D6 dy = min((y+1)<<6, to_y) - max(y<<6, from_y);
+
+    printf("dy: %f\n", (float)dy/(1<<6));
+    //float xnext     = x + dxdy * dy;
+    FT26D6 xnext = x + dy*deltax/deltay;
+
+    //float d         = dy * dir;
+    int d = dy*dir;
 
-    float x0, x1;
+    FT26D6 x0, x1;
     if ( x < xnext )
     {
       x0 = x;
@@ -167,36 +179,64 @@ dense_render_line( dense_worker* worker, TPos tox, TPos 
toy )
     floating-point inaccuracy That would cause an out-of-bounds array access at
     index -1.
     */
-    float x0floor = x0 <= 0.0f ? 0.0f : (float)floor( x0 );
+    //float x0floor = x0 <= 0.0f ? 0.0f : (float)floor( x0 );
 
-    int   x0i    = (int)x0floor;
-    float x1ceil = (float)ceil( x1 );
-    int   x1i    = (int)x1ceil;
+    //int   x0i    = (int)x0floor;
+    int x0i = x0 >>6;
+
+    //float x1ceil = (float)ceil( x1 );
+    FT26D6 x0floor = x0i<<6;
+
+    //int   x1i    = (int)x1ceil;
+    int x1i = (x1+0x3f)>>6;
+
+    FT26D6 x1ceil = x1i<<6;
     if ( x1i <= x0i + 1 )
     {
-      float xmf = 0.5f * ( x + xnext ) - x0floor;
-      m_a[linestart + x0i] += d - d * xmf;
+      //float xmf = 0.5f * ( x + xnext ) - x0floor;
+      FT26D6 xmf = ( x + xnext )>>1 - x0floor;
+     // m_a[linestart + x0i] += d - d * xmf;
+      m_a[linestart + x0i] += d * (1<<6 - xmf);
+    //  m_a[linestart + ( x0i + 1 )] += d * xmf;
       m_a[linestart + ( x0i + 1 )] += d * xmf;
     }
     else
     {
-      float s   = 1.0f / ( x1 - x0 );
-      float x0f = x0 - x0floor;
-      float a0  = 0.5f * s * ( 1.0f - x0f ) * ( 1.0f - x0f );
-      float x1f = x1 - x1ceil + 1.0f;
-      float am  = 0.5f * s * x1f * x1f;
+      //float s   = 1.0f / ( x1 - x0 );
+      FT26D6 oneOverS = x1 - x0;
+      //float x0f = x0 - x0floor;
+      FT26D6 x0f = x0 - x0floor;
+      FT26D6 oneMinusX0 = 1<<6 - x0f;
+      
+      //float a0  = 0.5f * s * ( 1.0f - x0f ) * ( 1.0f - x0f );
+      int a0 = ((oneMinusX0 * oneMinusX0) >> 1) / oneOverS;
+
+      //float x1f = x1 - x1ceil + 1.0f;
+      FT26D6 x1f = x1 - x1ceil + 1<<6;
+
+      //float am  = 0.5f * s * x1f * x1f;
+      int am = ((x1f * x1f) >> 1) / oneOverS;
+
       m_a[linestart + x0i] += d * a0;
+
       if ( x1i == x0i + 2 )
-        m_a[linestart + ( x0i + 1 )] += d * ( 1.0f - a0 - am );
+        m_a[linestart + ( x0i + 1 )] += d * ( 1<<6 - a0 - am );
       else
       {
-        float a1 = s * ( 1.5f - x0f );
+        //float a1 = s * ( 1.5f - x0f );
+        int a1 = ((1<<6 + 1<<5 - x0f) << 6) / oneOverS;
+
         m_a[linestart + ( x0i + 1 )] += d * ( a1 - a0 );
+
+        int                            dTimesS = (d << 12) / oneOverS;
         for ( int xi = x0i + 2; xi < x1i - 1; xi++ )
-          m_a[linestart + xi] += d * s;
-        float a2 = a1 + ( x1i - x0i - 3 ) * s;
+          m_a[linestart + xi] += dTimesS;
+
+        float a2 = a1 + (( x1i - x0i - 3 )<<12) / oneOverS;
+
         m_a[linestart + ( x1i - 1 )] += d * ( 1.0f - a2 - am );
       }
+
       m_a[linestart + x1i] += d * am;
     }
     x = xnext;
@@ -411,11 +451,11 @@ dense_render_glyph( dense_worker* worker, const 
FT_Bitmap* target )
   //float          value    = 0.0f;
   while ( dest < dest_end )
   {
+    //printf("%d\n", *source);
     valnew += *source++;
 
     if(valnew > 0){
-      int nnew = valnew * 255;
-      nnew >>= 4;
+      int nnew = valnew >> 4;
 
       if(nnew>255)nnew=255;
       *dest = (unsigned char)nnew;
diff --git a/src/dense/ftdense.h b/src/dense/ftdense.h
index bc6d16c61..38e9284ea 100644
--- a/src/dense/ftdense.h
+++ b/src/dense/ftdense.h
@@ -41,7 +41,7 @@ extern "C"
 #endif
 
   typedef long TPos;
-  typedef unsigned int FT26D6;
+  typedef signed int FT26D6;
   typedef signed int FT20D12;
 
   typedef struct



reply via email to

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