freetype-commit
[Top][All Lists]
Advanced

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

[freetype2-demos] master 2cc4c50: [ftgamma] Provide alternative pattern.


From: Alexei Podtelezhnikov
Subject: [freetype2-demos] master 2cc4c50: [ftgamma] Provide alternative pattern.
Date: Sun, 10 Jan 2016 04:31:13 +0000

branch: master
commit 2cc4c50edcf41a2cf5ed1c19187b51dcd2f29b6f
Author: Alexei Podtelezhnikov <address@hidden>
Commit: Alexei Podtelezhnikov <address@hidden>

    [ftgamma] Provide alternative pattern.
    
    * src/ftgamma.c (do_ptrn, GammaPtrn): Implement sligntly slanted
    anti-aliased lines.
    (Process_Event, event_help, main): Updated.
    * src/ftgamma.1: Updated.
---
 ChangeLog     |    9 ++++++
 src/ftgamma.1 |   12 ++++++--
 src/ftgamma.c |   89 ++++++++++++++++++++++++++++++++++++++++++++++++++------
 3 files changed, 97 insertions(+), 13 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index bd8ee18..8592ade 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2016-01-09  Alexei Podtelezhnikov  <address@hidden>
+
+       [ftgamma] Provide alternative pattern.
+
+       * src/ftgamma.c (do_ptrn, GammaPtrn): Implement sligntly slanted
+       anti-aliased lines.
+       (Process_Event, event_help, main): Updated.
+       * src/ftgamma.1: Updated.
+
 2016-01-04  Alexei Podtelezhnikov  <address@hidden>
 
        [ftgamma] Enable color.
diff --git a/src/ftgamma.1 b/src/ftgamma.1
index b149959..660529b 100644
--- a/src/ftgamma.1
+++ b/src/ftgamma.1
@@ -18,13 +18,19 @@ The
 demo program opens a window showing series of grey stripes filled with
 solid color and checkered pattern of pixels.  Your monitor's gamma value
 roughly corresponds to the horizontal position where the solid and checkered
-stripes are equally bright when seen from some distance. Three brightness
-targets are explored: 33%, 50%, and 67%. If the input-output curve of your
+stripes are equally bright when seen from some distance.  Three brightness
+targets are explored: 33%, 50%, and 67%.  If the input-output curve of your
 monitor does not follow ideal power law relationship, you might observe
-slightly different gamma values at different brightness levels. It is also
+slightly different gamma values at different brightness levels.  It is also
 possible to examine gamma values for basic colors.
 .
 .PP
+An alternative pattern of slightly slanted anti-aliased lines is provided
+to calibrate gamma for uniform perceived thickness of the lines.  The gamma
+value that corresponds to vanishing moiré pattern is ideal for anti-aliased
+font rendering.
+.
+.PP
 This program does not have any options.
 .
 .PP
diff --git a/src/ftgamma.c b/src/ftgamma.c
index 03ce599..75669e7 100644
--- a/src/ftgamma.c
+++ b/src/ftgamma.c
@@ -2,7 +2,7 @@
 /*                                                                          */
 /*  The FreeType project -- a free and portable quality TrueType renderer.  */
 /*                                                                          */
-/*  Copyright 2004, 2005, 2012 by                                           */
+/*  Copyright 2004-2016 by                                                  */
 /*  D. Turner, R.Wilhelm, and W. Lemberg                                    */
 /*                                                                          */
 /*                                                                          */
@@ -17,6 +17,72 @@
 
   static FTDemo_Display*  display;
 
+  grBitmap   bit1 = { 300, 600, 600, gr_pixel_mode_gray, 256 };
+  grBitmap   bit2 = { 300, 600, 600, gr_pixel_mode_gray, 256 };
+  grBitmap*  bit;
+
+
+  static void
+  do_ptrn( grBitmap*  bitmap,
+           int        x,
+           int        y,
+           int        w,
+           int        h )
+  {
+    int     pitch = bitmap->pitch;
+    int     i, j, k;
+    double  p[4];
+
+    unsigned char*  line;
+
+    for ( i = 0; i < h; i++ )
+    {
+      for ( k = 0; k < 4; k++)
+      {
+        j = 2 * i + 1 + ( k - 4 ) * h / 2;
+        if ( j > h )
+          j -= 2 * h;
+        if ( j < -h )
+          j += 2 * h;
+        if ( j < 0 )
+          j = -j;
+        j -= h / 4;
+        if ( j < 0 )
+          j = 0;
+        if ( j > h / 2 )
+          j = h / 2;
+
+        p[k] = 2. * j / h;
+      }
+
+      line = bitmap->buffer + ( y + i ) * pitch + x;
+      for ( j = 0, k = 0; j < w; j++ )
+      {
+        line[j] = 0.5 + 255. * pow ( p[k], 1. / (1. + 2. * j / w ) );
+        k++;
+        if ( k == 4 )
+          k = 0;
+      }
+    }
+  }
+
+
+  static FT_Error
+  GammaPtrn( grBitmap*  bitmap )
+  {
+    int  x = 0;
+    int  y = 0;
+    int  h = ( bitmap->rows - 2 * y ) / 3;
+    int  w = bitmap->width - 2 * x;
+
+
+    do_ptrn( bitmap, x,    y, w, h );
+    do_ptrn( bitmap, x, y+=h, w, h );
+    do_ptrn( bitmap, x, y+=h, w, h );
+
+    return 0;
+  }
+
 
   static void
   do_fill( grBitmap*  bitmap,
@@ -109,6 +175,7 @@
     grWriteln( "F1, ?       display this help screen" );
     grLn();
     grWriteln( "space       cycle through color");
+    grWriteln( "tab         alternate pattern");
     grWriteln( "G           show gamma ramp" );
     grLn();
     grLn();
@@ -267,6 +334,11 @@
       event_color_change();
       break;
 
+    case grKeyTab:
+      bit = bit == &bit1 ? &bit2
+                         : &bit1;
+      break;
+
     case grKEY( 'G' ):
       event_gamma_grid();
       break;
@@ -282,7 +354,6 @@
   int
   main( void )
   {
-    grBitmap         bit;
     grEvent          event;
     char             buf[4];
     int              i;
@@ -295,22 +366,20 @@
 
     grSetTitle( display->surface, "FreeType Gamma Matcher - press ? for help" 
);
 
-    bit.rows = 300;
-    bit.width = 600;
-    bit.pitch = 600;
-    bit.grays = 256;
-    bit.mode = gr_pixel_mode_gray;
+    grNewBitmap( bit1.mode, bit1.grays, bit1.width, bit1.rows, &bit1 );
+    GammaGrid( &bit1 );
 
-    grNewBitmap( bit.mode, bit.grays, bit.width, bit.rows, &bit );
-    GammaGrid( &bit );
+    grNewBitmap( bit2.mode, bit2.grays, bit2.width, bit2.rows, &bit2 );
+    GammaPtrn( &bit2 );
 
+    bit = &bit1;
     event_color_change();
 
     do
     {
       FTDemo_Display_Clear( display );
 
-      Render_Bitmap( display->bitmap, &bit, 20, 90, display->fore_color );
+      Render_Bitmap( display->bitmap, bit, 20, 90, display->fore_color );
 
       for ( i = 0; i <= 10; i++ )
       {



reply via email to

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