Commit Graph

70 Commits

Author SHA1 Message Date
Anuj Verma 41160c8be3 [sdf] Remove a unicode character. 2020-08-15 09:43:56 +05:30
Anuj Verma c3a5a07839 [sdf] Added a basic overview of the `sdf' rasterizer.
* src/sdf/ftsdf.c: Added the citation of the original paper
  and added a overview of the process for generating SDF
  from outlines.

* src/sdf/ftsdf.c (sdf_generate_subdivision): Added comment
  explaining how the optimization works.
2020-08-15 09:41:21 +05:30
Anuj Verma 0db5ba974d [sdf] Fix gcc compiler warnings.
* src/sdf/ftsdf.c, src/sdf/ftbsdf.c (*): Fix
  various compiler warnings, which were caused
  mainly due to unused variables and unused functions.
2020-08-14 09:14:15 +05:30
Anuj Verma e0a2a76b09 [sdf] Bug fix.
* src/sdf/ftsdf.c (sdf_generate_with_overlaps): The
  outside sign will always be 1. And added a missing
  `else'.
2020-08-13 09:05:50 +05:30
Anuj Verma d2796ed059 [sdf] Fix memory leaks.
* src/sdf/ftsdf.c (sdf_generate_with_overlaps): Deallocate
  the temporary bitmaps, and all the rest of the arrays.
  And also handle the `shape' appropriately so as to not
  cause memory leaks.
2020-08-12 17:21:40 +05:30
Anuj Verma b457aeee67 [sdf] Handle Post-Script fonts for overlap.
* src/sdf/ftsdf.c (sdf_generate_with_overlaps): Handle
  Handle Post-Script fonts for overlap support. Simply
  flip the orientation while combining all the separate
  SDF.
  Also, handle the `flip_sign' property separately so as
  to avoid handling extra cases.
2020-08-12 11:52:16 +05:30
Anuj Verma f644a47aae [sdf] Added overlap support (currently only for TrueType).
* src/sdf/ftsdfrend.h (SDF_Renderer_Module): Removed the
  expermental `optimization' property.
  Added another property `overlaps', which can be used to
  turn on the overlap support.

* src/sdf/ftsdf.h (SDF_Raster_Params): Ditto as above.

* src/sdf/ftsdfrend.c (*): Added functionality to set
  and get the new `overlaps' property.

* src/sdf/ftsdf.c (sdf_raster_render):
  Removed support for all the optimization modes and
  only keep the subdivision optimization and the new
  overlap support function.

* src/sdf/ftsdf.c (sdf_generate_coarse_grid): Turned
  off until we can find a way to make it faster.

* src/sdf/ftsdf.c (sdf_generate_with_overlaps): Added
  a function to generate SDF for shapes with overlapping
  contours. It basically generate SDF for separate contours
  in seperate bitmaps and then combine them to remove
  overlaps.
2020-08-12 10:14:35 +05:30
Anuj Verma 307b0cbd6f [sdf, bsdf] Added better documentation.
* src/sdf/ftsdf.c, src/sdf/ftbsdf.c (*): Added documentation
  of the structs and enums for both the renderers.
2020-08-07 16:47:50 +05:30
Anuj Verma 06bbff76b9 [sdf] Added function to get contour orientation.
* src/sdf/ftsdf.c (SDF_Contour_Orientation): Added
  enum to hold the different orientations of a contour.

* src/sdf/ftsdf.c (get_contour_orientation): Added
  function which can be used to compute the orientation
  of a contour.

* src/sdf/ftbsdf.c (*): Remove completed `[TODO]'s.
2020-08-06 11:42:26 +05:30
Anuj Verma bada3e4162 [sdf] Added documentation for function of the `sdf' renderer.
* src/sdf/ftsdf.c (*): Added function documentation for
  function of the `sdf' renderer, and fixed grammar at a
  few places.
2020-08-06 07:50:57 +05:30
Anuj Verma a62fd640f3 [sdf -> bsdf] Added option to use squared distances.
* src/sdf/ftbsdf.c (bsdf_is_edge): Modified the function
  to use distance map rather than the alpha values from
  the source image.

* src/sdf/ftbsdf.c (bsdf_approximate_edge): Only calculate
  approximate edges for edge pixels. Use `bsdf_is_edge' is
  to check for edge pixels. For non edge pixel assgn far
  away distances.

* src/sdf/ftbsdf.c (finalize_sdf): Handle distances in case
  of squared distances.
  And also use the macro `VECTOR_LENGTH_16D16' in the entire
  code to compute vector length. This takes care of squared
  distances.

* src/sdf/ftsdfcommon.c (VECTOR_LENGTH_16D16): Move the macro
  `VECTOR_LENGTH_16D16' from `ftsdf.c' to this file because
  it is also used by the `bsdf' renderer.
2020-08-02 16:33:21 +05:30
Anuj Verma f2553d89b2 [sdf,bsdf] Put common propertied and functions in one file.
* src/sdf/ftsdfcommon.h: Added new file which contains
  common function, macros, properties for both `sdf' and
  `bsdf' renderer.

* src/sdf/ftsdf.c, src/sdf/ftsdf.h, src/sdf/ftbsdf.c:
  Remove common properties and include `ftsdfcommon.h'.

* src/sdf/rules.mk (SDF_DRV_H): Add the new `ftsdfcommon.h'
  file to include list.
2020-08-02 16:33:21 +05:30
Anuj Verma ddfa07c5da [sdf] Add alloc/free functions.
* src/sdf/ftsdf.c (*): Add `sdf_alloc' and `sdf_free'
  to allocate and deallocate memory respectively.
  By using function we can directly use them in the
  conditional statements, which is not possible when
  using `do {} while ( 0 )'.

* src/sdf/ftsdf.c (SDF_MEMORY_TRACKER_): When not
  debugging don't leave the macros empty otherwise
  some compiler may emit warning because of empty
  `;' semi-colon.
2020-08-02 16:33:20 +05:30
Anuj Verma e78016b46d [sdf] Only track memory in debug mode.
* src/sdf/ftsdf.c (*): Disable total memory
  usage tracking if the program is not in
  debug mode.
2020-08-02 16:33:20 +05:30
Anuj Verma c09257f0dd [sdfb] Removed Module.
Remove sdfb module. Instead of a new module
simply create a new renderer in the `sdf'
module for converting bitmaps to SDF.
2020-08-02 16:33:20 +05:30
Anuj Verma f4918e139c Revert "[sdfb] Fix GNU Make build."
This reverts commit 0d9179f4e8cdb02986f5d01f178364e3f2b8dc07.
2020-08-02 16:33:20 +05:30
Anuj Verma fca2ed969c [sdfb] Fix GNU Make build.
* src/sdfb/rules.mk (SDFB_DRV_H): Fix name of
  the module specific error file `ftsdfberrs.h'.

* src/sdf/ftsdf.h (Optimizations): Fix warning.
  `warning: comma at end of enumerator list [-Wpedantic]'

* src/sdf/ftsdf.c (sdf_generate_coarse_grid): Remove
  unused variable `cindex', causes warning.
  `warning: unused variable 'cindex' [-Wunused-variable]'
2020-08-02 16:33:20 +05:30
Anuj Verma 968a2f6237 [sdf] Added memory tracker.
* src/sdf/ftsdf.c (SDF_MemoryUser): Added struct
  which is used in place of `FT_Memory::user'.

* src/sdf/ftsdf.c (SDF_ALLOC, SDF_FREE): Added macros
  for allocating and deallocating memory. These macros
  restore the old `FT_Memory::user' before calling the
  relevant allocation/deallocation functions so as to
  not cause errors while debugging memory. And later
  they add the allocated memory size in a variable.

* src/sdf/ftsdf.c (*): Use `SDF_ALLOC', `SDF_FREE'
  instead of the `FT_' variant.
2020-08-02 16:33:19 +05:30
Anuj Verma dfdbc34108 Revert "[sdf] Added total memory allocation log."
This reverts commit d97e060891af0cc59af6fefa84484bec0d1794a4.
2020-08-02 16:33:19 +05:30
Anuj Verma 531d51eb2a [sdf] Added total memory allocation log.
* src/sdf/ftsdf.c (*): Replaced `FT_QNEW' and `FT_ALLOC_MULT'
  to custom macros in order to track memory allocations
  throughout the process of generating SDF. It basically
  add the memory being allocated to a static global variable
  and at the end outputs it at the end.
2020-08-02 16:33:19 +05:30
Anuj Verma d40fc55dad [sdf] Temporary change.
Added new property to dynamically change the
optimization to be used to generate the SDF.
This can be used to compare the performance of
different optimization techniques without going
and recompiling the program.
And will also be used in the demo to check the
performance.
2020-08-02 16:33:19 +05:30
Anuj Verma dd5276601c [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-08-02 16:33:19 +05:30
Anuj Verma 6b03b1c57a [sdf] Check for left or right fill.
* src/sdf/ftsdf.c (SDF_Params): Added struct which
  contains some internal data required by the rater-
  izer (such as left/right fill).

* src/sdf/ftsdf.c (sdf_raster_render): Determine the
  fill side and pass it to the `sdf_generate_' funcs.

* src/sdf/ftsdf.c (sdf_generate_): Use the new `SDF_Params'
  to generate SDF accordingly.
2020-08-02 16:33:19 +05:30
Anuj Verma 548bd3cf62 [sdf] Optimize the coarse grid optimization.
* src/sdf/ftsdf.c (sdf_generate_coarse_grid): Merge
  the relevant edge finding loop and shortest dist-
  ance search loop. We can find the relevant edges
  of a coarse grid and immediately use them to find
  the shortest distance of the points in the coarse
  grid. This drastically reduce memory usage and 
  performance.
  Also, do the sign assignment of the edges which was
  missing.
2020-08-02 16:33:19 +05:30
Anuj Verma ad696c07d3 * src/sdf/ftsdf.c (*): Fixed warnings.
Fixed various warnings and other few errors.
2020-08-02 16:33:19 +05:30
Anuj Verma 2045c7d9b3 * src/sdf/ftsdf.c (sdf_generate_coarse_grid): Comments.
Add more comments explaining the step by step
process of using coarse grid to increase the
performance of nearest distance search.
2020-08-02 16:33:19 +05:30
Anuj Verma 2afa0cb369 * src/sdf/ftsdf.c (sdf_generate_coarse_grid): Memory leak.
Release the allocated lists for the coarse grid after
we are done using them.
2020-08-02 16:33:19 +05:30
Anuj Verma 80c5bed575 [sdf] Completed the coarse grid optimization.
* src/sdf/ftsdf.c (sdf_generate_coarse_grid): Fixed
  an issue with position calculation and upside down
  images.
2020-08-02 16:33:19 +05:30
Anuj Verma 992609a1db [sdf] Partially completed the coarse grid optimization.
* src/sdf/ftsdf.c (sdf_generate_coarse_grid): Added
  functionality to check distances of all edges from
  the coarse grid and add the relevant edges to the 
  list.
  [Note]: The function is not complete yet.
2020-08-02 16:33:19 +05:30
Anuj Verma 111b755128 [sdf] Added the coarse grid optimization function.
* src/sdf/ftsdf.c (sdf_generate_coarse_grid): The
  function uses coarse grid to optimize nearest edge
  search performance.
2020-08-02 16:33:19 +05:30
Anuj Verma d9eeac807e [sdf] Remove use of `FT_List'.
Simply use a `next' pointer inside `SDF_Edge' and
`SDF_Contour' to create a linked list. This reduces
the number of allocations due to `FT_ListNode', also
we don't need a doubly linked list.

* src/sdf/ftsdf.c (SDF_Edge, SDF_Contour): Remove the
  `FT_List' and use a `next' pointer to create the
  linked list.

* src/sdf/ftsdf.c(sdf_edge_destructor, sdf_contour_destructor):
  Removed, not needed any more.

* src/sdf/ftsdf.c (*): Remove the use of `FT_List_'
  functions wherever necessary and sync with the new
  list.
2020-08-02 16:33:19 +05:30
Anuj Verma 8bf9da21e0 [sdf] Added subdivision optimization.
* src/sdf/ftsdfrend.c (sdf_generate_subdivision): The
  function generate SDF just like the `sdf_generate'
  function, but subdivide the curve into a number of
  lines and then use the `sdf_generate_bounding_box'
  function to generate SDF.
2020-08-02 16:33:19 +05:30
Anuj Verma fa7251ba35 [sdf] Added functions to subdivide a cubic curve.
* src/sdf/ftsdf.c (split_cubic, split_sdf_cubic):
  These functions can be used to subdivide a
  cubic bezier curve into line segments which can
  then be used to generate the SDF.

* src/sdf/ftsdf.c (split_sdf_shape): Added function
  to split a cubic into a line segments.

* src/sdf/ftsdf.c (sdf_shape_done): No need to pass
  `FT_Memory' as a parameter, it can be accessed
  from the `shape' struct.
2020-08-02 16:33:19 +05:30
Anuj Verma 1ba3da86e1 * src/sdf/ftsdf.c (split_sdf_shape): Typo. 2020-08-02 16:33:18 +05:30
Anuj Verma 90abe41ead * src/sdf/ftsdf.c (split_sdf_shape): Memory leak.
* src/sdf/ftsdf.c (split_sdf_shape): Memory leak.
  After recursion the edges variable becomes `NULL'
  so reassign it to deallocate the list completely.
2020-08-02 16:33:18 +05:30
Anuj Verma 470d02aa60 [sdf] Added functions to subdivide a conic curve.
* src/sdf/ftsdf.c (split_conic, split_sdf_conic):
  These functions can be used to subdivide a
  conic bezier curve into line segments which can
  then be used to generate the SDF.

* src/sdf/ftsdf.c (split_sdf_shape): Added function
  to split a outline into a line segments.
2020-08-02 16:33:18 +05:30
Anuj Verma c4f64fc0e1 * src/sdf/ftsdfrend.c (sdf_generate_bounding_box): Add buffer for signs. 2020-08-02 16:33:18 +05:30
Anuj Verma e6576cc0e7 [sdf] Precompute the orthogonality. 2020-08-02 16:33:18 +05:30
Anuj Verma 1e3c41d19e [sdf] Added bounding box optimization. 2020-08-02 16:33:18 +05:30
preversewharf45 1d5d8ff288 * src/sdf/ftsdfrend.c (sdf_shape_dump): Use `%ld' to printf `signed long'. 2020-08-02 16:33:18 +05:30
Anuj Verma 4fcc1653ca * src/sdf/ftsdf.c: Use ASCII single quote ('). 2020-08-02 16:33:18 +05:30
Anuj Verma ddf631729e [sdf] Added function to find shortest distance from a point to a cubic. 2020-08-02 16:33:18 +05:30
Anuj Verma 5baa2cefc6 * src/sdf/ftsdf.c (sdf_contour_get_min_distance): Use epsilon. 2020-08-02 16:33:18 +05:30
Anuj Verma 76e67227ec * src/sdf/ftsdf.c (sdf_shape_dump): Add more info to the debug output. 2020-08-02 16:33:18 +05:30
Anuj Verma 3e52d1a7a8 * src/sdf/ftsdf.c (MAX_NEWTON_DIVISIONS): Renamed to avoid confusion. 2020-08-02 16:33:18 +05:30
Anuj Verma 363f1e8de1 [sdf] Added Newton's method for conic curve. 2020-08-02 16:33:17 +05:30
Anuj Verma be3b7d7945 * src/sdf/ftsdf.c: More comments and code style fix. 2020-08-02 16:33:17 +05:30
Anuj Verma d0e3074738 [sdf] Make squared distances toggleable. 2020-08-02 16:33:17 +05:30
Anuj Verma 97474a7072 * src/sdf/ftsdf.c (get_min_distance_conic): Use 0, 1 in case of 0 roots. 2020-08-02 16:33:17 +05:30
Anuj Verma f9b4f37433 [sdf] Added function to find shortest distance from a point to a conic. 2020-08-02 16:33:17 +05:30