freetype-commit
[Top][All Lists]
Advanced

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

[freetype2-demos] master 677d7ea 2/3: * graph/grobjs.c (grNewBitmap): Im


From: Alexei Podtelezhnikov
Subject: [freetype2-demos] master 677d7ea 2/3: * graph/grobjs.c (grNewBitmap): Implement bitmap resizing.
Date: Tue, 19 May 2020 00:51:42 -0400 (EDT)

branch: master
commit 677d7eac4da49c7b6623ddeef0458a06c8289512
Author: Alexei Podtelezhnikov <address@hidden>
Commit: Alexei Podtelezhnikov <address@hidden>

    * graph/grobjs.c (grNewBitmap): Implement bitmap resizing.
    * graph/graph.h (grNewBitmap): Document it.
    
    * graph/grdevice.c (grNewSurface): Prevent accidental resizing.
    * graph/win32/grwin32.c: Ditto.
---
 ChangeLog             |  8 ++++++++
 graph/graph.h         |  4 +++-
 graph/grdevice.c      |  2 ++
 graph/grobjs.c        | 33 ++++++++++++++++++++++++---------
 graph/win32/grwin32.c |  2 ++
 5 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4ad2665..e49e4d1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2020-05-18  Alexei Podtelezhnikov  <address@hidden>
 
+       * graph/grobjs.c (grNewBitmap): Implement bitmap resizing.
+       * graph/graph.h (grNewBitmap): Document it.
+
+       * graph/grdevice.c (grNewSurface): Prevent accidental resizing.
+       * graph/win32/grwin32.c: Ditto.
+
+2020-05-18  Alexei Podtelezhnikov  <address@hidden>
+
        * graph/x11/grx11.c (gr_x11_device_init): Remove one nested cycle.
 
 2020-05-01  David Turner  <address@hidden>
diff --git a/graph/graph.h b/graph/graph.h
index da1efbd..357bfb1 100644
--- a/graph/graph.h
+++ b/graph/graph.h
@@ -122,7 +122,7 @@
   *    grNewBitmap
   *
   * <Description>
-  *    creates a new bitmap
+  *    creates a new bitmap or resizes an existing one
   *
   * <Input>
   *    pixel_mode   :: the target surface's pixel_mode
@@ -140,6 +140,8 @@
   *    This function really allocates a pixel buffer, zero it, then
   *    returns a descriptor for it.
   *
+  *    An existing bitmap will be resized.
+  *
   *    Call grDoneBitmap when you're done with it..
   *
   **********************************************************************/
diff --git a/graph/grdevice.c b/graph/grdevice.c
index 8b51dd8..26d7b7a 100644
--- a/graph/grdevice.c
+++ b/graph/grdevice.c
@@ -145,6 +145,8 @@
     surface = (grSurface*)grAlloc( device->surface_objsize );
     if (!surface) return 0;
 
+    bitmap->buffer = NULL;
+
     if ( !device->init_surface( surface, bitmap ) )
     {
       grFree( (void *)surface );
diff --git a/graph/grobjs.c b/graph/grobjs.c
index d9b5f72..514cc91 100644
--- a/graph/grobjs.c
+++ b/graph/grobjs.c
@@ -139,7 +139,7 @@
   *    grNewBitmap
   *
   * <Description>
-  *    creates a new bitmap
+  *    creates a new bitmap or resizes an existing one
   *
   * <Input>
   *    pixel_mode   :: the target surface's pixel_mode
@@ -174,11 +174,6 @@
       goto Fail;
     }
 
-    bit->width = width;
-    bit->rows  = height;
-    bit->mode  = pixel_mode;
-    bit->grays = num_grays;
-
     pitch = width;
 
     switch (pixel_mode)
@@ -201,9 +196,29 @@
         return 0;
     }
 
-    bit->pitch  = pitch;
-    bit->buffer = grAlloc( (unsigned long)( bit->pitch * bit->rows ) );
-    if (!bit->buffer) goto Fail;
+    if ( !bit->buffer )
+    {
+       bit->buffer = grAlloc( (unsigned long)( pitch * height ) );
+       if (!bit->buffer) goto Fail;
+    }
+    else  /* resize */
+    {
+       unsigned char*  buffer;
+
+
+       buffer = (unsigned char*)realloc( bit->buffer,
+                        (unsigned long)( pitch * height ) );
+       if ( buffer )
+         bit->buffer = buffer;
+       else
+         goto Fail;
+    }
+
+    bit->width = width;
+    bit->rows  = height;
+    bit->pitch = pitch;
+    bit->mode  = pixel_mode;
+    bit->grays = num_grays;
 
     return 0;
 
diff --git a/graph/win32/grwin32.c b/graph/win32/grwin32.c
index cf98b36..e7bf2d1 100644
--- a/graph/win32/grwin32.c
+++ b/graph/win32/grwin32.c
@@ -351,6 +351,7 @@ gr_win32_surface_init( grWin32Surface*  surface,
     return 0;
 
   /* allocate the BGR shadow bitmap */
+  surface->bgrBitmap.buffer = NULL;
   if ( grNewBitmap( bitmap->mode,
                     bitmap->grays,
                     bitmap->width,
@@ -361,6 +362,7 @@ gr_win32_surface_init( grWin32Surface*  surface,
   surface->bgrBitmap.pitch = -surface->bgrBitmap.pitch;
 
 #ifdef SWIZZLE
+  surface->swizzle_bitmap.buffer = NULL;
   if ( bitmap->mode == gr_pixel_mode_rgb24 )
   {
     if ( grNewBitmap( bitmap->mode,



reply via email to

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