[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] upgray fbf5c76: [graph] Handle glyphs with 4 or 16 gra
From: |
Werner Lemberg |
Subject: |
[freetype2-demos] upgray fbf5c76: [graph] Handle glyphs with 4 or 16 grays. |
Date: |
Wed, 1 Mar 2023 23:18:28 -0500 (EST) |
branch: upgray
commit fbf5c760fca0709cde0e8f13ec8bd3d4de6e1dfb
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 | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/graph/gblblit.c b/graph/gblblit.c
index 0c5f756..f7b7fae 100644
--- a/graph/gblblit.c
+++ b/graph/gblblit.c
@@ -241,6 +241,27 @@
/* */
+/* 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 );
+
+
+ for ( i = 4; i <= size; i += 4, buf++ )
+ *buf *= scale;
+
+ for ( i -= 4; i < size; i++ )
+ glyph->buffer[i] *= scale;
+
+ glyph->grays = 256;
+}
+
+
static int
gblender_blit_init( GBlenderBlit blit,
int dst_x,
@@ -269,6 +290,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;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] upgray fbf5c76: [graph] Handle glyphs with 4 or 16 grays.,
Werner Lemberg <=