summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexei Podtelezhnikov <apodtele@gmail.com>2022-09-20 14:16:29 -0400
committerAlexei Podtelezhnikov <apodtele@gmail.com>2022-09-20 14:16:29 -0400
commitbaae1a27757c7269dfac07f5098eb9ae1f5d8194 (patch)
tree3884af0820e6715587bef77629ce6ba3bb0b3212
parent4dba6795b6eebd2a139b557f1dc7094b10873338 (diff)
downloadfreetype2-baae1a27757c7269dfac07f5098eb9ae1f5d8194.tar.gz
[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.
-rw-r--r--include/freetype/ftbitmap.h16
-rw-r--r--src/base/ftbitmap.c20
2 files changed, 18 insertions, 18 deletions
diff --git a/include/freetype/ftbitmap.h b/include/freetype/ftbitmap.h
index c3462dadc..862b8a369 100644
--- a/include/freetype/ftbitmap.h
+++ b/include/freetype/ftbitmap.h
@@ -178,8 +178,8 @@ FT_BEGIN_HEADER
* The source bitmap.
*
* alignment ::
- * The pitch of the bitmap is a multiple of this argument. Common
- * values are 1, 2, or 4.
+ * The pitch of the target bitmap is a multiple of this argument.
+ * Common values are 1, 2, or 4.
*
* @output:
* target ::
@@ -189,16 +189,16 @@ FT_BEGIN_HEADER
* FreeType error code. 0~means success.
*
* @note:
- * It is possible to call @FT_Bitmap_Convert multiple times without
- * calling @FT_Bitmap_Done (the memory is simply reallocated).
+ * 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.
*
- * 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
* handling functions.
- *
- * `source->buffer` and `target->buffer` must neither be equal nor
- * overlap.
*/
FT_EXPORT( FT_Error )
FT_Bitmap_Convert( FT_Library library,
diff --git a/src/base/ftbitmap.c b/src/base/ftbitmap.c
index 2dcade968..6d2b86fbc 100644
--- a/src/base/ftbitmap.c
+++ b/src/base/ftbitmap.c
@@ -542,7 +542,7 @@
case FT_PIXEL_MODE_LCD_V:
case FT_PIXEL_MODE_BGRA:
{
- FT_Int pad, target_pitch;
+ FT_Int width = (FT_Int)source->width;
FT_Bitmap_Done( library, target );
@@ -551,20 +551,20 @@
target->rows = source->rows;
target->width = source->width;
- pad = 0;
- if ( alignment > 0 )
+ if ( alignment )
{
- pad = (FT_Int)source->width % alignment;
- if ( pad != 0 )
- pad = alignment - pad;
- }
+ FT_Int rem = width % alignment;
+
- target_pitch = (FT_Int)source->width + pad;
+ if ( rem )
+ width = alignment < 0 ? width - rem - alignment
+ : width - rem + alignment;
+ }
- if ( FT_QALLOC_MULT( target->buffer, target->rows, target_pitch ) )
+ if ( FT_QALLOC_MULT( target->buffer, target->rows, width ) )
return error;
- target->pitch = target->pitch < 0 ? -target_pitch : target_pitch;
+ target->pitch = alignment < 0 ? -width : width;
}
break;