freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype][master] [base] Clean up the bitmap flow control


From: Alexei Podtelezhnikov (@apodtele)
Subject: [Git][freetype/freetype][master] [base] Clean up the bitmap flow control.
Date: Fri, 23 Sep 2022 00:51:34 +0000

Alexei Podtelezhnikov pushed to branch master at FreeType / FreeType

Commits:

  • c9c32631
    by Alexei Podtelezhnikov at 2022-09-22T20:40:21-04:00
    [base] Clean up the bitmap flow control.
    
    * src/base/ftbitmap.c (FT_Bitmap_Copy): Flip the copy if its pitch
    is trully opposite, zero is not a positive value.
    (FT_Bitmap_Convert): Set negative pitch as needed, accept negative
    alignment values.
    

1 changed file:

Changes:

  • src/base/ftbitmap.c
    ... ... @@ -67,8 +67,7 @@
    67 67
         FT_Memory  memory;
    
    68 68
         FT_Error   error  = FT_Err_Ok;
    
    69 69
         FT_Int     pitch;
    
    70
    -
    
    71
    -    FT_Int  source_pitch_sign, target_pitch_sign;
    
    70
    +    FT_Int     flip;
    
    72 71
     
    
    73 72
     
    
    74 73
         if ( !library )
    
    ... ... @@ -80,15 +79,15 @@
    80 79
         if ( source == target )
    
    81 80
           return FT_Err_Ok;
    
    82 81
     
    
    83
    -    source_pitch_sign = source->pitch < 0 ? -1 : 1;
    
    84
    -    target_pitch_sign = target->pitch < 0 ? -1 : 1;
    
    82
    +    flip = ( source->pitch < 0 && target->pitch > 0 ) ||
    
    83
    +           ( source->pitch > 0 && target->pitch < 0 );
    
    85 84
     
    
    86 85
         memory = library->memory;
    
    87 86
         FT_FREE( target->buffer );
    
    88 87
     
    
    89 88
         *target = *source;
    
    90 89
     
    
    91
    -    if ( source_pitch_sign != target_pitch_sign )
    
    90
    +    if ( flip )
    
    92 91
           target->pitch = -target->pitch;
    
    93 92
     
    
    94 93
         if ( !source->buffer )
    
    ... ... @@ -102,10 +101,7 @@
    102 101
     
    
    103 102
         if ( !error )
    
    104 103
         {
    
    105
    -      if ( source_pitch_sign == target_pitch_sign )
    
    106
    -        FT_MEM_COPY( target->buffer, source->buffer,
    
    107
    -                     (FT_Long)source->rows * pitch );
    
    108
    -      else
    
    104
    +      if ( flip )
    
    109 105
           {
    
    110 106
             /* take care of bitmap flow */
    
    111 107
             FT_UInt   i;
    
    ... ... @@ -123,6 +119,9 @@
    123 119
               t -= pitch;
    
    124 120
             }
    
    125 121
           }
    
    122
    +      else
    
    123
    +        FT_MEM_COPY( target->buffer, source->buffer,
    
    124
    +                     (FT_Long)source->rows * pitch );
    
    126 125
         }
    
    127 126
     
    
    128 127
         return error;
    
    ... ... @@ -519,8 +518,9 @@
    519 518
         case FT_PIXEL_MODE_LCD_V:
    
    520 519
         case FT_PIXEL_MODE_BGRA:
    
    521 520
           {
    
    522
    -        FT_Int  pad, target_pitch; 
    
    523
    -        FT_Int  old_target_pitch = target->pitch;
    
    521
    +        FT_Int  width = (FT_Int)source->width;
    
    522
    +        FT_Int  neg = ( target->pitch == 0 && source->pitch < 0 ) ||
    
    523
    +                        target->pitch  < 0;
    
    524 524
     
    
    525 525
     
    
    526 526
             FT_Bitmap_Done( library, target );
    
    ... ... @@ -529,20 +529,20 @@
    529 529
             target->rows       = source->rows;
    
    530 530
             target->width      = source->width;
    
    531 531
     
    
    532
    -        pad = 0;
    
    533
    -        if ( alignment > 0 )
    
    532
    +        if ( alignment )
    
    534 533
             {
    
    535
    -          pad = (FT_Int)source->width % alignment;
    
    536
    -          if ( pad != 0 )
    
    537
    -            pad = alignment - pad;
    
    538
    -        }
    
    534
    +          FT_Int  rem = width % alignment;
    
    539 535
     
    
    540
    -        target_pitch = (FT_Int)source->width + pad;
    
    541 536
     
    
    542
    -        if ( FT_QALLOC_MULT( target->buffer, target->rows, target_pitch ) )
    
    537
    +          if ( rem )
    
    538
    +            width = alignment > 0 ? width - rem + alignment
    
    539
    +                                  : width - rem - alignment;
    
    540
    +        }
    
    541
    +
    
    542
    +        if ( FT_QALLOC_MULT( target->buffer, target->rows, width ) )
    
    543 543
               return error;
    
    544 544
     
    
    545
    -        target->pitch = old_target_pitch < 0 ? -target_pitch : target_pitch;
    
    545
    +        target->pitch = neg ? -width : width;
    
    546 546
           }
    
    547 547
           break;
    
    548 548
     
    


  • reply via email to

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