freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype-demos][master] * graph/gblender.c (gblender_set_


From: Alexei Podtelezhnikov (@apodtele)
Subject: [Git][freetype/freetype-demos][master] * graph/gblender.c (gblender_set_gamma_table): Updated sRGB ramps.
Date: Wed, 17 Aug 2022 04:15:56 +0000

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

Commits:

  • af5c17e8
    by Alexei Podtelezhnikov at 2022-08-17T00:09:17-04:00
    * graph/gblender.c (gblender_set_gamma_table): Updated sRGB ramps.
    
    When we use finite approxination it is more appropriate to use the
    actual values for the linear portion instead of the standard ones.
    

1 changed file:

Changes:

  • graph/gblender.c
    ... ... @@ -66,34 +66,53 @@ gblender_set_gamma_table( double gamma_value,
    66 66
     {
    
    67 67
       const int  gmax = (256 << GBLENDER_GAMMA_SHIFT) - 1;
    
    68 68
       double     p;
    
    69
    +  int        ii;
    
    70
    +
    
    69 71
     
    
    70 72
       if ( gamma_value <= 0 )  /* special case for sRGB */
    
    71 73
       {
    
    72
    -    int     ii;
    
    74
    +    double  d;
    
    75
    +    int     linear = 0;
    
    76
    +
    
    73 77
     
    
    74 78
         /* voltage to linear; power function using finite differences */
    
    75
    -    for ( p = gmax, ii = 255; ii > (int)(255.*0.039285714); ii-- )
    
    79
    +    for ( p = gmax, ii = 255; ii >= 0; ii--, p -= d )
    
    76 80
         {
    
    77 81
           gamma_ramp[ii] = (unsigned short)( p + 0.5 );
    
    78
    -      p -= 2.4 * p / ( ii + 255. * 0.055 );
    
    82
    +
    
    83
    +      if ( linear )
    
    84
    +        continue;
    
    85
    +
    
    86
    +      d = 2.4 * p / ( ii + 255. * 0.055 );  /* derivative */
    
    87
    +
    
    88
    +      if ( ii == 10 )  /* same as d < p / ii */
    
    89
    +      {
    
    90
    +        d = p / ii;
    
    91
    +        linear = 1;
    
    92
    +      }
    
    79 93
         }
    
    80
    -    for ( ; ii >= 0; ii-- )
    
    81
    -      gamma_ramp[ii] = (unsigned short)( gmax*ii/(255.*12.92321) + 0.5 );
    
    82 94
     
    
    95
    +    linear = 0;
    
    83 96
     
    
    84 97
         /* linear to voltage; power function using finite differences */
    
    85
    -    for ( p = 255., ii = gmax; ii > (int)(gmax*0.0030399346); ii-- )
    
    98
    +    for ( p = 255., ii = gmax; ii >= 0; ii--, p -= d )
    
    86 99
         {
    
    87 100
           gamma_ramp_inv[ii] = (unsigned char)( p + 0.5 );
    
    88
    -      p -= ( p + 255. * 0.055 ) / ( 2.4 * ii );
    
    101
    +
    
    102
    +      if ( linear )
    
    103
    +        continue;
    
    104
    +
    
    105
    +      d = ( p + 255. * 0.055 ) / ( 2.4 * ii );  /* derivative */
    
    106
    +
    
    107
    +      if ( p < 10.02 )  /* same as d > p / ii */
    
    108
    +      {
    
    109
    +        d = p / ii;
    
    110
    +        linear = 1;
    
    111
    +      }
    
    89 112
         }
    
    90
    -    for ( ; ii >= 0; ii-- )
    
    91
    -      gamma_ramp_inv[ii] = (unsigned char)( 255.*12.92321*ii/gmax + 0.5 );
    
    92 113
       }
    
    93 114
       else
    
    94 115
       {
    
    95
    -    int     ii;
    
    96
    -
    
    97 116
         /* voltage to linear; power function using finite differences */
    
    98 117
         for ( p = gmax, ii = 255; ii > 0; ii-- )
    
    99 118
         {
    


  • reply via email to

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