summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/freetype/src/base/ftbitmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/freetype/src/base/ftbitmap.c')
-rw-r--r--src/3rdparty/freetype/src/base/ftbitmap.c117
1 files changed, 42 insertions, 75 deletions
diff --git a/src/3rdparty/freetype/src/base/ftbitmap.c b/src/3rdparty/freetype/src/base/ftbitmap.c
index 0e0a76fe40..1c93648dcb 100644
--- a/src/3rdparty/freetype/src/base/ftbitmap.c
+++ b/src/3rdparty/freetype/src/base/ftbitmap.c
@@ -4,7 +4,7 @@
*
* FreeType utility functions for bitmaps (body).
*
- * Copyright (C) 2004-2019 by
+ * Copyright (C) 2004-2023 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used,
@@ -16,12 +16,11 @@
*/
-#include <ft2build.h>
-#include FT_INTERNAL_DEBUG_H
+#include <freetype/internal/ftdebug.h>
-#include FT_BITMAP_H
-#include FT_IMAGE_H
-#include FT_INTERNAL_OBJECTS_H
+#include <freetype/ftbitmap.h>
+#include <freetype/ftimage.h>
+#include <freetype/internal/ftobjs.h>
/**************************************************************************
@@ -67,11 +66,8 @@
{
FT_Memory memory;
FT_Error error = FT_Err_Ok;
-
- FT_Int pitch;
- FT_ULong size;
-
- FT_Int source_pitch_sign, target_pitch_sign;
+ FT_Int pitch;
+ FT_Int flip;
if ( !library )
@@ -83,53 +79,29 @@
if ( source == target )
return FT_Err_Ok;
- source_pitch_sign = source->pitch < 0 ? -1 : 1;
- target_pitch_sign = target->pitch < 0 ? -1 : 1;
+ flip = ( source->pitch < 0 && target->pitch > 0 ) ||
+ ( source->pitch > 0 && target->pitch < 0 );
- if ( !source->buffer )
- {
- *target = *source;
- if ( source_pitch_sign != target_pitch_sign )
- target->pitch = -target->pitch;
+ memory = library->memory;
+ FT_FREE( target->buffer );
+
+ *target = *source;
+
+ if ( flip )
+ target->pitch = -target->pitch;
+ if ( !source->buffer )
return FT_Err_Ok;
- }
- memory = library->memory;
pitch = source->pitch;
-
if ( pitch < 0 )
pitch = -pitch;
- size = (FT_ULong)pitch * source->rows;
-
- if ( target->buffer )
- {
- FT_Int target_pitch = target->pitch;
- FT_ULong target_size;
-
- if ( target_pitch < 0 )
- target_pitch = -target_pitch;
- target_size = (FT_ULong)target_pitch * target->rows;
-
- if ( target_size != size )
- (void)FT_QREALLOC( target->buffer, target_size, size );
- }
- else
- (void)FT_QALLOC( target->buffer, size );
+ FT_MEM_QALLOC_MULT( target->buffer, target->rows, pitch );
if ( !error )
{
- unsigned char *p;
-
-
- p = target->buffer;
- *target = *source;
- target->buffer = p;
-
- if ( source_pitch_sign == target_pitch_sign )
- FT_MEM_COPY( target->buffer, source->buffer, size );
- else
+ if ( flip )
{
/* take care of bitmap flow */
FT_UInt i;
@@ -147,6 +119,9 @@
t -= pitch;
}
}
+ else
+ FT_MEM_COPY( target->buffer, source->buffer,
+ (FT_Long)source->rows * pitch );
}
return error;
@@ -481,7 +456,7 @@
* A gamma of 2.2 is fair to assume. And then, we need to
* undo the premultiplication too.
*
- * https://accessibility.kde.org/hsl-adjusted.php
+ * http://www.brucelindbloom.com/index.html?WorkingSpaceInfo.html#SideNotes
*
* We do the computation with integers only, applying a gamma of 2.0.
* We guarantee 32-bit arithmetic to avoid overflow but the resulting
@@ -489,9 +464,9 @@
*
*/
- l = ( 4732UL /* 0.0722 * 65536 */ * bgra[0] * bgra[0] +
- 46871UL /* 0.7152 * 65536 */ * bgra[1] * bgra[1] +
- 13933UL /* 0.2126 * 65536 */ * bgra[2] * bgra[2] ) >> 16;
+ l = ( 4731UL /* 0.072186 * 65536 */ * bgra[0] * bgra[0] +
+ 46868UL /* 0.715158 * 65536 */ * bgra[1] * bgra[1] +
+ 13937UL /* 0.212656 * 65536 */ * bgra[2] * bgra[2] ) >> 16;
/*
* Final transparency can be determined as follows.
@@ -543,39 +518,31 @@
case FT_PIXEL_MODE_LCD_V:
case FT_PIXEL_MODE_BGRA:
{
- FT_Int pad, old_target_pitch, target_pitch;
- FT_ULong old_size;
+ FT_Int width = (FT_Int)source->width;
+ FT_Int neg = ( target->pitch == 0 && source->pitch < 0 ) ||
+ target->pitch < 0;
- old_target_pitch = target->pitch;
- if ( old_target_pitch < 0 )
- old_target_pitch = -old_target_pitch;
-
- old_size = target->rows * (FT_UInt)old_target_pitch;
+ FT_Bitmap_Done( library, target );
target->pixel_mode = FT_PIXEL_MODE_GRAY;
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 ( target_pitch > 0 &&
- (FT_ULong)target->rows > FT_ULONG_MAX / (FT_ULong)target_pitch )
- return FT_THROW( Invalid_Argument );
+ if ( rem )
+ width = alignment > 0 ? width - rem + alignment
+ : width - rem - alignment;
+ }
- if ( FT_QREALLOC( target->buffer,
- old_size, target->rows * (FT_UInt)target_pitch ) )
+ if ( FT_QALLOC_MULT( target->buffer, target->rows, width ) )
return error;
- target->pitch = target->pitch < 0 ? -target_pitch : target_pitch;
+ target->pitch = neg ? -width : width;
}
break;
@@ -908,14 +875,14 @@
final_rows = ( final_ury - final_lly ) >> 6;
#ifdef FT_DEBUG_LEVEL_TRACE
- FT_TRACE5(( "FT_Bitmap_Blend:\n"
- " source bitmap: (%d, %d) -- (%d, %d); %d x %d\n",
+ FT_TRACE5(( "FT_Bitmap_Blend:\n" ));
+ FT_TRACE5(( " source bitmap: (%ld, %ld) -- (%ld, %ld); %d x %d\n",
source_llx / 64, source_lly / 64,
source_urx / 64, source_ury / 64,
source_->width, source_->rows ));
if ( target->width && target->rows )
- FT_TRACE5(( " target bitmap: (%d, %d) -- (%d, %d); %d x %d\n",
+ FT_TRACE5(( " target bitmap: (%ld, %ld) -- (%ld, %ld); %d x %d\n",
target_llx / 64, target_lly / 64,
target_urx / 64, target_ury / 64,
target->width, target->rows ));
@@ -923,7 +890,7 @@
FT_TRACE5(( " target bitmap: empty\n" ));
if ( final_width && final_rows )
- FT_TRACE5(( " final bitmap: (%d, %d) -- (%d, %d); %d x %d\n",
+ FT_TRACE5(( " final bitmap: (%ld, %ld) -- (%ld, %ld); %d x %d\n",
final_llx / 64, final_lly / 64,
final_urx / 64, final_ury / 64,
final_width, final_rows ));