[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.
This commit is contained in:
Anuj Verma 2020-07-27 10:25:52 +05:30 committed by anujverma
parent 8564d5caf2
commit f057095bef
2 changed files with 106 additions and 3 deletions

View File

@ -1,3 +1,15 @@
2020-07-27 Anuj Verma <anujv@iitbhilai.ac.in>
[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 <anujv@iitbhilai.ac.in>
[sdf -> bsdf] Added the second pass of the '8SED'.

View File

@ -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
}
}