freetype-commit
[Top][All Lists]
Advanced

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

[freetype2-demos] master d6a7381 2/2: [ftlint] Report integral X- and Y-


From: Werner Lemberg
Subject: [freetype2-demos] master d6a7381 2/2: [ftlint] Report integral X- and Y-acutance.
Date: Mon, 14 Jun 2021 23:35:57 -0400 (EDT)

branch: master
commit d6a7381a6069b6951c9779140412ff5f8acb0583
Author: Alexei Podtelezhnikov <apodtele@gmail.com>
Commit: Alexei Podtelezhnikov <apodtele@gmail.com>

    [ftlint] Report integral X- and Y-acutance.
    
    Acutance is a measure of how quickly the intensity changes between
    the minimum and maximum value at the edges.  We calculate is as a
    ratio of the integrals for the absolute second derivative and the
    absolute first derivative.  It equals to 2.0 for bitmap fonts and
    approahes this value for well hinted fonts.
    
    * src/ftlint.c (Analyze): Implement it.
    (main): Use it.
---
 ChangeLog    | 13 +++++++++++++
 src/ftlint.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index d4c04a7..5d18995 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2021-06-14  Alexei Podtelezhnikov  <apodtele@gmail.com>
 
+       [ftlint] Report integral X- and Y-acutance.
+
+       Acutance is a measure of how quickly the intensity changes between
+       the minimum and maximum value at the edges.  We calculate is as a
+       ratio of the integrals for the absolute second derivative and the
+       absolute first derivative.  It equals to 2.0 for bitmap fonts and
+       approahes this value for well hinted fonts.
+
+       * src/ftlint.c (Analyze): Implement it.
+       (main): Use it.
+
+2021-06-14  Alexei Podtelezhnikov  <apodtele@gmail.com>
+
        * src/ftlint.c (main): Report bitmap size, improve output formatting.
        (Checksum): Updated.
 
diff --git a/src/ftlint.c b/src/ftlint.c
index 01a4e4f..ebaafcf 100644
--- a/src/ftlint.c
+++ b/src/ftlint.c
@@ -69,6 +69,55 @@
   }
 
 
+  /* Analyze X- and Y-acutance; bitmap should have positive pitch */
+  static void
+  Analyze( FT_Bitmap* bitmap )
+  {
+    unsigned int   i, j;
+    unsigned char  *b;
+    unsigned long  s1, s2;
+    long           d0, d1;
+
+
+    /* X-acutance */
+    for ( b = bitmap->buffer, s1 = s2 = 0, i = 0; i < bitmap->rows; i++ )
+    {
+      for ( d0 = d1 = 0, j = 0; j < bitmap->pitch; j++, b++ )
+      {
+        d1 -= *b;
+        s2 += d1 >= d0 ? d1 - d0 : d0 - d1;  /* second derivative sum */
+        s1 += d1 >= 0 ? d1 : -d1;            /*  first derivative sum */
+        d0  = d1;
+        d1  = *b;
+      }
+      s2 += d1 > d0 ? d1 - d0 : d0 - d1;
+      s2 += d1;
+      s1 += d1;
+    }
+
+    printf( "X=%.4lf  ", s1 ? (double)s2 / s1 : 2.0 );
+
+    /* Y-acutance */
+    for ( s1 = s2 = 0, j = 0; j < bitmap->pitch; j++ )
+    {
+      b = bitmap->buffer + j;
+      for ( d0 = d1 = 0, i = 0; i < bitmap->rows; i++, b += bitmap->pitch )
+      {
+        d1 -= *b;
+        s2 += d1 >= d0 ? d1 - d0 : d0 - d1;  /* second derivative sum */
+        s1 += d1 >= 0 ? d1 : -d1;            /*  first derivative sum */
+        d0  = d1;
+        d1  = *b;
+      }
+      s2 += d1 > d0 ? d1 - d0 : d0 - d1;
+      s2 += d1;
+      s1 += d1;
+    }
+
+    printf( "Y=%.4lf  ", s1 ? (double)s2 / s1 : 2.0 );
+  }
+
+
   /* Calculate MD5 checksum; bitmap should have positive pitch */
   static void
   Checksum( FT_Bitmap* bitmap )
@@ -278,6 +327,7 @@
         else
           printf( "%3ux%-4u ", bitmap.width, bitmap.rows );
 
+        Analyze( &bitmap );
         Checksum( &bitmap );
 
         FT_Bitmap_Done( library, &bitmap );



reply via email to

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