freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype][master] [base] Discard and recreate bitmaps for


From: Alexei Podtelezhnikov (@apodtele)
Subject: [Git][freetype/freetype][master] [base] Discard and recreate bitmaps for copying and converting.
Date: Thu, 22 Sep 2022 15:09:21 +0000

Alexei Podtelezhnikov pushed to branch master at FreeType / FreeType

Commits:

  • c456eeb4
    by Alexei Podtelezhnikov at 2022-09-22T15:09:17+00:00
    [base] Discard and recreate bitmaps for copying and converting.
    
    Reusing target bitmaps for copying and converting is permitted.  It is,
    however, pointless to preserve their content before overwriting.  Free-
    malloc might be faster than realloc.
    
    * src/base/ftbitmap.c (FT_Bitmap_Copy, FT_Bitmap_Convert): Free
    an old buffer and create a new one.

1 changed file:

Changes:

  • src/base/ftbitmap.c
    ... ... @@ -66,9 +66,7 @@
    66 66
       {
    
    67 67
         FT_Memory  memory;
    
    68 68
         FT_Error   error  = FT_Err_Ok;
    
    69
    -
    
    70
    -    FT_Int    pitch;
    
    71
    -    FT_ULong  size;
    
    69
    +    FT_Int     pitch;
    
    72 70
     
    
    73 71
         FT_Int  source_pitch_sign, target_pitch_sign;
    
    74 72
     
    
    ... ... @@ -85,49 +83,28 @@
    85 83
         source_pitch_sign = source->pitch < 0 ? -1 : 1;
    
    86 84
         target_pitch_sign = target->pitch < 0 ? -1 : 1;
    
    87 85
     
    
    88
    -    if ( !source->buffer )
    
    89
    -    {
    
    90
    -      *target = *source;
    
    91
    -      if ( source_pitch_sign != target_pitch_sign )
    
    92
    -        target->pitch = -target->pitch;
    
    86
    +    memory = library->memory;
    
    87
    +    FT_FREE( target->buffer );
    
    88
    +
    
    89
    +    *target = *source;
    
    90
    +
    
    91
    +    if ( source_pitch_sign != target_pitch_sign )
    
    92
    +      target->pitch = -target->pitch;
    
    93 93
     
    
    94
    +    if ( !source->buffer )
    
    94 95
           return FT_Err_Ok;
    
    95
    -    }
    
    96 96
     
    
    97
    -    memory = library->memory;
    
    98 97
         pitch  = source->pitch;
    
    99
    -
    
    100 98
         if ( pitch < 0 )
    
    101 99
           pitch = -pitch;
    
    102
    -    size = (FT_ULong)pitch * source->rows;
    
    103 100
     
    
    104
    -    if ( target->buffer )
    
    105
    -    {
    
    106
    -      FT_Int    target_pitch = target->pitch;
    
    107
    -      FT_ULong  target_size;
    
    108
    -
    
    109
    -
    
    110
    -      if ( target_pitch < 0 )
    
    111
    -        target_pitch = -target_pitch;
    
    112
    -      target_size = (FT_ULong)target_pitch * target->rows;
    
    113
    -
    
    114
    -      if ( target_size != size )
    
    115
    -        FT_MEM_QREALLOC( target->buffer, target_size, size );
    
    116
    -    }
    
    117
    -    else
    
    118
    -      FT_MEM_QALLOC( target->buffer, size );
    
    101
    +    FT_MEM_QALLOC_MULT( target->buffer, target->rows, pitch );
    
    119 102
     
    
    120 103
         if ( !error )
    
    121 104
         {
    
    122
    -      unsigned char *p;
    
    123
    -
    
    124
    -
    
    125
    -      p = target->buffer;
    
    126
    -      *target = *source;
    
    127
    -      target->buffer = p;
    
    128
    -
    
    129 105
           if ( source_pitch_sign == target_pitch_sign )
    
    130
    -        FT_MEM_COPY( target->buffer, source->buffer, size );
    
    106
    +        FT_MEM_COPY( target->buffer, source->buffer,
    
    107
    +                     (FT_Long)source->rows * pitch );
    
    131 108
           else
    
    132 109
           {
    
    133 110
             /* take care of bitmap flow */
    
    ... ... @@ -542,15 +519,11 @@
    542 519
         case FT_PIXEL_MODE_LCD_V:
    
    543 520
         case FT_PIXEL_MODE_BGRA:
    
    544 521
           {
    
    545
    -        FT_Int    pad, old_target_pitch, target_pitch;
    
    546
    -        FT_ULong  old_size;
    
    522
    +        FT_Int  pad, target_pitch; 
    
    523
    +        FT_Int  old_target_pitch = target->pitch;
    
    547 524
     
    
    548 525
     
    
    549
    -        old_target_pitch = target->pitch;
    
    550
    -        if ( old_target_pitch < 0 )
    
    551
    -          old_target_pitch = -old_target_pitch;
    
    552
    -
    
    553
    -        old_size = target->rows * (FT_UInt)old_target_pitch;
    
    526
    +        FT_Bitmap_Done( library, target );
    
    554 527
     
    
    555 528
             target->pixel_mode = FT_PIXEL_MODE_GRAY;
    
    556 529
             target->rows       = source->rows;
    
    ... ... @@ -566,15 +539,10 @@
    566 539
     
    
    567 540
             target_pitch = (FT_Int)source->width + pad;
    
    568 541
     
    
    569
    -        if ( target_pitch > 0                                               &&
    
    570
    -             (FT_ULong)target->rows > FT_ULONG_MAX / (FT_ULong)target_pitch )
    
    571
    -          return FT_THROW( Invalid_Argument );
    
    572
    -
    
    573
    -        if ( FT_QREALLOC( target->buffer,
    
    574
    -                          old_size, target->rows * (FT_UInt)target_pitch ) )
    
    542
    +        if ( FT_QALLOC_MULT( target->buffer, target->rows, target_pitch ) )
    
    575 543
               return error;
    
    576 544
     
    
    577
    -        target->pitch = target->pitch < 0 ? -target_pitch : target_pitch;
    
    545
    +        target->pitch = old_target_pitch < 0 ? -target_pitch : target_pitch;
    
    578 546
           }
    
    579 547
           break;
    
    580 548
     
    


  • reply via email to

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