summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnuj Verma <anujv@iitbhilai.ac.in>2020-07-27 17:04:33 +0530
committeranujverma <anujv@iitbhilai.ac.in>2020-08-02 16:33:21 +0530
commit419633c3745dcb093ee26afb593895608417d73e (patch)
treec69c76e29ef8b4adaccfdc5900a128254a6f72d3
parent262e9649f385a82bb460741bd729bd35817984cd (diff)
downloadfreetype2-419633c3745dcb093ee26afb593895608417d73e.tar.gz
* src/sdf/ftbsdf.c (bsdf_is_edge): Use macros to make it look cleaner.
Use `CHECK_NEIGHBOR' macro to check neighbors while finding edges. Make the code more readable and look cleaner.
-rw-r--r--[GSoC]ChangeLog9
-rw-r--r--src/sdf/ftbsdf.c109
2 files changed, 38 insertions, 80 deletions
diff --git a/[GSoC]ChangeLog b/[GSoC]ChangeLog
index 798b61495..85d7f794a 100644
--- a/[GSoC]ChangeLog
+++ b/[GSoC]ChangeLog
@@ -1,5 +1,14 @@
2020-07-27 Anuj Verma <anujv@iitbhilai.ac.in>
+ * src/sdf/ftbsdf.c (bsdf_is_edge): Use macros to
+ make it look cleaner.
+
+ Use `CHECK_NEIGHBOR' macro to check neighbors while
+ finding edges. Make the code more readable and look
+ cleaner.
+
+2020-07-27 Anuj Verma <anujv@iitbhilai.ac.in>
+
[sdf -> bsdf] Fix edge detection bug.
* src/sdf/ftbsdf.c (bsdf_is_edge): [BUG] Check all
diff --git a/src/sdf/ftbsdf.c b/src/sdf/ftbsdf.c
index a42c4d4a4..69504342a 100644
--- a/src/sdf/ftbsdf.c
+++ b/src/sdf/ftbsdf.c
@@ -82,6 +82,24 @@
*
*/
+ #ifdef CHECK_NEIGHBOR
+ #undef CHECK_NEIGHBOR
+ #endif
+
+ /* Use the macro only in `bsdf_is_edge' function. */
+ #define CHECK_NEIGHBOR( x_offset, y_offset ) \
+ if ( x + x_offset >= 0 && x + x_offset < w && \
+ y + y_offset >= 0 && y + y_offset < r ) \
+ { \
+ num_neighbour++; \
+ to_check = s + y_offset * w + x_offset; \
+ if ( *to_check == 0 ) \
+ { \
+ is_edge = 1; \
+ goto Done; \
+ } \
+ }
+
/**************************************************************************
*
* @Function:
@@ -115,108 +133,39 @@
goto Done;
/* up */
- if ( y > 0 )
- {
- num_neighbour++;
- to_check = s - w;
- if ( *to_check == 0 )
- {
- is_edge = 1;
- goto Done;
- }
- }
+ CHECK_NEIGHBOR( 0, -1 );
/* down */
- if ( y < r - 2 )
- {
- num_neighbour++;
- to_check = s + w;
- if ( *to_check == 0 )
- {
- is_edge = 1;
- goto Done;
- }
- }
+ CHECK_NEIGHBOR( 0, 1 );
/* left */
- if ( x > 0 )
- {
- num_neighbour++;
- to_check = s - 1;
- if ( *to_check == 0 )
- {
- is_edge = 1;
- goto Done;
- }
- }
+ CHECK_NEIGHBOR( -1, 0 );
/* right */
- if ( x < w - 2 )
- {
- num_neighbour++;
- to_check = s + 1;
- if ( *to_check == 0 )
- {
- is_edge = 1;
- goto Done;
- }
- }
+ CHECK_NEIGHBOR( 1, 0 );
/* up left */
- if ( y > 0 && x > 0 )
- {
- num_neighbour++;
- to_check = s - w - 1;
- if ( *to_check == 0 )
- {
- is_edge = 1;
- goto Done;
- }
- }
+ CHECK_NEIGHBOR( -1, -1 );
/* up right */
- if ( y > 0 && x < w - 2 )
- {
- num_neighbour++;
- to_check = s - w + 1;
- if ( *to_check == 0 )
- {
- is_edge = 1;
- goto Done;
- }
- }
+ CHECK_NEIGHBOR( 1, -1 );
/* down left */
- if ( y < r - 2 && x > 0 )
- {
- num_neighbour++;
- to_check = s + w - 1;
- if ( *to_check == 0 )
- {
- is_edge = 1;
- goto Done;
- }
- }
+ CHECK_NEIGHBOR( -1, 1 );
/* down right */
- if ( y < r - 2 && x < w - 2 )
- {
- num_neighbour++;
- to_check = s + w + 1;
- if ( *to_check == 0 )
- {
- is_edge = 1;
- goto Done;
- }
- }
+ CHECK_NEIGHBOR( 1, 1 );
if ( num_neighbour != 8 )
is_edge = 1;
Done:
return is_edge;
+
}
+ #undef CHECK_NEIGHBOR
+
/**************************************************************************
*
* @Function: