Commit Graph

40 Commits

Author SHA1 Message Date
Werner Lemberg 695d606ae5 Whitespace. 2022-04-01 08:50:33 +02:00
Werner Lemberg 87989a1435 Fix clang++ warnings.
* src/base/ftglyph.c (ft_svg_glyph_prepare), src/base/ftobj.c
(ft_glyphslot_init), src/cache/ftccmap.c (ftc_cmap_node_new),
src/cache/ftcimage.c (FTC_INode_New), src/lzw/ftlzw.c (FT_Stream_OpenLZW),
src/psaux/psobjs.c (ps_parser_load_field), src/pshinter/pshglob.c
(psh_globals_new), src/sfnt/ttsvg.c (tt_face_load_svg_doc): Initialize
variables used for allocation.

* src/sdf/ftsdf.c (split_sdf_conic, split_sdf_cubic): Change type of
`max_splits` to FT_UInt.
(sdf_generate_bounding_box): Add cast.
2022-03-31 07:49:35 +02:00
Anuj Verma 360e2507a3 [sdf] Fix corner checks and improve performance.
* src/sdf/ftsdf.c (sdf_generate_bounding_box): Always check for a corner if
two distances (for different curves) are very close.

(sdf_conic_to): Check whether the conic curve can be treated as a line
(which happens if the control point coincides with any end point).
2022-03-05 17:00:10 +01:00
Anuj Verma 2600ef637e [sdf] Implement deviation-based splitting for Bezier curves.
* src/sdf/ftsdf.c (split_sdf_cubic, split_sdf_shape): Add checks to figure
out the deviation of Bezier curves and stop splitting if the curve is flat
enough.

* src/sdf/ftsdfcommon.h (ONE_PIXEL): New macro.
2022-03-05 16:53:45 +01:00
Anuj Verma ab1c98ac18 Fix sdf computation while `USE_SQUARED_DISTANCES`.
Function `map_fixed_to_sdf` expects spread to be absolute
and not squared.

* src/sdf/ftbsdf.c (finalize_sdf): Pass absolute spread
while `map_fixed_to_sdf`.

* src/sdf/ftsdf.c (sdf_generate_bounding_box): Ditto.
2022-01-27 18:01:08 +05:30
Alexei Podtelezhnikov 0ac535900b * src/sdf/ftsdf.c (sdf_*_new): Use standard macro. 2022-01-26 14:02:27 -05:00
Werner Lemberg d0cfb4e1b2 Update all copyright notices. 2022-01-11 10:54:10 +01:00
Alexander Borsuk 4f35711844 Clang-Tidy warning fixes.
* src/base/ftobjs.c (FT_Get_Paint): Operator has equivalent nested operands.
* src/bdf/bdflib.c (_bdf_add_property): Value stored to `fp` is never read.
* src/sdf/ftbsdf.c (bsdf_init_distance_map): Value stored to `pixel` is
never read.
* src/sdf/ftsdf.c (split_sdf_shape): Value stored to `error` is never read.
2021-12-18 11:09:15 +01:00
Werner Lemberg 238245cd66 Fix clang++ warnings.
* src/*: Initialize some variables to NULL.
2021-11-16 22:08:47 +01:00
Alexei Podtelezhnikov 7f8f0c1c70 [smooth, raster, sdf] Clean up initialization calls.
* src/raster/ftraster.c (ft_black_init): Removed.
(ft_black_new): Clean up.
* src/sdf/ftbsdf.c (bsdf_raster_new): Ditto.
* src/sdf/ftsdf.c (sdf_raster_new): Ditto.
* src/smooth/ftgrays.c (gray_raster_new): Ditto.
2021-09-02 23:30:31 -04:00
Werner Lemberg f44c2d5860 * src/sdf/ftsdf.c (get_control_box): Fix compiler warning. 2021-08-18 08:52:21 +02:00
Anuj Verma e592982a83 [sdf] Improve documentation. 2021-07-13 10:00:22 +02:00
Alexei Podtelezhnikov 7833e308ef [sdf] Fix SDF positioning.
* src/sdf/ftsdfrend.c (ft_sdf_render, ft_bsdf_render): Add padding to
`bitmap_top' and `bitmap_left'.

* sdf/sdf/ftsdf.c (sdf_generate_with_overlaps): Fix VC++ warning.
2021-06-09 10:40:30 -04:00
Werner Lemberg 35b21c71e5 [sdf] Make `make multi` work.
* src/sdf/ftsdf.c: Include `ftbitmap.h`.

* src/sdf/ftsdfcommon.h: Move function bodies to `ftsdfcommon.c`.
Include `ftobjs.h` to get definitions of `FT_LOCAL` and friends.

* src/sdf/ftsdfcommon.c: New file.

* src/sdf/rules.mk, src/sdf/sdf.c: Updated.
2021-06-08 09:06:39 +02:00
Werner Lemberg 36ee71714f [sdf] Formatting and improved comments. 2021-06-08 09:00:39 +02:00
Anuj Verma 2b1d556269 [sdf] Use 8 bits for final SDF output instead of 16bits.
Since 8-bits is enough to represent SDF data we no longer require
16-bits for  this purpose. Also, we now normalize the output data
to use the entire 8-bit range efficiently. For example: if we use
3.5 format with a spread of 1 we basically only use the starting
5-bits. By normalizing we can use the entire 8-bit range.

* include/freetype/freetype.h (FT_Render_Mode): Updated description
for `FT_RENDER_MODE_SDF` regarding this change.

* include/freetype/ftimage.h (FT_Pixel_Mode): Removed
`FT_PIXEL_MODE_GRAY16` since no longer required.

* include/freetype/fttypes.h (FT_F6Dot10): Removed since no longer
required.

* src/sdf/ftsdfrend.c (ft_sdf_render, ft_bsdf_render): Allocate 8-bit
bitmap instead of 16-bit buffer.

* src/sdf/ftsdfcommon.h (map_fixed_to_sdf): Added function to convert
16.16 distance value to our desired format.

* src/sdf/ftsdf.c (sdf_generate_with_overlaps,
sdf_generate_bounding_box): Use the new `map_fixed_to_sdf` function
and also use 8-bit output buffer.

* src/sdf/ftbsdf.c (finalize_sdf): Output to a 8-bit buffer instead
of 16-bit buffer.
2021-06-08 08:29:34 +05:30
Werner Lemberg 6e253b26b2 Typos in previous commit. 2021-05-29 11:07:10 +02:00
Werner Lemberg a50c39aa8e Fix compilation errors and (some) warnings for clang++.
* src/autofit/afmodule.c (AF_GlyphHintsRec): Make it static.

* src/cache/ftcache.c (FTC_Cache_NewNode), src/cache/ftcsbits.c
(ftc_snode_compare): Remove semicolon.

* src/cff/cffparse.c (cff_parser_run): Add `break` statement.

* src/cid/cidload.c (cid_hex_to_binary): Add cast.

* src/sdf/ftbsdf.c (CHECK_NEIGHBOR): Use `do {} while(0)` loop.
(bsdf_init_distance_map, finalize_sdf, bsdf_raster_render): Add
casts.
* src/sdf/ftsdf.c (sdf_generate_bounding_box,
sdf_generate_with_overlaps): Ditto.
* src/sdf/ftsdfcommon.h (square_root): Ditto.
* src/sdf/ftsdfrend.c (sdf_property_get, ft_sdf_render,
ft_bsdf_render): Ditto.

* src/sfnt/ttcolr.c (find_base_glyph_record,
find_base_glyph_v1_record): Fix variable signedness.
(read_color_line): Add cast.
(read_paint): Add casts.
Fix signedness issue.
(tt_face_get_colorline_stops) Fix signedness issues.

* src/sfnt/ttpost.c (load_format_20): Add casts.

* src/truetype/ttsubpix.c (TWEAK_RULES, TWEAK_RULES_EXCEPTIONS):
Remove final semicolons.
2021-05-29 09:51:04 +02:00
Alexei Podtelezhnikov e6e5b67db3 * src/sdf/ftsdf.c (sdf_{edge,contour,shape}_new): Use FT_QALLOC. 2021-04-23 21:33:03 -04:00
Werner Lemberg 2149b51f25 Handle various VC++ compiler warnings.
Fixes #1039.

* src/base/ftstroke.c (ft_stroker_inside, ft_stroker_outside):
Initialize `sigma`.

* src/sdf/ftsdf.c (sdf_generate_with_overlaps): Exit immediately if
function arguments are invalid.
* src/sdf/ftsdfrend.c (sdf_property_set) <"overlaps">: Fix cast.

* src/sfnt/sfwoff2.c (woff2_decompress)
[!FT_CONFIG_OPTION_USE_BROTLI]: Use `FT_UNUSED`.

* src/truetype/ttgxvar.c (TT_Get_MM_Var): Initialize `fvar_head`.
2021-03-13 19:08:09 +01:00
Werner Lemberg b6e8a71266 Update all copyright notices. 2021-01-17 07:18:48 +01:00
Werner Lemberg c6ff2556c8 [sdf] Use 'counter-clockwise', not 'anti-clockwise'.
We prefer US nomenclature.

* src/sdf/ftsdf.c (SDF_Contour_Orientation):
s/SDF_ORIENTATION-ACW/SDF_ORIENTATION_CCW/.
Update all users.
2020-12-26 10:50:21 +01:00
Anuj Verma 10a5dfec7f [sdf] Remove custom memory tracker.
The internal FreeType memory tracker is sufficient.

* src/sdf/ftsdf.c (FT_DEBUG_INNER, FT_ASSIGNP_INNER, SDF_MemoryUser,
sdf_alloc, sdf_free, SDF_ALLOC, SDF_FREE,
SDF_MEMORY_TRACKER_DECLARE, SDF_MEMORY_TRACKER_SETUP,
SDF_MEMORY_TRACKER_DONE): Removed.

s/SDF_ALLOC/FT_ALLOC/.
s/SDF_FREE/FT_FREE/.

Other updates.
2020-12-26 08:34:38 +01:00
Werner Lemberg 3c983eb84a [sdf] Fix `make multi`.
* src/sdf/ftsdf.c: Include `ftoutln.h`.
2020-12-24 08:36:09 +01:00
Werner Lemberg aa1b5362d3 [sdf] Fix tracing.
* include/freetype/internal.fttrace.h: Add 'bsdf' component.

* src/sdf/ftbsdf.c, src/sdf/ftsdf.c (FT_COMPONENT): Define.
2020-12-24 08:32:04 +01:00
Werner Lemberg 04a6443254 [sdf] Add copyright notices. 2020-12-24 08:29:05 +01:00
Anuj Verma b298a64464 [sdf] Add debugging function.
* src/sdf/ftsdf.c (sdf_shape_dump): New function.
2020-12-24 07:23:48 +01:00
Anuj Verma 6444875f68 [sdf] Add brief technical overview of both rasterizers. 2020-12-24 07:23:48 +01:00
Anuj Verma 05f6088df3 [sdf] Added basic overlapping contour support.
* src/sdf/ftsdf.c (sdf_generate_with_overlaps): New function.
(sdf_raster_render): Enable it.
2020-12-24 07:23:48 +01:00
Anuj Verma 665ac96792 [sdf] Add interface functions for the 'sdf' rasterizer.
* src/sdf/ftsdf.c (sdf_raster_new, sdf_raster_reset,
sdf_raster_set_mode, sdf_raster_render, sdf_raster_done): New
functions.
(ft_sdf_raster): New structure.
2020-12-24 07:23:48 +01:00
Anuj Verma 1010f2c39c [sdf] Add subdivision and bounding box optimization.
* src/sdf/ftsdf.c (sdf_generate_bounding_box): New function, which
is an optimized version of `sdf_generate`.
(sdf_generate_subdivision): New function.
2020-12-24 07:23:48 +01:00
Anuj Verma 986d3108ac [sdf] Add function to generate SDF.
* src/sdf/ftsdf.c (sdf_generate): New function, currently disabled.
This is a proof-of-concept implementation: It doesn't use any
optimization, it simply checks all grid points against all contours.
2020-12-24 07:23:48 +01:00
Anuj Verma 0d52f4ae0a [sdf] Add functions to get shortest distance from any edge/contour.
* src/sdf/ftsdf.c (sdf_edge_get_min_distance): New function.
(sdf_contour_get_min_distance): New function, currently disabled.
2020-12-24 07:23:48 +01:00
Anuj Verma 81e32986ca [sdf] Add shortest distance finding functions.
* src/sdf/ftsdf.c (get_min_distance_line, get_min_distance_conic,
get_min_distance_cubic): New functions.  Note that
`get_min_distance_conic` comes with two implementations (using an
analytical and an iterative method, to be controlled with the
`USE_NEWTON_FOR_CONIC` macro).
2020-12-24 07:23:48 +01:00
Anuj Verma c918b54f25 [sdf] Add function to resolve corner distances.
* src/sdf/ftsdf.c (resolve_corner): New function.
2020-12-24 07:23:48 +01:00
Anuj Verma a255125fe4 [sdf] Add essential math functions.
* src/sdf/ftsdf.c (cube_root, arc_cos) [!USE_NEWTON_FOR_CONIC]: New
auxiliary functions.

* src/sdf/ftsdf.c (solve_quadratic_equation, solve_cubic_equation)
[!USE_NEWTON_FOR_CONIC]: New functions.
2020-12-24 07:23:48 +01:00
Anuj Verma cd4138458a [sdf] Add utility functions for contours.
* src/sdf/ftsdf.c (get_control_box, get_contour_orientation): New
functions.
(split_conic, split_cubic, split_sdf_conic, split_sdf_cubic,
split_sdf_shape): New functions.
2020-12-24 07:23:47 +01:00
Anuj Verma 2de1b5630d [sdf] Add functions to decompose `FT_Outline`.
* src/sdf/ftsdf.c (sdf_move_to, sdf_line_to, sdf_conic_to,
sdf_cubic_to): New auxiliary decomposition functions.
(sdf_compose_funcs): New structure.
(sdf_outline_decompose): New function.
2020-12-24 07:23:47 +01:00
Anuj Verma cf0464d855 [sdf] Structs, enums, macros, and functions for 'sdf' rasterizer.
* src/sdf/ftsdf.c (FT_DEBUG_INNER, FT_ASSIGNP_INNER)
[FT_DEBUG_LEVEL_TRACE && FT_DEBUG_MEMORY]: New macros.
(SDF_MemoryUser) [FT_DEBUG_LEVEL_TRACE && FT_DEBUG_MEMORY]: New
struct for memory usage tracing.
(sdf_alloc, sdf_free) [FT_DEBUG_LEVEL_TRACE && FT_DEBUG_MEMORY]: New
functions for memory usage tracing.

(SDF_ALLOC, SDF_FREE): New macros for memory management.
(SDF_MEMORY_TRACKER_DECLARE, SDF_MEMORY_TRACKER_SETUP,
SDF_MEMORY_TRACKER_DONE): New macros to set up memory usage tracing.

(USE_NEWTON_FOR_CONIC, MAX_NEWTON_DIVISIONS, MAX_NEWTON_STEPS,
CORNER_CHECK_EPSILON, CG_DIMEN): New configuration macros for
controlling the process of finding the shortest distance.

(MUL_26D6, VEC_26D6_DOT): New auxiliary macros.

(SDF_TRaster, SDF_Edge, SDF_Contour, SDF_Shape, SDF_Signed_Distance,
SDF_Params): New structs for setting up SDF data.
(SDF_Edge_Type, SDF_Contour_Orientation): New enums for SDF data.

(zero_vector, null_edge, null_contour, null_shape, max_sdf): Useful
constants.

(sdf_edge_new, sdf_edge_done, sdf_contour_new, sdf_contour_done,
sdf_shape_new, sdf_shape_done): New constructors and destructors.
2020-12-24 07:23:47 +01:00
Anuj Verma cd6ff28a17 [sdf] Add files for new 'sdf' module.
Here is a breakdown of what the files will contain.

* src/sdf/ftsdfrend.c, src/sdf/ftsdfrend.h: The 'sdf' and 'bsdf'
renderers.

* src/sdf/ftsdf.c, src/sdf/ftsdf.h: The rasterizer for the 'sdf'
renderer.
* src/sdf/ftbsdf.c, src/sdf/ftbsdf.h: The rasterizer for the 'bsdf'
renderer.

* src/sdf/ftsdfcommon.h: Commmon properties and functions for both
rasterizers.
* src/sdf/ftsdferrs.h: Common error defines.

* src/sdf/sdf.c: For building a single object of the entire module.
2020-12-24 07:23:47 +01:00