freetype-commit
[Top][All Lists]
Advanced

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

[freetype2-demos] master dee1c4c: [graph] Do not zero a new bitmap.


From: Werner Lemberg
Subject: [freetype2-demos] master dee1c4c: [graph] Do not zero a new bitmap.
Date: Sun, 17 Oct 2021 22:45:06 -0400 (EDT)

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

    [graph] Do not zero a new bitmap.
    
    The `grNewBitmap` function is mostly used to allocate and resize
    canvas, which is shortly flooded with a background color.  There is
    no need to zero it.
    
    * graph/grobjs.c (grNewBitmap): Always call `realloc` directly,
    which does not initialize the buffer.
    * graph/grobjs.c (grNewBitmap): Update description.
---
 graph/graph.h  |  7 ++++---
 graph/grobjs.c | 38 ++++++++++++++++----------------------
 2 files changed, 20 insertions(+), 25 deletions(-)

diff --git a/graph/graph.h b/graph/graph.h
index 90c9579..5a1cc17 100644
--- a/graph/graph.h
+++ b/graph/graph.h
@@ -162,7 +162,8 @@
   *    grNewBitmap
   *
   * <Description>
-  *    creates a new bitmap or resizes an existing one
+  *    Creates a new bitmap or resizes an existing one.  The allocated
+  *    pixel buffer is not initialized.
   *
   * <Input>
   *    pixel_mode   :: the target surface's pixel_mode
@@ -177,8 +178,8 @@
   *    Error code. 0 means success.
   *
   * <Note>
-  *    This function really allocates a pixel buffer, zero it, then
-  *    returns a descriptor for it.
+  *    This function really allocates a pixel buffer, then returns
+  *    a descriptor for it.
   *
   *    An existing bitmap will be resized.
   *
diff --git a/graph/grobjs.c b/graph/grobjs.c
index a7e0b0a..717e074 100644
--- a/graph/grobjs.c
+++ b/graph/grobjs.c
@@ -140,7 +140,8 @@
   *    grNewBitmap
   *
   * <Description>
-  *    creates a new bitmap or resizes an existing one
+  *    Creates a new bitmap or resizes an existing one.  The allocated
+  *    pixel buffer is not initialized.
   *
   * <Input>
   *    pixel_mode   :: the target surface's pixel_mode
@@ -162,7 +163,9 @@
                             int          height,
                             grBitmap    *bit )
   {
-    int  pitch;
+    int             pitch;
+    unsigned char*  buffer;
+
 
     /* check mode */
     if (check_mode(pixel_mode,num_grays))
@@ -197,29 +200,20 @@
         return 0;
     }
 
-    if ( !bit->buffer )
-    {
-       bit->buffer = grAlloc( (size_t)pitch * (size_t)height );
-       if (!bit->buffer) goto Fail;
-    }
-    else  /* resize */
+    buffer = (unsigned char*)realloc( bit->buffer,
+                                      (size_t)pitch * (size_t)height );
+    if ( !buffer && pitch && height )
     {
-       unsigned char*  buffer;
-
-
-       buffer = (unsigned char*)realloc( bit->buffer,
-                                         (size_t)pitch * (size_t)height );
-       if ( buffer || !pitch || !height )
-         bit->buffer = buffer;
-       else
-         goto Fail;
+      grError = gr_err_memory;
+      goto Fail;
     }
 
-    bit->width = width;
-    bit->rows  = height;
-    bit->pitch = pitch;
-    bit->mode  = pixel_mode;
-    bit->grays = num_grays;
+    bit->buffer = buffer;
+    bit->width  = width;
+    bit->rows   = height;
+    bit->pitch  = pitch;
+    bit->mode   = pixel_mode;
+    bit->grays  = num_grays;
 
     return 0;
 



reply via email to

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