[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2] anuj-distance-field dd52766 55/93: [sdf] Added more properti
From: |
Anuj Verma |
Subject: |
[freetype2] anuj-distance-field dd52766 55/93: [sdf] Added more properties. |
Date: |
Sun, 2 Aug 2020 07:04:22 -0400 (EDT) |
branch: anuj-distance-field
commit dd5276601c518993c3edc05af0d1b082f4a35afb
Author: Anuj Verma <anujv@iitbhilai.ac.in>
Commit: anujverma <anujv@iitbhilai.ac.in>
[sdf] Added more properties.
Added two properties:
- `flip_y': To flip the generated SDF along the y axis.
- `flip_sign': By default outside is treated to have
negative sign, setting `flip_sign' to 1 the outside
pixels will have positive sign.
* src/sdf/ftsdf.* (*): Use the newly added properties.
* src/sdf/ftsdfrend.* (*): Add the newly added properties,
and add functionality to set them using `FT_Property_Set'.
---
[GSoC]ChangeLog | 15 +++++++++++++++
src/sdf/ftsdf.c | 36 +++++++++++++++++++++++++++---------
src/sdf/ftsdf.h | 2 ++
src/sdf/ftsdfrend.c | 38 +++++++++++++++++++++++++++++++++++++-
src/sdf/ftsdfrend.h | 2 ++
5 files changed, 83 insertions(+), 10 deletions(-)
diff --git a/[GSoC]ChangeLog b/[GSoC]ChangeLog
index 72e763c..fc25667 100644
--- a/[GSoC]ChangeLog
+++ b/[GSoC]ChangeLog
@@ -1,5 +1,20 @@
2020-07-13 Anuj Verma <anujv@iitbhilai.ac.in>
+ [sdf] Added more properties.
+
+ Added two properties:
+ - `flip_y': To flip the generated SDF along the y axis.
+ - `flip_sign': By default outside is treated to have
+ negative sign, setting `flip_sign' to 1 the outside
+ pixels will have positive sign.
+
+ * src/sdf/ftsdf.* (*): Use the newly added properties.
+
+ * src/sdf/ftsdfrend.* (*): Add the newly added properties,
+ and add functionality to set them using `FT_Property_Set'.
+
+2020-07-13 Anuj Verma <anujv@iitbhilai.ac.in>
+
[sdf] Check for left or right fill.
* src/sdf/ftsdf.c (SDF_Params): Added struct which
diff --git a/src/sdf/ftsdf.c b/src/sdf/ftsdf.c
index 9d530db..4797be8 100644
--- a/src/sdf/ftsdf.c
+++ b/src/sdf/ftsdf.c
@@ -2470,8 +2470,6 @@
contour_list = shape->contours;
- index = ( rows - y - 1 ) * width + x;
-
/* iterate through all the contours manually */
while ( contour_list ) {
SDF_Signed_Distance current_dist = max_sdf;
@@ -2500,11 +2498,18 @@
if ( internal_params.orientation == FT_ORIENTATION_FILL_LEFT )
min_dist.sign = -min_dist.sign;
+ if ( internal_params.flip_sign )
+ min_dist.sign = -min_dist.sign;
min_dist.distance /= 64; /* convert from 16.16 to 22.10 */
value = min_dist.distance & 0x0000FFFF; /* truncate to 6.10 */
value *= min_dist.sign;
+ if ( internal_params.flip_y )
+ index = y * width + x;
+ else
+ index = ( rows - y - 1 ) * width + x;
+
buffer[index] = value;
}
}
@@ -2642,8 +2647,6 @@
grid_point.x += FT_INT_26D6( 1 ) / 2;
grid_point.y += FT_INT_26D6( 1 ) / 2;
- index = ( rows - y - 1 ) * width + x;
-
FT_CALL( sdf_edge_get_min_distance( edges,
grid_point,
&dist ) );
@@ -2659,6 +2662,11 @@
if ( USE_SQUARED_DISTANCES )
dist.distance = square_root( dist.distance );
+ if ( internal_params.flip_y )
+ index = y * width + x;
+ else
+ index = ( rows - y - 1 ) * width + x;
+
/* check weather the pixel is set or not */
if ( dists[index].sign == 0 )
dists[index] = dist;
@@ -2704,7 +2712,10 @@
/* convert from 16.16 to 6.10 */
dists[index].distance /= 64;
- buffer[index] = (FT_Short)dists[index].distance * current_sign;
+ if ( internal_params.flip_sign )
+ buffer[index] = (FT_Short)dists[index].distance * -current_sign;
+ else
+ buffer[index] = (FT_Short)dists[index].distance * current_sign;
}
}
@@ -2920,7 +2931,7 @@
FT_26D6_Vec current_pos;
SDF_Signed_Distance min_dist = max_sdf;
SDF_Edge* edges = relevant_list;
- FT_Int index = ( rows - y - 1 ) * width + x;
+ FT_Int index;
if ( x < 0 || x >= width ) continue;
@@ -2962,11 +2973,18 @@
if ( USE_SQUARED_DISTANCES )
min_dist.distance = square_root( min_dist.distance );
- if ( internal_params.orientation == FT_ORIENTATION_FILL_RIGHT )
+ if ( internal_params.orientation == FT_ORIENTATION_FILL_LEFT )
+ min_dist.sign = -min_dist.sign;
+ if ( internal_params.flip_sign )
min_dist.sign = -min_dist.sign;
min_dist.distance /= 64;
+ if ( internal_params.flip_y )
+ index = y * width + x;
+ else
+ index = ( rows - y - 1 ) * width + x;
+
buffer[index] = (FT_Short)min_dist.distance * min_dist.sign;
}
@@ -3104,8 +3122,8 @@
/* setup the params */
internal_params.orientation = FT_Outline_Get_Orientation( outline );
- internal_params.flip_sign = 0;
- internal_params.flip_y = 0;
+ internal_params.flip_sign = sdf_params->flip_sign;
+ internal_params.flip_y = sdf_params->flip_y;
FT_CALL( sdf_shape_new( memory, &shape ) );
diff --git a/src/sdf/ftsdf.h b/src/sdf/ftsdf.h
index 58b9148..edad035 100644
--- a/src/sdf/ftsdf.h
+++ b/src/sdf/ftsdf.h
@@ -35,6 +35,8 @@ FT_BEGIN_HEADER
{
FT_Raster_Params root;
FT_UInt spread;
+ FT_Bool flip_sign;
+ FT_Bool flip_y;
} SDF_Raster_Params;
diff --git a/src/sdf/ftsdfrend.c b/src/sdf/ftsdfrend.c
index 85a716d..0b0bd5a 100644
--- a/src/sdf/ftsdfrend.c
+++ b/src/sdf/ftsdfrend.c
@@ -61,6 +61,24 @@
FT_TRACE7(( "[sdf] sdf_property_set: "
"updated property `spread' to %d\n", val ));
}
+ else if ( ft_strcmp( property_name, "flip_sign" ) == 0 )
+ {
+ FT_Int val = *(const FT_Int*)value;
+
+
+ render->flip_sign = val ? 1 : 0;
+ FT_TRACE7(( "[sdf] sdf_property_set: "
+ "updated property `flip_sign' to %d\n", val ));
+ }
+ else if ( ft_strcmp( property_name, "flip_y" ) == 0 )
+ {
+ FT_Int val = *(const FT_Int*)value;
+
+
+ render->flip_y = val ? 1 : 0;
+ FT_TRACE7(( "[sdf] sdf_property_set: "
+ "updated property `flip_y' to %d\n", val ));
+ }
else
{
FT_TRACE0(( "[sdf] sdf_property_set: "
@@ -88,6 +106,20 @@
*val = render->spread;
}
+ else if ( ft_strcmp( property_name, "flip_sign" ) == 0 )
+ {
+ FT_Int* val = (FT_Int*)value;
+
+
+ *val = render->flip_sign;
+ }
+ else if ( ft_strcmp( property_name, "flip_y" ) == 0 )
+ {
+ FT_Int* val = (FT_Int*)value;
+
+
+ *val = render->flip_y;
+ }
else
{
FT_TRACE0(( "[sdf] sdf_property_get: "
@@ -131,7 +163,9 @@
SDF_Renderer sdf_render = SDF_RENDERER( render );
- sdf_render->spread = DEFAULT_SPREAD;
+ sdf_render->spread = DEFAULT_SPREAD;
+ sdf_render->flip_sign = 0;
+ sdf_render->flip_y = 0;
return FT_Err_Ok;
}
@@ -243,6 +277,8 @@
params.root.source = outline;
params.root.flags = FT_RASTER_FLAG_SDF;
params.spread = sdf_module->spread;
+ params.flip_sign = sdf_module->flip_sign;
+ params.flip_y = sdf_module->flip_y;
/* render the outline */
error = render->raster_render( render->raster, (const
FT_Raster_Params*)¶ms );
diff --git a/src/sdf/ftsdfrend.h b/src/sdf/ftsdfrend.h
index 47071a3..3f0f831 100644
--- a/src/sdf/ftsdfrend.h
+++ b/src/sdf/ftsdfrend.h
@@ -26,6 +26,8 @@ FT_BEGIN_HEADER
{
FT_RendererRec root;
FT_UInt spread;
+ FT_Bool flip_sign;
+ FT_Bool flip_y;
} SDF_Renderer_Module, *SDF_Renderer;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2] anuj-distance-field dd52766 55/93: [sdf] Added more properties.,
Anuj Verma <=