[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2] bitmap_convert bcb547834: [base] Accept negative bitmap alig
From: |
Werner Lemberg |
Subject: |
[freetype2] bitmap_convert bcb547834: [base] Accept negative bitmap alignment for bottom-up flow. |
Date: |
Tue, 20 Sep 2022 10:18:03 -0400 (EDT) |
branch: bitmap_convert
commit bcb54783479cf29317445f26994799514fe1b9d5
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 | 21 ++++++++++-----------
2 files changed, 18 insertions(+), 19 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..0873554e2 100644
--- a/src/base/ftbitmap.c
+++ b/src/base/ftbitmap.c
@@ -542,7 +542,8 @@
case FT_PIXEL_MODE_LCD_V:
case FT_PIXEL_MODE_BGRA:
{
- FT_Int pad, target_pitch;
+ FT_Int width = (FT_Int)source->width;
+ FT_Int pad;
FT_Bitmap_Done( library, target );
@@ -551,20 +552,18 @@
target->rows = source->rows;
target->width = source->width;
- pad = 0;
- if ( alignment > 0 )
- {
- pad = (FT_Int)source->width % alignment;
- if ( pad != 0 )
- pad = alignment - pad;
- }
+ if ( !alignment )
+ alignment = 1;
- target_pitch = (FT_Int)source->width + pad;
+ pad = width % alignment;
+ 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 bcb547834: [base] Accept negative bitmap alignment for bottom-up flow.,
Werner Lemberg <=