[base] Accept negative bitmap alignment for bottom-up flow.

* src/base/ftbitmap.c (FT_Bitmap_Convert): Use negative alignment
to produce negative pitch.
* include/freetype/ftbitmap.c (FT_Bitmap_Convert): Document it.
This commit is contained in:
Alexei Podtelezhnikov 2022-09-20 14:16:29 -04:00
parent 4dba6795b6
commit baae1a2775
2 changed files with 18 additions and 18 deletions

View File

@ -178,8 +178,8 @@ FT_BEGIN_HEADER
* The source bitmap. * The source bitmap.
* *
* alignment :: * alignment ::
* The pitch of the bitmap is a multiple of this argument. Common * The pitch of the target bitmap is a multiple of this argument.
* values are 1, 2, or 4. * Common values are 1, 2, or 4.
* *
* @output: * @output:
* target :: * target ::
@ -189,16 +189,16 @@ FT_BEGIN_HEADER
* FreeType error code. 0~means success. * FreeType error code. 0~means success.
* *
* @note: * @note:
* It is possible to call @FT_Bitmap_Convert multiple times without * This function reallocates the memory in the target bitmap, which has
* calling @FT_Bitmap_Done (the memory is simply reallocated). * 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.
* *
* Use @FT_Bitmap_Done to finally remove the bitmap object. * Negative alignment values produce bottom-up bitmaps with negative
* pitch. Zero alignment is treated as one, i.e., no padding is used.
* *
* The `library` argument is taken to have access to FreeType's memory * The `library` argument is taken to have access to FreeType's memory
* handling functions. * handling functions.
*
* `source->buffer` and `target->buffer` must neither be equal nor
* overlap.
*/ */
FT_EXPORT( FT_Error ) FT_EXPORT( FT_Error )
FT_Bitmap_Convert( FT_Library library, FT_Bitmap_Convert( FT_Library library,

View File

@ -542,7 +542,7 @@
case FT_PIXEL_MODE_LCD_V: case FT_PIXEL_MODE_LCD_V:
case FT_PIXEL_MODE_BGRA: case FT_PIXEL_MODE_BGRA:
{ {
FT_Int pad, target_pitch; FT_Int width = (FT_Int)source->width;
FT_Bitmap_Done( library, target ); FT_Bitmap_Done( library, target );
@ -551,20 +551,20 @@
target->rows = source->rows; target->rows = source->rows;
target->width = source->width; target->width = source->width;
pad = 0; if ( alignment )
if ( alignment > 0 )
{ {
pad = (FT_Int)source->width % alignment; FT_Int rem = width % alignment;
if ( pad != 0 )
pad = alignment - pad;
if ( rem )
width = alignment < 0 ? width - rem - alignment
: width - rem + alignment;
} }
target_pitch = (FT_Int)source->width + pad; if ( FT_QALLOC_MULT( target->buffer, target->rows, width ) )
if ( FT_QALLOC_MULT( target->buffer, target->rows, target_pitch ) )
return error; return error;
target->pitch = target->pitch < 0 ? -target_pitch : target_pitch; target->pitch = alignment < 0 ? -width : width;
} }
break; break;