mirror of https://github.com/freetype/freetype
* src/base/ftbitmap.c (FT_Bitmap_Copy): Clarify the flow control.
* include/freetype/ftbitmap.h (FT_Bitmap_Copy): Ditto.
This commit is contained in:
parent
82c5ecfee1
commit
468eaf19d9
|
@ -47,14 +47,6 @@ FT_BEGIN_HEADER
|
||||||
* @description:
|
* @description:
|
||||||
* This section contains functions for handling @FT_Bitmap objects,
|
* This section contains functions for handling @FT_Bitmap objects,
|
||||||
* automatically adjusting the target's bitmap buffer size as needed.
|
* 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.
|
* FreeType error code. 0~means success.
|
||||||
*
|
*
|
||||||
* @note:
|
* @note:
|
||||||
* `source->buffer` and `target->buffer` must neither be equal nor
|
* This function reallocates the memory in the target bitmap, which has
|
||||||
* overlap.
|
* 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_EXPORT( FT_Error )
|
||||||
FT_Bitmap_Copy( FT_Library library,
|
FT_Bitmap_Copy( FT_Library library,
|
||||||
|
|
|
@ -67,8 +67,7 @@
|
||||||
FT_Memory memory;
|
FT_Memory memory;
|
||||||
FT_Error error = FT_Err_Ok;
|
FT_Error error = FT_Err_Ok;
|
||||||
FT_Int pitch;
|
FT_Int pitch;
|
||||||
|
FT_Int flip;
|
||||||
FT_Int source_pitch_sign, target_pitch_sign;
|
|
||||||
|
|
||||||
|
|
||||||
if ( !library )
|
if ( !library )
|
||||||
|
@ -80,15 +79,15 @@
|
||||||
if ( source == target )
|
if ( source == target )
|
||||||
return FT_Err_Ok;
|
return FT_Err_Ok;
|
||||||
|
|
||||||
source_pitch_sign = source->pitch < 0 ? -1 : 1;
|
flip = ( source->pitch < 0 && target->pitch > 0 ) ||
|
||||||
target_pitch_sign = target->pitch < 0 ? -1 : 1;
|
( source->pitch > 0 && target->pitch < 0 );
|
||||||
|
|
||||||
memory = library->memory;
|
memory = library->memory;
|
||||||
FT_FREE( target->buffer );
|
FT_FREE( target->buffer );
|
||||||
|
|
||||||
*target = *source;
|
*target = *source;
|
||||||
|
|
||||||
if ( source_pitch_sign != target_pitch_sign )
|
if ( flip )
|
||||||
target->pitch = -target->pitch;
|
target->pitch = -target->pitch;
|
||||||
|
|
||||||
if ( !source->buffer )
|
if ( !source->buffer )
|
||||||
|
@ -102,10 +101,7 @@
|
||||||
|
|
||||||
if ( !error )
|
if ( !error )
|
||||||
{
|
{
|
||||||
if ( source_pitch_sign == target_pitch_sign )
|
if ( flip )
|
||||||
FT_MEM_COPY( target->buffer, source->buffer,
|
|
||||||
(FT_Long)source->rows * pitch );
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
/* take care of bitmap flow */
|
/* take care of bitmap flow */
|
||||||
FT_UInt i;
|
FT_UInt i;
|
||||||
|
@ -123,6 +119,9 @@
|
||||||
t -= pitch;
|
t -= pitch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
FT_MEM_COPY( target->buffer, source->buffer,
|
||||||
|
(FT_Long)source->rows * pitch );
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
|
|
Loading…
Reference in New Issue