freetype-commit
[Top][All Lists]
Advanced

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

[freetype2-demos] master d05efca: Recycle some code.


From: Alexei Podtelezhnikov
Subject: [freetype2-demos] master d05efca: Recycle some code.
Date: Thu, 19 Apr 2018 22:45:46 -0400 (EDT)

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

    Recycle some code.
    
    * graph/grfill.c (grFillRect): Call `memcpy' to speed it up.
    * src/ftcommon.c (FTDemo_Display_Clear): Call `grFillRect'.
---
 ChangeLog      |  7 +++++++
 graph/grfill.c | 35 +++++++++++++++++++++++++++++------
 src/ftcommon.c | 25 +------------------------
 3 files changed, 37 insertions(+), 30 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c4ce76e..60d09f1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2018-04-19  Alexei Podtelezhnikov  <address@hidden>
+
+       Recycle some code.
+
+       * graph/grfill.c (grFillRect): Call `memcpy' to speed it up.
+       * src/ftcommon.c (FTDemo_Display_Clear): Call `grFillRect'.
+
 2018-04-18  Alexei Podtelezhnikov  <address@hidden>
 
        [ftdump] Special case for copyright sign.
diff --git a/graph/grfill.c b/graph/grfill.c
index c91fddb..8f5093d 100644
--- a/graph/grfill.c
+++ b/graph/grfill.c
@@ -231,6 +231,7 @@ grFillRect( grBitmap*   target,
   int              delta;
   unsigned char*   line;
   grFillHLineFunc  hline_func;
+  size_t           size = 0;
 
   if ( x < 0 )
   {
@@ -253,14 +254,36 @@ grFillRect( grBitmap*   target,
   if ( width <= 0 || height <= 0 )
     return;
 
+  line = target->buffer + y*target->pitch;
+  if ( target->pitch < 0 )
+    line -= target->pitch*(target->rows-1);
+
   hline_func = gr_fill_hline_funcs[ target->mode ];
-  if ( hline_func )
-  {
-    line = target->buffer + y*target->pitch;
-    if ( target->pitch < 0 )
-      line -= target->pitch*(target->rows-1);
 
-    for ( ; height > 0; height--, line += target->pitch )
+  switch ( target->mode )
+  {
+  case gr_pixel_mode_rgb32:
+    size += width;
+  case gr_pixel_mode_rgb24:
+    size += width;
+  case gr_pixel_mode_rgb565:
+  case gr_pixel_mode_rgb555:
+    size += width;
+  case gr_pixel_mode_gray:
+  case gr_pixel_mode_pal8:
+    size += width;
+    hline_func( line, x, width, color );
+    for ( ; --height > 0; line += target->pitch )
+      memcpy( line + target->pitch, line, size );
+    break;
+
+  case gr_pixel_mode_pal4:
+  case gr_pixel_mode_mono:
+    for ( ; height-- > 0; line += target->pitch )
       hline_func( line, x, width, color );
+    break;
+
+  default:
+    break;
   }
 }
diff --git a/src/ftcommon.c b/src/ftcommon.c
index b762a23..123df6a 100644
--- a/src/ftcommon.c
+++ b/src/ftcommon.c
@@ -162,32 +162,9 @@
   FTDemo_Display_Clear( FTDemo_Display*  display )
   {
     grBitmap*  bit   = display->bitmap;
-    int        pitch = bit->pitch;
 
 
-    if ( pitch < 0 )
-      pitch = -pitch;
-
-    if ( bit->mode == gr_pixel_mode_gray )
-      memset( bit->buffer,
-              display->back_color.value,
-              (unsigned int)( pitch * bit->rows ) );
-    else
-    {
-      unsigned char*  p = bit->buffer;
-      int             i;
-
-
-      for ( i = 0; i < pitch; i += 3, p += 3 )
-      {
-        p[0] = display->back_color.chroma[0];
-        p[1] = display->back_color.chroma[1];
-        p[2] = display->back_color.chroma[2];
-      }
-
-      for ( i = 1; i < bit->rows; i++, p += pitch )
-        memcpy( p, p - pitch, (size_t)pitch );
-    }
+    grFillRect( bit, 0, 0, bit->width, bit->rows, display->back_color );
   }
 
 



reply via email to

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