freetype-commit
[Top][All Lists]
Advanced

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

[freetype2-demos] master 746d5be: [graph] Handle glyphs with 4 or 16 gra


From: Werner Lemberg
Subject: [freetype2-demos] master 746d5be: [graph] Handle glyphs with 4 or 16 grays.
Date: Thu, 2 Mar 2023 09:27:15 -0500 (EST)

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

    [graph] Handle glyphs with 4 or 16 grays.
    
    * graph/gblblit.c (gblender_glyph_upgray): Convert to 256 grays.
    (gblender_blit_init): Call it if necessary.
---
 graph/gblblit.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/graph/gblblit.c b/graph/gblblit.c
index 0c5f756..57c1f1d 100644
--- a/graph/gblblit.c
+++ b/graph/gblblit.c
@@ -241,6 +241,29 @@
 
 /* */
 
+/* works best to convert from 4 or 16 grays to 256 grays,
+ * needs aligned buffers and clean padding
+ */
+static void
+gblender_glyph_upgray( grBitmap*  glyph )
+{
+  int        i, size = abs( glyph->pitch ) * glyph->rows;
+  uint32_t*  buf = (uint32_t*)glyph->buffer;
+  uint32_t   scale = 255U / ( glyph->grays - 1 );
+
+
+  /* four bytes at a time */
+  for ( i = 0; i <= size - 4; i += 4, buf++ )
+    *buf *= scale;
+
+  /* remaining bytes */
+  for ( ; i < size; i++ )
+    glyph->buffer[i] *= scale;
+
+  glyph->grays = 256;
+}
+
+
 static int
 gblender_blit_init( GBlenderBlit           blit,
                     int                    dst_x,
@@ -269,6 +292,8 @@ gblender_blit_init( GBlenderBlit           blit,
   {
   case gr_pixel_mode_gray:
     src_format = GBLENDER_SOURCE_GRAY8;
+    if ( glyph->grays != 256 )
+      gblender_glyph_upgray( glyph );
     if ( blender->channels )
       gblender_clear( blender );
     break;



reply via email to

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