[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2] bitmap_convert 2747c0900: [base] Accept negative bitmap alig
From: |
Werner Lemberg |
Subject: |
[freetype2] bitmap_convert 2747c0900: [base] Accept negative bitmap alignment for bottom-up flow. |
Date: |
Tue, 20 Sep 2022 12:08:10 -0400 (EDT) |
branch: bitmap_convert
commit 2747c09005984bdcc9dcb7ec4b466aad6f9523dd
Author: Alexei Podtelezhnikov <apodtele@gmail.com>
Commit: Alexei Podtelezhnikov <apodtele@gmail.com>
[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.
---
include/freetype/ftbitmap.h | 16 ++++++++--------
src/base/ftbitmap.c | 20 ++++++++++----------
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..364d84eed 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 pad = width % alignment;
+
- target_pitch = (FT_Int)source->width + pad;
+ if ( pad )
+ width = alignment < 0 ? width - ( alignment + pad )
+ : width + ( alignment - pad );
+ }
- 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;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2] bitmap_convert 2747c0900: [base] Accept negative bitmap alignment for bottom-up flow.,
Werner Lemberg <=