From a9fbef27abe25e5986b5788da757563d24c89e41 Mon Sep 17 00:00:00 2001 From: Anuj Verma Date: Wed, 5 Aug 2020 09:12:29 +0530 Subject: [PATCH] [sdf -> bsdf] Extended to work with monochrome bitmaps. * src/sdf/ftbsdf.c (bsdf_init_distance_map): Handle monochrome bitmaps and convert them to the internal intermediate format, which can then be used to generate SDF. --- [GSoC]ChangeLog | 9 ++++++++ src/sdf/ftbsdf.c | 53 ++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/[GSoC]ChangeLog b/[GSoC]ChangeLog index 22014eb27..2419c53c1 100644 --- a/[GSoC]ChangeLog +++ b/[GSoC]ChangeLog @@ -1,3 +1,12 @@ +2020-08-5 Anuj Verma + + [sdf -> bsdf] Extended to work with monochrome bitmaps. + + * src/sdf/ftbsdf.c (bsdf_init_distance_map): Handle + monochrome bitmaps and convert them to the internal + intermediate format, which can then be used to + generate SDF. + 2020-08-3 Anuj Verma * src/sdf/ftsdfrend.c (ft_bsdf_render): Initialize diff --git a/src/sdf/ftbsdf.c b/src/sdf/ftbsdf.c index 1a9c84d91..f94533838 100644 --- a/src/sdf/ftbsdf.c +++ b/src/sdf/ftbsdf.c @@ -446,17 +446,54 @@ /* since the target bitmap can be 16bpp we manually */ /* convert the source bitmap to desired bpp. */ switch ( source->pixel_mode ) { - case FT_PIXEL_MODE_GRAY2: - case FT_PIXEL_MODE_GRAY4: - case FT_PIXEL_MODE_GRAY16: - case FT_PIXEL_MODE_LCD: - case FT_PIXEL_MODE_LCD_V: case FT_PIXEL_MODE_MONO: /* [TODO] */ - FT_ERROR(( "[bsdf] bsdf_copy_source_to_target: " - "support for pixel mode not yet added\n" )); - error = FT_THROW( Unimplemented_Feature ); + { + FT_Int t_width = worker->width; + FT_Int t_rows = worker->rows; + FT_Int s_width = source->width; + FT_Int s_rows = source->rows; + + + for ( t_j = 0; t_j < t_rows; t_j++ ) + { + for ( t_i = 0; t_i < t_width; t_i++ ) + { + FT_Int t_index = t_j * t_width + t_i; + FT_Int s_index; + FT_Int div, mod; + FT_Byte pixel, byte; + + + t[t_index] = zero_ed; + + s_i = t_i - x_diff; + s_j = t_j - y_diff; + + /* Assign 0 to padding similar to */ + /* the source bitmap. */ + if ( s_i < 0 || s_i >= s_width || + s_j < 0 || s_j >= s_rows ) + continue; + + if ( worker->params.flip_y ) + s_index = ( s_rows - s_j - 1 ) * source->pitch; + else + s_index = s_j * source->pitch; + + div = s_index + s_i / 8; + mod = 7 - s_i % 8; + + pixel = s[div]; + byte = 1 << mod; + + t[t_index].alpha = pixel & byte ? 255 : 0; + + pixel = 0; + } + } break; + } case FT_PIXEL_MODE_GRAY: { FT_Int t_width = worker->width;