From 468eaf19d9d0980694fe9857c866e28303ad4d97 Mon Sep 17 00:00:00 2001 From: Alexei Podtelezhnikov Date: Wed, 21 Sep 2022 16:57:34 +0000 Subject: * src/base/ftbitmap.c (FT_Bitmap_Copy): Clarify the flow control. * include/freetype/ftbitmap.h (FT_Bitmap_Copy): Ditto. --- include/freetype/ftbitmap.h | 18 ++++++++---------- src/base/ftbitmap.c | 17 ++++++++--------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/include/freetype/ftbitmap.h b/include/freetype/ftbitmap.h index 862b8a369..dd0e200b5 100644 --- a/include/freetype/ftbitmap.h +++ b/include/freetype/ftbitmap.h @@ -47,14 +47,6 @@ FT_BEGIN_HEADER * @description: * This section contains functions for handling @FT_Bitmap objects, * automatically adjusting the target's bitmap buffer size as needed. - * - * Note that none of the functions changes the bitmap's 'flow' (as - * indicated by the sign of the `pitch` field in @FT_Bitmap). - * - * To set the flow, assign an appropriate positive or negative value to - * the `pitch` field of the target @FT_Bitmap object after calling - * @FT_Bitmap_Init but before calling any of the other functions - * described here. */ @@ -105,8 +97,14 @@ FT_BEGIN_HEADER * FreeType error code. 0~means success. * * @note: - * `source->buffer` and `target->buffer` must neither be equal nor - * overlap. + * This function reallocates the memory in the target bitmap, which has + * to be valid, either initialized by @FT_Bitmap_Init or reused multiple + * times. `source->buffer` and `target->buffer` must neither be equal + * nor overlap. Use @FT_Bitmap_Done to finally remove the bitmap object. + * + * The source and target bitmaps can have different flows if their + * pitches are set to opposite signs before calling this function. + * Otherwise, the flow is preserved. */ FT_EXPORT( FT_Error ) FT_Bitmap_Copy( FT_Library library, diff --git a/src/base/ftbitmap.c b/src/base/ftbitmap.c index 53f02ae55..99afbd976 100644 --- a/src/base/ftbitmap.c +++ b/src/base/ftbitmap.c @@ -67,8 +67,7 @@ FT_Memory memory; FT_Error error = FT_Err_Ok; FT_Int pitch; - - FT_Int source_pitch_sign, target_pitch_sign; + FT_Int flip; if ( !library ) @@ -80,15 +79,15 @@ if ( source == target ) return FT_Err_Ok; - source_pitch_sign = source->pitch < 0 ? -1 : 1; - target_pitch_sign = target->pitch < 0 ? -1 : 1; + flip = ( source->pitch < 0 && target->pitch > 0 ) || + ( source->pitch > 0 && target->pitch < 0 ); memory = library->memory; FT_FREE( target->buffer ); *target = *source; - if ( source_pitch_sign != target_pitch_sign ) + if ( flip ) target->pitch = -target->pitch; if ( !source->buffer ) @@ -102,10 +101,7 @@ if ( !error ) { - if ( source_pitch_sign == target_pitch_sign ) - FT_MEM_COPY( target->buffer, source->buffer, - (FT_Long)source->rows * pitch ); - else + if ( flip ) { /* take care of bitmap flow */ FT_UInt i; @@ -123,6 +119,9 @@ t -= pitch; } } + else + FT_MEM_COPY( target->buffer, source->buffer, + (FT_Long)source->rows * pitch ); } return error; -- cgit v1.2.1