freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype][gsoc-anurag-2022] 3 commits: lkw


From: Anurag Thakur (@AdbhutDev)
Subject: [Git][freetype/freetype][gsoc-anurag-2022] 3 commits: lkw
Date: Sun, 09 Oct 2022 15:17:21 +0000

Anurag Thakur pushed to branch gsoc-anurag-2022 at FreeType / FreeType

Commits:

  • c03591c4
    by Anurag Thakur at 2022-10-06T01:55:06+05:30
    lkw
    
  • 9538d8e7
    by Anurag Thakur at 2022-10-06T03:06:00+05:30
    Fixed first pass
    
  • d2574056
    by Anurag Thakur at 2022-10-09T18:20:49+05:30
    Fixed point working now
    

2 changed files:

Changes:

  • src/dense/ftdense.c
    ... ... @@ -58,6 +58,19 @@ dense_line_to( const FT_Vector* to, dense_worker* worker )
    58 58
       dense_move_to( to, worker );
    
    59 59
       return 0;
    
    60 60
     }
    
    61
    +
    
    62
    +FT26D6 max(FT26D6 x, FT26D6 y){
    
    63
    +  if(x > y)
    
    64
    +    return x;
    
    65
    +  return y;
    
    66
    +}
    
    67
    +
    
    68
    +FT26D6 min(FT26D6 x, FT26D6 y){
    
    69
    +  if(x < y)
    
    70
    +    return x;
    
    71
    +  return y;
    
    72
    +}
    
    73
    +
    
    61 74
     void
    
    62 75
     swap( long int* a, long int* b )
    
    63 76
     {
    
    ... ... @@ -72,33 +85,39 @@ dense_render_line( dense_worker* worker, TPos tox, TPos toy )
    72 85
     {
    
    73 86
       // printf("line from: %d, %d to %d, %d\n", worker->prev_x, worker->prev_y,
    
    74 87
       // to_x, to_y);
    
    75
    -  float from_x = worker->prev_x;
    
    76
    -  float from_y = worker->prev_y;
    
    77
    -  if ( from_y == toy )
    
    78
    -    return;
    
    79 88
     
    
    80
    -  // aP0.m_x -= worker->m_origin_x;
    
    81
    -  // aP0.m_y -= worker->m_origin_y;
    
    82
    -  // aP1.m_x -= worker->m_origin_x;
    
    83
    -  // aP1.m_y -= worker->m_origin_y;
    
    84 89
     
    
    85
    -  // from_x = TRUNC( (int)from_x );
    
    86
    -  // from_y = TRUNC( (int)from_y );
    
    87
    -  // to_x   = TRUNC( (int)to_x );
    
    88
    -  // to_y   = TRUNC( (int)to_y );
    
    90
    +  FT26D6 fx = worker->prev_x>>2;
    
    91
    +  FT26D6 fy = worker->prev_y>>2;
    
    92
    +
    
    93
    +
    
    94
    +  // float from_x = fx;
    
    95
    +  // float from_y = fy;
    
    96
    +    
    
    97
    +  FT26D6 from_x = fx;
    
    98
    +  FT26D6 from_y = fy;
    
    99
    +
    
    100
    +
    
    101
    +  // from_x /= 64.0;
    
    102
    +  // from_y /= 64.0;
    
    103
    +
    
    104
    +  FT26D6 tx = tox>>2;
    
    105
    +  FT26D6 ty = toy>>2;
    
    106
    +
    
    107
    +  if ( fy == ty )
    
    108
    +    return;
    
    109
    +
    
    110
    +  //  float to_x = tx / 64.0;
    
    111
    +  //  float to_y = ty / 64.0;
    
    112
    +  FT26D6 to_x = tx;
    
    113
    +  FT26D6 to_y = ty;
    
    89 114
     
    
    90
    -  from_x /= 256.0;
    
    91
    -  from_y /= 256.0;
    
    92
    -  float to_x = tox / 256.0;
    
    93
    -  float to_y = toy / 256.0;
    
    94 115
     
    
    95 116
     
    
    96 117
       //printf("line from: %f, %f to %f, %f\n", from_x, from_y, to_x, to_y);
    
    97 118
     
    
    98
    -  float dir;
    
    99
    -  if ( from_y < to_y )
    
    100
    -    dir = 1;
    
    101
    -  else
    
    119
    +  int dir = 1;
    
    120
    +  if ( from_y >= to_y )
    
    102 121
       {
    
    103 122
         dir = -1;
    
    104 123
         swap( &from_x, &to_x );
    
    ... ... @@ -106,35 +125,41 @@ dense_render_line( dense_worker* worker, TPos tox, TPos toy )
    106 125
       }
    
    107 126
     
    
    108 127
       // Clip to the height.
    
    109
    -  if ( from_y >= worker->m_h || to_y <= 0 )
    
    128
    +  if ( from_y >= worker->m_h<<6 || to_y <= 0 )
    
    110 129
         return;
    
    111 130
     
    
    112
    -  float dxdy = ( to_x - from_x ) / (float)( to_y - from_y );
    
    131
    +  //float dxdy = ( to_x - from_x ) / (float)( to_y - from_y );
    
    132
    +  FT26D6 deltax,deltay;
    
    133
    +  deltax = to_x - from_x;
    
    134
    +  deltay = to_y - from_y;
    
    135
    +
    
    113 136
       if ( from_y < 0 )
    
    114 137
       {
    
    115
    -    from_x -= from_y * dxdy;
    
    138
    +    from_x -= from_y * deltax/deltay;
    
    116 139
         from_y = 0;
    
    117 140
       }
    
    118
    -  if ( to_y > worker->m_h )
    
    141
    +
    
    142
    +  // TODO: test, imp line
    
    143
    +  if ( to_y > worker->m_h<<6 )
    
    119 144
       {
    
    120
    -    to_x -= ( to_y - worker->m_h ) * dxdy;
    
    121
    -    to_y = (float)worker->m_h;
    
    145
    +    to_x -= (( to_y - worker->m_h<<6 ) * deltax/deltay);
    
    146
    +    to_y = worker->m_h<<6;
    
    122 147
       }
    
    123 148
     
    
    124
    -  float  x       = from_x;
    
    125
    -  int    y0      = (int)from_y;
    
    126
    -  int    y_limit = (int)ceil( to_y );
    
    127
    -  float* m_a     = worker->m_a;
    
    149
    +  int  x       = from_x;
    
    150
    +  int    y0      = from_y>>6;
    
    151
    +  int    y_limit = (to_y + 0x3f)>>6;
    
    152
    +  FT20D12* m_a     = worker->m_a;
    
    128 153
     
    
    129 154
       for ( int y = y0; y < y_limit; y++ )
    
    130 155
       {
    
    131 156
        // printf("y is %d\n", y);
    
    132 157
         int   linestart = y * worker->m_w;
    
    133
    -    float dy        = fmin( y + 1.0f, to_y ) - fmax( (float)y, from_y );
    
    134
    -    float xnext     = x + dxdy * dy;
    
    135
    -    float d         = dy * dir;
    
    158
    +    FT26D6 dy        = min( (y + 1)<<6, to_y ) - max( y<<6, from_y );
    
    159
    +    FT26D6 xnext     = x + dy * deltax/deltay;
    
    160
    +    FT26D6 d         = dy * dir;
    
    136 161
     
    
    137
    -    float x0, x1;
    
    162
    +    FT26D6 x0, x1;
    
    138 163
         if ( x < xnext )
    
    139 164
         {
    
    140 165
           x0 = x;
    
    ... ... @@ -151,35 +176,59 @@ dense_render_line( dense_worker* worker, TPos tox, TPos toy )
    151 176
         floating-point inaccuracy That would cause an out-of-bounds array access at
    
    152 177
         index -1.
    
    153 178
         */
    
    154
    -    float x0floor = x0 <= 0.0f ? 0.0f : (float)floor( x0 );
    
    179
    +    // float x0floor = x0 <= 0.0f ? 0.0f : (float)floor( x0 );
    
    180
    +
    
    181
    +    int   x0i    = x0>>6;
    
    182
    +    FT26D6 x0floor = x0i<<6;
    
    183
    +
    
    184
    +
    
    185
    +    // float x1ceil = (float)ceil( x1 );
    
    186
    +    int   x1i    = (x1+0x3f)>>6;
    
    187
    +    FT26D6 x1ceil =  x1i <<6;
    
    155 188
     
    
    156
    -    int   x0i    = (int)x0floor;
    
    157
    -    float x1ceil = (float)ceil( x1 );
    
    158
    -    int   x1i    = (int)x1ceil;
    
    159 189
         if ( x1i <= x0i + 1 )
    
    160 190
         {
    
    161
    -      float xmf = 0.5f * ( x + xnext ) - x0floor;
    
    162
    -      m_a[linestart + x0i] += d - d * xmf;
    
    191
    +      FT26D6 xmf = ( ( x + xnext )>>1) - x0floor;
    
    192
    +      m_a[linestart + x0i] += d * ((1<<6) - xmf);
    
    163 193
           m_a[linestart + ( x0i + 1 )] += d * xmf;
    
    164 194
         }
    
    165 195
         else
    
    166 196
         {
    
    167
    -      float s   = 1.0f / ( x1 - x0 );
    
    168
    -      float x0f = x0 - x0floor;
    
    169
    -      float a0  = 0.5f * s * ( 1.0f - x0f ) * ( 1.0f - x0f );
    
    170
    -      float x1f = x1 - x1ceil + 1.0f;
    
    171
    -      float am  = 0.5f * s * x1f * x1f;
    
    197
    +      // float s   = 1.0f / ( x1 - x0 );
    
    198
    +      // float x0f = x0 - x0floor;
    
    199
    +      // float a0  = 0.5f * s * ( 1.0f - x0f ) * ( 1.0f - x0f );
    
    200
    +      // float x1f = x1 - x1ceil + 1.0f;
    
    201
    +      // float am  = 0.5f * s * x1f * x1f;
    
    202
    +
    
    203
    +      FT26D6 oneOverS = x1 - x0;
    
    204
    +      FT26D6 x0f = x0 - x0floor;
    
    205
    +
    
    206
    +
    
    207
    +      FT26D6 oneMinusX0f = (1<<6) - x0f;
    
    208
    +			FT26D6 a0 = ((oneMinusX0f * oneMinusX0f) >> 1) / oneOverS;
    
    209
    +			FT26D6 x1f = x1 - x1ceil + (1<<6);
    
    210
    +			FT26D6 am = ((x1f * x1f) >> 1) / oneOverS;
    
    211
    +
    
    212
    +       // printf("x0 is %lld, x1 is %lld\n",x0,x1 );
    
    213
    +
    
    214
    +
    
    215
    +
    
    172 216
           m_a[linestart + x0i] += d * a0;
    
    217
    +
    
    173 218
           if ( x1i == x0i + 2 )
    
    174
    -        m_a[linestart + ( x0i + 1 )] += d * ( 1.0f - a0 - am );
    
    219
    +        m_a[linestart + ( x0i + 1 )] += d * ( (1<<6) - a0 - am );
    
    175 220
           else
    
    176 221
           {
    
    177
    -        float a1 = s * ( 1.5f - x0f );
    
    222
    +        FT26D6 a1 = (((1<<6) + (1<<5) - x0f) << 6) / oneOverS;
    
    178 223
             m_a[linestart + ( x0i + 1 )] += d * ( a1 - a0 );
    
    179
    -        for ( int xi = x0i + 2; xi < x1i - 1; xi++ )
    
    180
    -          m_a[linestart + xi] += d * s;
    
    181
    -        float a2 = a1 + ( x1i - x0i - 3 ) * s;
    
    182
    -        m_a[linestart + ( x1i - 1 )] += d * ( 1.0f - a2 - am );
    
    224
    +
    
    225
    +        FT26D6 dTimesS = (d << 12) / oneOverS;
    
    226
    +        
    
    227
    +        for ( FT26D6 xi = x0i + 2; xi < x1i - 1; xi++ )
    
    228
    +          m_a[linestart + xi] += dTimesS;
    
    229
    +
    
    230
    +        FT26D6 a2 = a1 + (( x1i - x0i - 3 )<<12)/oneOverS;
    
    231
    +        m_a[linestart + ( x1i - 1 )] += d * ( (1<<6) - a2 - am );
    
    183 232
           }
    
    184 233
           m_a[linestart + x1i] += d * am;
    
    185 234
         }
    
    ... ... @@ -369,26 +418,45 @@ dense_render_glyph( dense_worker* worker, const FT_Bitmap* target )
    369 418
       FT_Error error = FT_Outline_Decompose( &( worker->outline ),
    
    370 419
                                              &dense_decompose_funcs, worker );
    
    371 420
       // Render into bitmap
    
    372
    -  const float* source = worker->m_a;
    
    421
    +  const FT20D12* source = worker->m_a;
    
    373 422
     
    
    374 423
       unsigned char* dest     = target->buffer;
    
    375 424
       unsigned char* dest_end = target->buffer + worker->m_w * worker->m_h;
    
    376 425
     
    
    377
    -  __m128 offset = _mm_setzero_ps();
    
    378
    -  __m128i mask = _mm_set1_epi32(0x0c080400);
    
    379
    -  __m128 sign_mask = _mm_set1_ps(-0.f);
    
    380
    -  for (int i = 0; i < worker->m_h*worker->m_w; i += 4) {
    
    381
    -    __m128 x = _mm_load_ps(&source[i]);
    
    382
    -    x = _mm_add_ps(x, _mm_castsi128_ps(_mm_slli_si128(_mm_castps_si128(x), 4)));
    
    383
    -    x = _mm_add_ps(x, _mm_shuffle_ps(_mm_setzero_ps(), x, 0x40));
    
    384
    -    x = _mm_add_ps(x, offset);
    
    385
    -    __m128 y = _mm_andnot_ps(sign_mask, x);  // fabs(x)
    
    386
    -    y = _mm_min_ps(y, _mm_set1_ps(1.0f));
    
    387
    -    y = _mm_mul_ps(y, _mm_set1_ps(255.0f));
    
    388
    -    __m128i z = _mm_cvtps_epi32(y);
    
    389
    -    z = _mm_shuffle_epi8(z, mask);
    
    390
    -    _mm_store_ss((float *)&dest[i], (__m128)z);
    
    391
    -    offset = _mm_shuffle_ps(x, x, _MM_SHUFFLE(3, 3, 3, 3));
    
    426
    +  // __m128 offset = _mm_setzero_ps();
    
    427
    +  // __m128i mask = _mm_set1_epi32(0x0c080400);
    
    428
    +  // __m128 sign_mask = _mm_set1_ps(-0.f);
    
    429
    +  // for (int i = 0; i < worker->m_h*worker->m_w; i += 4) {
    
    430
    +  //   __m128 x = _mm_load_ps(&source[i]);
    
    431
    +  //   x = _mm_add_ps(x, _mm_castsi128_ps(_mm_slli_si128(_mm_castps_si128(x), 4)));
    
    432
    +  //   x = _mm_add_ps(x, _mm_shuffle_ps(_mm_setzero_ps(), x, 0x40));
    
    433
    +  //   x = _mm_add_ps(x, offset);
    
    434
    +  //   __m128 y = _mm_andnot_ps(sign_mask, x);  // fabs(x)
    
    435
    +  //   y = _mm_min_ps(y, _mm_set1_ps(1.0f));
    
    436
    +  //   y = _mm_mul_ps(y, _mm_set1_ps(255.0f));
    
    437
    +  //   __m128i z = _mm_cvtps_epi32(y);
    
    438
    +  //   z = _mm_shuffle_epi8(z, mask);
    
    439
    +  //   _mm_store_ss((float *)&dest[i], (__m128)z);
    
    440
    +  //   offset = _mm_shuffle_ps(x, x, _MM_SHUFFLE(3, 3, 3, 3));
    
    441
    +  // }
    
    442
    +
    
    443
    +  FT20D12 valnew = 0;
    
    444
    +  //float          value    = 0.0f;
    
    445
    +  while ( dest < dest_end )
    
    446
    +  {
    
    447
    +    valnew += *source++;
    
    448
    +
    
    449
    +   // printf("%d\n", *source);
    
    450
    +
    
    451
    +    if(valnew > 0){
    
    452
    +      int nnew = valnew >>4;
    
    453
    +
    
    454
    +      if(nnew>255)nnew=255;
    
    455
    +      *dest = (unsigned char)nnew;
    
    456
    +    }else{
    
    457
    +      *dest = 0;
    
    458
    +    }
    
    459
    +    dest++;
    
    392 460
       }
    
    393 461
     
    
    394 462
       // float          value    = 0.0f;
    
    ... ... @@ -445,10 +513,10 @@ dense_raster_render( FT_Raster raster, const FT_Raster_Params* params )
    445 513
     
    
    446 514
       int size = worker->m_w * worker->m_h + 4;
    
    447 515
     
    
    448
    -  worker->m_a      = malloc( sizeof( float ) * size );
    
    516
    +  worker->m_a      = malloc( sizeof( FT20D12 ) * size );
    
    449 517
       worker->m_a_size = size;
    
    450 518
     
    
    451
    -  memset( worker->m_a, 0, ( sizeof( float ) * size ) );
    
    519
    +  memset( worker->m_a, 0, ( sizeof( FT20D12 ) * size ) );
    
    452 520
       /* exit if nothing to do */
    
    453 521
       if ( worker->m_w <= worker->m_origin_x || worker->m_h <= worker->m_origin_y )
    
    454 522
       {
    

  • src/dense/ftdense.h
    ... ... @@ -40,12 +40,14 @@ extern "C"
    40 40
     {
    
    41 41
     #endif
    
    42 42
     
    
    43
    -  typedef long TPos;
    
    43
    +  typedef signed long TPos;
    
    44
    +  typedef signed long long FT26D6;
    
    45
    +  typedef signed long long FT20D12;
    
    44 46
     
    
    45 47
       typedef struct
    
    46 48
       {
    
    47 49
         /** The array used to store signed area differences. */
    
    48
    -    float* m_a;
    
    50
    +    FT20D12* m_a;
    
    49 51
         /** The number of elements in m_a. */
    
    50 52
         int m_a_size;
    
    51 53
         /** The width of the current raster in pixels. */
    


  • reply via email to

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