freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2] master c456eeb47: [base] Discard and recreate bitmaps for co


From: Werner Lemberg
Subject: [freetype2] master c456eeb47: [base] Discard and recreate bitmaps for copying and converting.
Date: Thu, 22 Sep 2022 11:09:29 -0400 (EDT)

branch: master
commit c456eeb47add724147b8a28160ae0e7929e2a88d
Author: Alexei Podtelezhnikov <apodtele@gmail.com>
Commit: Alexei Podtelezhnikov <apodtele@gmail.com>

    [base] Discard and recreate bitmaps for copying and converting.
    
    Reusing target bitmaps for copying and converting is permitted.  It is,
    however, pointless to preserve their content before overwriting.  Free-
    malloc might be faster than realloc.
    
    * src/base/ftbitmap.c (FT_Bitmap_Copy, FT_Bitmap_Convert): Free
    an old buffer and create a new one.
---
 src/base/ftbitmap.c | 66 ++++++++++++++---------------------------------------
 1 file changed, 17 insertions(+), 49 deletions(-)

diff --git a/src/base/ftbitmap.c b/src/base/ftbitmap.c
index 7825895ad..c79409d7b 100644
--- a/src/base/ftbitmap.c
+++ b/src/base/ftbitmap.c
@@ -66,9 +66,7 @@
   {
     FT_Memory  memory;
     FT_Error   error  = FT_Err_Ok;
-
-    FT_Int    pitch;
-    FT_ULong  size;
+    FT_Int     pitch;
 
     FT_Int  source_pitch_sign, target_pitch_sign;
 
@@ -85,49 +83,28 @@
     source_pitch_sign = source->pitch < 0 ? -1 : 1;
     target_pitch_sign = target->pitch < 0 ? -1 : 1;
 
-    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 ( source_pitch_sign != target_pitch_sign )
+      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 )
-        FT_MEM_QREALLOC( target->buffer, target_size, size );
-    }
-    else
-      FT_MEM_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 );
+        FT_MEM_COPY( target->buffer, source->buffer,
+                     (FT_Long)source->rows * pitch );
       else
       {
         /* take care of bitmap flow */
@@ -542,15 +519,11 @@
     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  pad, target_pitch; 
+        FT_Int  old_target_pitch = target->pitch;
 
 
-        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;
@@ -566,15 +539,10 @@
 
         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 ( FT_QREALLOC( target->buffer,
-                          old_size, target->rows * (FT_UInt)target_pitch ) )
+        if ( FT_QALLOC_MULT( target->buffer, target->rows, target_pitch ) )
           return error;
 
-        target->pitch = target->pitch < 0 ? -target_pitch : target_pitch;
+        target->pitch = old_target_pitch < 0 ? -target_pitch : target_pitch;
       }
       break;
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]