freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype][bitmap_convert] [base] Accept negative bitmap a


From: Alexei Podtelezhnikov (@apodtele)
Subject: [Git][freetype/freetype][bitmap_convert] [base] Accept negative bitmap alignment for bottom-up flow.
Date: Tue, 20 Sep 2022 14:17:54 +0000

Alexei Podtelezhnikov pushed to branch bitmap_convert at FreeType / FreeType

Commits:

  • bcb54783
    by Alexei Podtelezhnikov at 2022-09-20T14:17:50+00:00
    [base] Accept negative bitmap alignment for bottom-up flow.
    
    * src/base/ftbitmap.c (FT_Bitmap_Convert): Use negative alignment
    to produce negative pitch.
    * include/freetype/ftbitmap.c (FT_Bitmap_Convert): Document it.

2 changed files:

Changes:

  • include/freetype/ftbitmap.h
    ... ... @@ -178,8 +178,8 @@ FT_BEGIN_HEADER
    178 178
        *     The source bitmap.
    
    179 179
        *
    
    180 180
        *   alignment ::
    
    181
    -   *     The pitch of the bitmap is a multiple of this argument.  Common
    
    182
    -   *     values are 1, 2, or 4.
    
    181
    +   *     The pitch of the target bitmap is a multiple of this argument.
    
    182
    +   *     Common values are 1, 2, or 4.
    
    183 183
        *
    
    184 184
        * @output:
    
    185 185
        *   target ::
    
    ... ... @@ -189,16 +189,16 @@ FT_BEGIN_HEADER
    189 189
        *   FreeType error code.  0~means success.
    
    190 190
        *
    
    191 191
        * @note:
    
    192
    -   *   It is possible to call @FT_Bitmap_Convert multiple times without
    
    193
    -   *   calling @FT_Bitmap_Done (the memory is simply reallocated).
    
    192
    +   *   This function reallocates the memory in the target bitmap, which has
    
    193
    +   *   to be valid, either initialized by @FT_Bitmap_Init or reused multiple
    
    194
    +   *   times. `source->buffer` and `target->buffer` must neither be equal
    
    195
    +   *   nor overlap.  Use @FT_Bitmap_Done to finally remove the bitmap object.
    
    194 196
        *
    
    195
    -   *   Use @FT_Bitmap_Done to finally remove the bitmap object.
    
    197
    +   *   Negative alignment values produce bottom-up bitmaps with negative
    
    198
    +   *   pitch.  Zero alignment is treated as one, i.e., no padding is used.
    
    196 199
        *
    
    197 200
        *   The `library` argument is taken to have access to FreeType's memory
    
    198 201
        *   handling functions.
    
    199
    -   *
    
    200
    -   *   `source->buffer` and `target->buffer` must neither be equal nor
    
    201
    -   *   overlap.
    
    202 202
        */
    
    203 203
       FT_EXPORT( FT_Error )
    
    204 204
       FT_Bitmap_Convert( FT_Library        library,
    

  • src/base/ftbitmap.c
    ... ... @@ -542,7 +542,8 @@
    542 542
         case FT_PIXEL_MODE_LCD_V:
    
    543 543
         case FT_PIXEL_MODE_BGRA:
    
    544 544
           {
    
    545
    -        FT_Int  pad, target_pitch;
    
    545
    +        FT_Int  width = (FT_Int)source->width;
    
    546
    +        FT_Int  pad;
    
    546 547
     
    
    547 548
     
    
    548 549
             FT_Bitmap_Done( library, target );
    
    ... ... @@ -551,20 +552,18 @@
    551 552
             target->rows       = source->rows;
    
    552 553
             target->width      = source->width;
    
    553 554
     
    
    554
    -        pad = 0;
    
    555
    -        if ( alignment > 0 )
    
    556
    -        {
    
    557
    -          pad = (FT_Int)source->width % alignment;
    
    558
    -          if ( pad != 0 )
    
    559
    -            pad = alignment - pad;
    
    560
    -        }
    
    555
    +        if ( !alignment )
    
    556
    +          alignment = 1;
    
    561 557
     
    
    562
    -        target_pitch = (FT_Int)source->width + pad;
    
    558
    +        pad = width % alignment;
    
    559
    +        if ( pad )
    
    560
    +          width = alignment > 0 ? width + ( alignment - pad )
    
    561
    +                                : width - ( alignment + pad );
    
    563 562
     
    
    564
    -        if ( FT_QALLOC_MULT( target->buffer, target->rows, target_pitch ) )
    
    563
    +        if ( FT_QALLOC_MULT( target->buffer, target->rows, width ) )
    
    565 564
               return error;
    
    566 565
     
    
    567
    -        target->pitch = target->pitch < 0 ? -target_pitch : target_pitch;
    
    566
    +        target->pitch = alignment > 0 ? width : -width;
    
    568 567
           }
    
    569 568
           break;
    
    570 569
     
    


  • reply via email to

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