From f057095bef5133f152f56c560fc0e30e8a85262b Mon Sep 17 00:00:00 2001 From: Anuj Verma Date: Mon, 27 Jul 2020 10:25:52 +0530 Subject: [PATCH] [sdf -> bsdf] Added edge detection algorithm. Added edge detection algorithm. It works by checking the neighboring pixels and if any neighbor is not filled (i.e. belongs to background) we mark the pixel as edge by setting it's distance to 0. * src/sdf/ftbsdf.c (bsdf_is_edge): Added function to detect if the pixel is an edge. --- [GSoC]ChangeLog | 12 ++++++ src/sdf/ftbsdf.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 106 insertions(+), 3 deletions(-) diff --git a/[GSoC]ChangeLog b/[GSoC]ChangeLog index ae4cae034..9d15fea09 100644 --- a/[GSoC]ChangeLog +++ b/[GSoC]ChangeLog @@ -1,3 +1,15 @@ +2020-07-27 Anuj Verma + + [sdf -> bsdf] Added edge detection algorithm. + + Added edge detection algorithm. It works by checking + the neighboring pixels and if any neighbor is not + filled (i.e. belongs to background) we mark the + pixel as edge by setting it's distance to 0. + + * src/sdf/ftbsdf.c (bsdf_is_edge): Added function to + detect if the pixel is an edge. + 2020-07-27 Anuj Verma [sdf -> bsdf] Added the second pass of the '8SED'. diff --git a/src/sdf/ftbsdf.c b/src/sdf/ftbsdf.c index caa1acfb5..004346a04 100644 --- a/src/sdf/ftbsdf.c +++ b/src/sdf/ftbsdf.c @@ -82,6 +82,94 @@ * */ + /************************************************************************** + * + * @Function: + * bsdf_is_edge + * + * @Description: + * [TODO] + * + * @Input: + * [TODO] + * + * @Return: + * [TODO] + */ + static FT_Bool + bsdf_is_edge( FT_Byte* s, /* source bitmap */ + FT_Int x, /* x index of point to check */ + FT_Int y, /* y index of point to check */ + FT_Int w, /* width */ + FT_Int r ) /* rows */ + { + FT_Bool is_edge = 0; + FT_Byte* to_check = NULL; + FT_Int num_neighbour = 0; + + if ( y == 7 && x == 20 ) + to_check = NULL; + + if ( *s == 0 ) + goto Done; + + /* up */ + if ( y > 0 ) + { + num_neighbour++; + to_check = s - w; + if ( *to_check == 0 ) + { + is_edge = 1; + goto Done; + } + } + + /* down */ + if ( y < r - 2 ) + { + num_neighbour++; + to_check = s + w; + if ( *to_check == 0 ) + { + is_edge = 1; + goto Done; + } + } + + /* left */ + if ( x > 0 ) + { + num_neighbour++; + to_check = s - 1; + if ( *to_check == 0 ) + { + is_edge = 1; + goto Done; + } + } + + /* right */ + if ( x < w - 2 ) + { + num_neighbour++; + to_check = s + 1; + if ( *to_check == 0 ) + { + is_edge = 1; + goto Done; + } + } + + + + if ( num_neighbour != 4 ) + is_edge = 1; + + Done: + return is_edge; + } + /************************************************************************** * * @Function: @@ -233,19 +321,22 @@ pixel_value <<= 8; #else - if ( pixel_value ) + if ( bsdf_is_edge( s + s_index , s_i, s_j, s_width, s_rows ) ) { t[t_index].dist = 0; - t[t_index].sign = 1; } else { t[t_index].near.x = FT_INT_MAX; t[t_index].near.y = FT_INT_MAX; t[t_index].dist = 128 * ONE; - t[t_index].sign = -1; } + if ( pixel_value ) + t[t_index].sign = 1; + else + t[t_index].sign = -1; + #endif } }