Commit Graph

61 Commits

Author SHA1 Message Date
Werner Lemberg 2848378be5 s/fixed point/fixed-point/ 2022-06-21 17:08:04 +02:00
Anuj Verma 7b3ebb9c12 [sdf] Do not throw errors for invisible glyphs.
* src/sdf/ftsdfrend.c (ft_sdf_render, ft_bsdf_render): Return `FT_Err_Ok` if
width or height is zero, since some glyphs do not generate visible bitmaps.

Fixes #1150.
2022-04-30 19:38:11 +02:00
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
Alexei Podtelezhnikov ba5d661f34 * src/sdf/ftbsdf.c (ED): s/near/prox/.
This works around the Watcom C definition of `near` as restricted
__near.
2022-01-14 21:54:17 -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 be6ab31900 [sdf] Fix out-of-range-access.
* src/sdf/ftbsdf.c (first_pass, second_pass): Fix range during forward pass.
Otherwise the index goes out of range for the last column.

Fixes issue #1077.
2021-08-02 06:49:50 +02:00
Anuj Verma ebcc96e559 Fix invalid memory access in `bsdf` rasterizer.
Do not generate SDF from bitmap if the `FT_GLYPH_OWN_BITMAP` flag is not
set.  In some cases the bitmap buffer is freed but still points to a valid
address; to handle those cases check the flag before accessing the memory.

* src/sdf/ftsdfrend.c (ft_bsdf_render): Handle the above case.
Also, return an error message if the bitmap's rows/pitch is invalid,
otherwise `slot->buffer` might be assigned to some invalid memory location.
(ft_sdf_render): Same as above.
Plus, move the outline back to original state after rasterization and not if
any error occurs.

Signed-off-by: Anuj Verma <anujv@iitbhilai.ac.in>
2021-08-02 05:51:15 +02:00
Anuj Verma e592982a83 [sdf] Improve documentation. 2021-07-13 10:00:22 +02:00
Werner Lemberg 90ecac4118 Update `CHANGES` file; other minor doc fixes. 2021-06-30 10:23:42 +02:00
Alexei Podtelezhnikov 61bac75963 * src/sdf/ftsdfrend.c (ft_(b)sdf_render): Do not FT_ERROR routinely. 2021-06-18 17:38:00 -04: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 41fa19fcea * src/sdf/ftsdfcommon.c: Fix inclusion of header files. 2021-06-08 10:32:20 +02: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 286e9e0d72 [sdf] Two more copyright notices. 2020-12-24 08:41:12 +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 6cd6df55c9 [sdf] Add 'bsdf' renderer to 'sdf' module.
* src/sdf/ftsdfrend.c (ft_bsdf_render): New function.

(ft_bitmap_sdf_renderer_class): New structure.
2020-12-24 07:23:48 +01:00
Anuj Verma d27d107f15 [sdf] Add interface functions for the 'bsdf' rasterizer.
* src/sdf/ftsdf.c (bsdf_raster_new, bsdf_raster_reset,
bsdf_raster_set_mode, bsdf_raster_render, bsdf_raster_done): New
functions.

(ft_bitmap_sdf_raster): New variable.

* src/sdf/ftsdf.h: Updated.
2020-12-24 07:23:48 +01:00
Anuj Verma a21134751c [sdf] Add function to copy SDF data into output bitmap.
* src/sdf/ftbsdf.c (finalize_sdf): New function.
2020-12-24 07:23:48 +01:00
Anuj Verma e2ae96b978 [sdf] Add '8-point sequential Euclidean distance mapping' algorithm.
* src/sdf/ftbsdf.c (compare_neighbor, first_pass, second_pass,
edt8): New functions.
2020-12-24 07:23:48 +01:00
Anuj Verma 6b9a8044be [sdf] Add function to copy source bitmap to distance map.
* src/sdf/ftbsdf.c (bsdf_init_distance_map): New function.
2020-12-24 07:23:48 +01:00
Anuj Verma 0f644f38e9 [sdf] Add functions to compute pixel edge distances.
* src/sdf/ftbsdf.c (compute_edge_distance, bsdf_approximate_edge):
New functions.
2020-12-24 07:23:48 +01:00
Anuj Verma c576176461 [sdf] Add function to find edge pixels in a grid of alpha values.
* src/sdf/ftbsdf.c (bsdf_is_edge): New function.
2020-12-24 07:23:48 +01:00
Anuj Verma 9bbb3611b3 [sdf] Add essential structures for the 'bsdf' rasterizer.
* src/sdf/ftbsdf.c (ONE): New macro.
(BSDF_TRaster, ED, BSDF_Worker): New structures.
(zero_ed): New constant.
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 879ca87f0b [sdf] Add build infrastructure.
* src/sdf/module.mk, src/sfd/rules.mk: New files.

* src/sdf/ftsdf.h (ft_sdf_raster): New forward declaration.

* include/freetype/ftmoderr.h (FT_MODERRDEF): Add error definition
for the 'sdf' module.

* include/freetype/internal/fttrace.h (FT_TRACE_DEF): Add trace
definition for the `sdf' module.

* modules.cfg (RASTER_MODULES): Add the `sdf' module to the list of
rasterizers.
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