* src/base/ftbitmap.c (FT_Bitmap_Copy): Clarify the flow control.

* include/freetype/ftbitmap.h (FT_Bitmap_Copy): Ditto.
This commit is contained in:
Alexei Podtelezhnikov 2022-09-21 16:57:34 +00:00
parent 82c5ecfee1
commit 468eaf19d9
2 changed files with 16 additions and 19 deletions

View File

@ -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,

View File

@ -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;