diff options
author | Alexei Podtelezhnikov <apodtele@gmail.com> | 2022-09-21 14:44:23 +0000 |
---|---|---|
committer | Alexei Podtelezhnikov <apodtele@gmail.com> | 2022-09-21 14:44:23 +0000 |
commit | 82c5ecfee1035143c28f82fa6d582179c7449667 (patch) | |
tree | 28e62608c71b8e67359e664f10d1dfaba4b956a3 | |
parent | baae1a27757c7269dfac07f5098eb9ae1f5d8194 (diff) | |
download | freetype2-82c5ecfee1035143c28f82fa6d582179c7449667.tar.gz |
* src/base/ftbitmap.c (FT_Bitmap_Copy): Recreate target.
There is no need to preserve bits before overwriting them.
Therefore, free-malloc could be faster than realloc.
-rw-r--r-- | src/base/ftbitmap.c | 47 |
1 files changed, 12 insertions, 35 deletions
diff --git a/src/base/ftbitmap.c b/src/base/ftbitmap.c index 6d2b86fbc..53f02ae55 100644 --- a/src/base/ftbitmap.c +++ b/src/base/ftbitmap.c @@ -66,9 +66,7 @@ { FT_Memory memory; FT_Error error = FT_Err_Ok; - - FT_Int pitch; - FT_ULong size; + FT_Int pitch; FT_Int source_pitch_sign, target_pitch_sign; @@ -85,49 +83,28 @@ source_pitch_sign = source->pitch < 0 ? -1 : 1; target_pitch_sign = target->pitch < 0 ? -1 : 1; - if ( !source->buffer ) - { - *target = *source; - if ( source_pitch_sign != target_pitch_sign ) - target->pitch = -target->pitch; + memory = library->memory; + FT_FREE( target->buffer ); + + *target = *source; + if ( source_pitch_sign != target_pitch_sign ) + target->pitch = -target->pitch; + + if ( !source->buffer ) return FT_Err_Ok; - } - memory = library->memory; pitch = source->pitch; - if ( pitch < 0 ) pitch = -pitch; - size = (FT_ULong)pitch * source->rows; - if ( target->buffer ) - { - FT_Int target_pitch = target->pitch; - FT_ULong target_size; - - - if ( target_pitch < 0 ) - target_pitch = -target_pitch; - target_size = (FT_ULong)target_pitch * target->rows; - - if ( target_size != size ) - FT_MEM_QREALLOC( target->buffer, target_size, size ); - } - else - FT_MEM_QALLOC( target->buffer, size ); + FT_MEM_QALLOC_MULT( target->buffer, target->rows, pitch ); if ( !error ) { - unsigned char *p; - - - p = target->buffer; - *target = *source; - target->buffer = p; - if ( source_pitch_sign == target_pitch_sign ) - FT_MEM_COPY( target->buffer, source->buffer, size ); + FT_MEM_COPY( target->buffer, source->buffer, + (FT_Long)source->rows * pitch ); else { /* take care of bitmap flow */ |