freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype-demos][master] 2 commits: * src/ftlint.c (main):


From: Alexei Podtelezhnikov (@apodtele)
Subject: [Git][freetype/freetype-demos][master] 2 commits: * src/ftlint.c (main): Report bitmap size, improve output formatting.
Date: Tue, 15 Jun 2021 03:35:54 +0000

Alexei Podtelezhnikov pushed to branch master at FreeType / FreeType Demo Programs

Commits:

2 changed files:

Changes:

  • ChangeLog
    1 1
     2021-06-14  Alexei Podtelezhnikov  <apodtele@gmail.com>
    
    2 2
     
    
    3
    -	* bin/ftlint.c (main): Implement limited indexing.
    
    3
    +	[ftlint] Report integral X- and Y-acutance.
    
    4
    +
    
    5
    +	Acutance is a measure of how quickly the intensity changes between
    
    6
    +	the minimum and maximum value at the edges.  We calculate is as a
    
    7
    +	ratio of the integrals for the absolute second derivative and the
    
    8
    +	absolute first derivative.  It equals to 2.0 for bitmap fonts and
    
    9
    +	approahes this value for well hinted fonts.
    
    10
    +
    
    11
    +	* src/ftlint.c (Analyze): Implement it.
    
    12
    +	(main): Use it.
    
    13
    +
    
    14
    +2021-06-14  Alexei Podtelezhnikov  <apodtele@gmail.com>
    
    15
    +
    
    16
    +	* src/ftlint.c (main): Report bitmap size, improve output formatting.
    
    17
    +	(Checksum): Updated.
    
    18
    +
    
    19
    +2021-06-14  Alexei Podtelezhnikov  <apodtele@gmail.com>
    
    20
    +
    
    21
    +	* src/ftlint.c (main): Implement limited indexing.
    
    4 22
     	(Usage): Document it.
    
    5 23
     
    
    6 24
     2021-06-13  Sarthak Bhardwaj  <1sarthakbhardwaj@gmail.com>
    

  • src/ftlint.c
    ... ... @@ -68,41 +68,72 @@
    68 68
         exit(1);
    
    69 69
       }
    
    70 70
     
    
    71
    +
    
    72
    +  /* Analyze X- and Y-acutance; bitmap should have positive pitch */
    
    71 73
       static void
    
    72
    -  Checksum( FT_GlyphSlot glyph )
    
    74
    +  Analyze( FT_Bitmap* bitmap )
    
    73 75
       {
    
    74
    -      FT_Bitmap  bitmap;
    
    75
    -      FT_Error err;
    
    76
    -      FT_Bitmap_Init( &bitmap );
    
    76
    +    unsigned int   i, j;
    
    77
    +    unsigned char  *b;
    
    78
    +    unsigned long  s1, s2;
    
    79
    +    long           d0, d1;
    
    80
    +
    
    77 81
     
    
    82
    +    /* X-acutance */
    
    83
    +    for ( b = bitmap->buffer, s1 = s2 = 0, i = 0; i < bitmap->rows; i++ )
    
    84
    +    {
    
    85
    +      for ( d0 = d1 = 0, j = 0; j < bitmap->pitch; j++, b++ )
    
    86
    +      {
    
    87
    +        d1 -= *b;
    
    88
    +        s2 += d1 >= d0 ? d1 - d0 : d0 - d1;  /* second derivative sum */
    
    89
    +        s1 += d1 >= 0 ? d1 : -d1;            /*  first derivative sum */
    
    90
    +        d0  = d1;
    
    91
    +        d1  = *b;
    
    92
    +      }
    
    93
    +      s2 += d1 > d0 ? d1 - d0 : d0 - d1;
    
    94
    +      s2 += d1;
    
    95
    +      s1 += d1;
    
    96
    +    }
    
    78 97
     
    
    79
    -      printf( "#%u ", glyph->glyph_index );
    
    98
    +    printf( "X=%.4lf  ", s1 ? (double)s2 / s1 : 2.0 );
    
    80 99
     
    
    81
    -      err = FT_Bitmap_Convert( library, &glyph->bitmap, &bitmap, 1 );
    
    82
    -      if ( !err )
    
    100
    +    /* Y-acutance */
    
    101
    +    for ( s1 = s2 = 0, j = 0; j < bitmap->pitch; j++ )
    
    102
    +    {
    
    103
    +      b = bitmap->buffer + j;
    
    104
    +      for ( d0 = d1 = 0, i = 0; i < bitmap->rows; i++, b += bitmap->pitch )
    
    83 105
           {
    
    84
    -        MD5_CTX        ctx;
    
    85
    -        unsigned char  md5[16];
    
    86
    -        int            i;
    
    87
    -        int            rows  = (int)bitmap.rows;
    
    88
    -        int            pitch = bitmap.pitch;
    
    89
    -
    
    90
    -        MD5_Init( &ctx );
    
    91
    -        if ( bitmap.buffer )
    
    92
    -          MD5_Update( &ctx, bitmap.buffer,
    
    93
    -                      (unsigned long)rows * (unsigned long)pitch );
    
    94
    -        MD5_Final( md5, &ctx );
    
    95
    -
    
    96
    -        for ( i = 0; i < 16; i++ )
    
    97
    -        {
    
    98
    -          printf( "%02X", md5[i] );
    
    99
    -        }
    
    100
    -        printf( "\n" );
    
    106
    +        d1 -= *b;
    
    107
    +        s2 += d1 >= d0 ? d1 - d0 : d0 - d1;  /* second derivative sum */
    
    108
    +        s1 += d1 >= 0 ? d1 : -d1;            /*  first derivative sum */
    
    109
    +        d0  = d1;
    
    110
    +        d1  = *b;
    
    101 111
           }
    
    102
    -      else
    
    103
    -        printf("Error generating checksums\n");
    
    112
    +      s2 += d1 > d0 ? d1 - d0 : d0 - d1;
    
    113
    +      s2 += d1;
    
    114
    +      s1 += d1;
    
    115
    +    }
    
    104 116
     
    
    105
    -      FT_Bitmap_Done( library, &bitmap );
    
    117
    +    printf( "Y=%.4lf  ", s1 ? (double)s2 / s1 : 2.0 );
    
    118
    +  }
    
    119
    +
    
    120
    +
    
    121
    +  /* Calculate MD5 checksum; bitmap should have positive pitch */
    
    122
    +  static void
    
    123
    +  Checksum( FT_Bitmap* bitmap )
    
    124
    +  {
    
    125
    +    MD5_CTX        ctx;
    
    126
    +    unsigned char  md5[16];
    
    127
    +    int            i;
    
    128
    +
    
    129
    +    MD5_Init( &ctx );
    
    130
    +    if ( bitmap->buffer )
    
    131
    +      MD5_Update( &ctx, bitmap->buffer,
    
    132
    +                  (unsigned long)bitmap->rows * (unsigned long)bitmap->pitch );
    
    133
    +    MD5_Final( md5, &ctx );
    
    134
    +
    
    135
    +    for ( i = 0; i < 16; i++ )
    
    136
    +       printf( "%02X", md5[i] );
    
    106 137
       }
    
    107 138
     
    
    108 139
     
    
    ... ... @@ -270,21 +301,38 @@
    270 301
             Panic( "Could not set character size" );
    
    271 302
     
    
    272 303
           Fail = 0;
    
    304
    +      for ( id = first_index; id <= last_index; id++ )
    
    273 305
           {
    
    274
    -        for ( id = first_index; id <= last_index; id++ )
    
    275
    -        {
    
    276
    -          error = FT_Load_Glyph( face, id, load_flags );
    
    277
    -          if ( error )
    
    278
    -          {
    
    279
    -            if ( Fail < 10 )
    
    280
    -              printf( "glyph %4u: 0x%04x\n" , id, error );
    
    281
    -            Fail++;
    
    282
    -            continue;
    
    283
    -          }
    
    306
    +        FT_Bitmap  bitmap;
    
    284 307
     
    
    285
    -          FT_Render_Glyph( face->glyph, render_mode );
    
    286
    -          Checksum( face->glyph );
    
    308
    +
    
    309
    +        printf( "%5u: ", id );
    
    310
    +
    
    311
    +        error = FT_Load_Glyph( face, id, load_flags );
    
    312
    +        if ( error )
    
    313
    +        {
    
    314
    +          printf( "error = 0x%04x\n" , error );
    
    315
    +          Fail++;
    
    316
    +          continue;
    
    287 317
             }
    
    318
    +
    
    319
    +        FT_Render_Glyph( face->glyph, render_mode );
    
    320
    +
    
    321
    +        FT_Bitmap_Init( &bitmap );
    
    322
    +
    
    323
    +        /* convert to an 8-bit bitmap with a positive pitch */
    
    324
    +        error = FT_Bitmap_Convert( library, &face->glyph->bitmap, &bitmap, 1 );
    
    325
    +        if ( error )
    
    326
    +          printf( "error = 0x%04x", error );
    
    327
    +        else
    
    328
    +          printf( "%3ux%-4u ", bitmap.width, bitmap.rows );
    
    329
    +
    
    330
    +        Analyze( &bitmap );
    
    331
    +        Checksum( &bitmap );
    
    332
    +
    
    333
    +        FT_Bitmap_Done( library, &bitmap );
    
    334
    +
    
    335
    +        printf( "\n" );
    
    288 336
           }
    
    289 337
     
    
    290 338
           if ( Fail == 0 )
    


  • reply via email to

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