[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2] anuj-distance-field ac961e1 81/95: * src/sdf/ftbsdf.c (bsdf_
From: |
Anuj Verma |
Subject: |
[freetype2] anuj-distance-field ac961e1 81/95: * src/sdf/ftbsdf.c (bsdf_is_edge): Use macros to make it look cleaner. |
Date: |
Sun, 2 Aug 2020 01:10:41 -0400 (EDT) |
branch: anuj-distance-field
commit ac961e12512ae5eed48ac0cf761714680161718f
Author: Anuj Verma <anujv@iitbhilai.ac.in>
Commit: 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.
---
[GSoC]ChangeLog | 9 +++++
src/sdf/ftbsdf.c | 109 +++++++++++++++----------------------------------------
2 files changed, 38 insertions(+), 80 deletions(-)
diff --git a/[GSoC]ChangeLog b/[GSoC]ChangeLog
index 798b614..85d7f79 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 a42c4d4..6950434 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:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2] anuj-distance-field ac961e1 81/95: * src/sdf/ftbsdf.c (bsdf_is_edge): Use macros to make it look cleaner.,
Anuj Verma <=