Commit Graph

6912 Commits

Author SHA1 Message Date
Anuj Verma 64d1c20fec [sdf -> bsdf] Added a basic overview of the `bsdf' rasterizer.
* src/sdf/ftbsdf.c: Added the citation of the original paper
  and added a overview of the process for generating SDF
  from bitmaps.
2020-08-15 16:56:50 +05:30
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 398cae8398 [base] Fix memory leaks due to FreeType internals.
* src/base/ftobjs.c (ft_remove_renderer): Similar to
  `ft_add_renderer', remover raster's `glyph_format'
  check. Due to this the rasterizers which do not have
  `glyph_format' of `FT_GLYPH_FORMAT_OUTLINE' won't get
  deallocated (the `raster_done' function is no called).
2020-08-12 17:27:29 +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 5014394b3e [sdf -> bsdf] Added documentation for functions of the `bsdf' renderer.
* src/sdf/ftbsdf.c (*) Added function documentation for
  function of the `bsdf' renderer.
2020-08-06 08:59:33 +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 45398811c7 [sdf] Added documentation for some structs.
* src/sdf/ftsdfrend.h
      .../ftsdfrend.c
      .../ftsdfcommon.h
      .../ftsdf.h
  : Added documentation for a few structs.
2020-08-05 17:55:02 +05:30
Anuj Verma a9fbef27ab [sdf -> bsdf] Extended to work with monochrome bitmaps.
* src/sdf/ftbsdf.c (bsdf_init_distance_map): Handle
  monochrome bitmaps and convert them to the internal
  intermediate format, which can then be used to
  generate SDF.
2020-08-05 09:12:29 +05:30
Anuj Verma ee9b8e8cc0 * src/sdf/ftsdfrend.c (ft_bsdf_render): Initialize variable.
Initialize the target bitmap so as to avoid crashes due
to uninitialized memory.
2020-08-03 16:19:21 +05:30
Anuj Verma 95846825f6 [sdf -> bsdf] Fixed memory leak.
* src/sdf/ftbsdf.c (bsdf_raster_render): Release the
  allocated distance map.
  Also, added a log of total memory allocated for
  generating SDF from bitmap.
2020-08-03 09:13:53 +05:30
Anuj Verma d7a2e99bb0 [sdf -> bsdf] Fixed a bug with `finalize_sdf'.
* src/sdf/ftbsdf.c (finalize_sdf): First check if the
  value is withing [-spread, spread] and then cast it
  to 6.10 short, otherwise the value can overflow and
  give negative result.
  Also, flip the sign if the property `flip_sign' is
  set to true.
2020-08-02 16:33:22 +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 436f091db1 * src/sdf/ftbsdf.c (compare_neighbor): Fix bug. 2020-08-02 16:33:21 +05:30
Anuj Verma 903d28725a Fix line endings and typo. 2020-08-02 16:33:21 +05:30
Anuj Verma 77ce541e10 [sdf -> bsdf] Optimized a bit.
* src/sdf/ftbsdf.c (ED: sign => alpha): Renamed sign
  to alphs. This is used to store the alpha of the current
  pixel mapped to the source image. This let's us store
  additional information without increasing memory usage.

* src/sdf/ftbsdf.c (bsdf_init_distance_map): Removed any/all
  kind of edge approximation and edge check from the function.
  The function simply copy the source bitmap to the distance
  map now, preserving alpha values.

* src/sdf/ftbsdf.c (compute_edge_distance): Use the new `alpha'
  parameter to compute gradient and approximate distance.
  Previously we were using the `dist' variable to store alpha
  values, which restricts modifying the `dist' variable because
  we need alpha values of neighbor to compute the gradient.

* src/sdf/ftbsdf.c (bsdf_approximate_edge): Now that we can
  modify the `dist' variable of the distance map, we can
  combine the two nested loops.

* src/sdf/ftbsdf.c (finalize_sdf): Move the `sign' determination
  and assignment to this function.
2020-08-02 16:33:21 +05:30
Anuj Verma 185c88905e * src/sdf/ftbsdf.c (compute_edge_distance): Grammer fix. 2020-08-02 16:33:21 +05:30
Anuj Verma 62b38d2b85 [sdf -> bsdf] Add explanation of the approximation.
* src/sdf/ftbsdf.c (compute_gradient => compute_edge_distance):
  Renamed to make sense of what the function does.
  Also, added the explanation of the algorithm used
  and a high level view of how it works.

* src/sdf/ftbsdf.c (compare_neighbor): Fix a bug related
  to value approximation before calling `FT_Vector_Length'.
2020-08-02 16:33:21 +05:30
Anuj Verma dcdcc65201 * src/sdf/ftsdfcommon.h (*): Fix line endings.
Always use LF line endings.
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 aed19e1524 * src/sdf/ftbsdf.c (compute_gradient): Use root(2) for the filter.
Also, use the computed gradient to approximate
the edge distance from a pixel's position according
to the Gustavson's algorithm.
2020-08-02 16:33:21 +05:30
Anuj Verma fbbec7c64d [sdf -> bsdf] Added function to approximate edge distance.
* src/sdf/ftbsdf.c (bsdf_approximate_edge): The function
  uses the Gustavson's algorithm to approximate the edge
  from pixel values.

* src/sdf/ftbsdf.c (compute_gradient): The function uses
  Sobel's operator to compute the gradient at a pixel.
  The is used to detect edge direction.
2020-08-02 16:33:21 +05:30
Anuj Verma ffb6890089 * src/sdf/ftbsdf.c (_pass): Use function for repetitive task.
Use function `compare_neighbor' for comparing the
neighbors. Makes it easier to tweak the algorithm
and looks better.

* src/sdf/ftbsdf.c (compare_neighbor): Added function
  to compare the neighbors and assign values if the
  new distance is the shortest.
2020-08-02 16:33:21 +05:30
Anuj Verma 419633c374 * 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-08-02 16:33:21 +05:30
Anuj Verma 262e9649f3 [sdf -> bsdf] Fix edge detection bug.
* src/sdf/ftbsdf.c (bsdf_is_edge): [BUG] Check all
  neighbors including the diagonal neighbors to
  properly determine the edge.
2020-08-02 16:33:21 +05:30
Anuj Verma f057095bef [sdf -> bsdf] Added edge detection algorithm.
Added edge detection algorithm. It works by checking
the neighboring pixels and if any neighbor is not
filled (i.e. belongs to background) we mark the
pixel as edge by setting it's distance to 0.

* src/sdf/ftbsdf.c (bsdf_is_edge): Added function to
  detect if the pixel is an edge.
2020-08-02 16:33:21 +05:30
Anuj Verma 8564d5caf2 [sdf -> bsdf] Added the second pass of the '8SED'.
Added the second pass of the 8SED algorithm. The second pass
transverse the bitmap from bottom to top and for each row
it sweeps forward and backward assigning distances to the
grid points.

* src/sdf/ftbsdf.c (second_pas): Added function to do the
  second pass of the 8SED algorithm on the bitmap.
2020-08-02 16:33:21 +05:30
Anuj Verma 6214e58893 [sdf -> bsdf] Optimize the first pass of the 8SED.
* src/sdf/ftbsdf.c (first_pass): Optimize the first
  pass by first approximating the neighbor's distance
  by adding an offset. The offset will be max root(2)
  because the maximum be add to a vector is (1, 1).
  By approximating we can reduce the number of
  `FT_Vector_Length' calls and thus make the process
  faster.
2020-08-02 16:33:21 +05:30
Anuj Verma 6ccbf0ecf6 [sdf] Fix GNU Make build.
* src/sdf/rules.mk (SDF_DRV_H): Manually add source files
  as there is a `ftbsdf.c' file without any `ftbsdf.h'.

* src/sdf/ftbsdf.c: Include `fttrigon.h' for `multi' builds.
2020-08-02 16:33:21 +05:30
Anuj Verma 470131db91 [sdf -> bsdf] Added first pass of the '8SED' algorithm.
Added the first pass of the 8SED algorithm. The first pass
transverse the bitmap from top to bottom and for each row
it sweeps forward and backward assigning distances to the
grid points.

* src/sdf/ftbsdf.c (ED): Added additional parameter `sign'.

* src/sdf/ftbsdf.c (edt8): Added function to convert bitmap
  to SDF using the 8SED algorithm.

* src/sdf/ftbsdf.c (first_pass): Added function to do the
  first pass of the 8SED algorithm on the bitmap.

* src/sdf/ftbsdf.c (finalize_sdf): Added function to assign
  the final SDF data to the target bitmap.

* src/sdf/ftbsdf.c (*): Various minor or experimental changes.

* src/sdf/ftsdfrend.c (ft_bsdf_render): Fix spacing.
2020-08-02 16:33:20 +05:30
Anuj Verma 59d340878a * src/sdf/ftbsdf.c (*): Rename `SDF_TRaster' => `BSDF_TRaster'.
`SDF_TRaster' is for the `sdf' renderer.
2020-08-02 16:33:20 +05:30
Anuj Verma ea5114acfd * src/sdf/ftbsdf.c: Typo. `FT_16D16' is 16.16 representation. 2020-08-02 16:33:20 +05:30
Anuj Verma 13180a3cd4 [sdf -> bsdf renderer] Hold a refrence to `FT_Memory'.
Due to the way the 8SED algorithm works we need to keep
a track of distances and nearest point of all the pixels/
grid points.

* src/sdf/ftbsdf.c (BSDF_TRaster): Added struct to
  hold the `FT_Memory' reference, to be used to allocate
  memory.

* src/sdf/ftbsdf.c (ED, BSDF_Worker): Added few more
  essential struct. `ED' contains infomation about the
  nearest point. `BSDF_Worker' is used to combine all
  the essentail parameters to functions.

* src/sdf/ftbsdf.c (bsdf_copy_source_to_target => 
  bsdf_init_distance_map): Renamed.

* src/sdf/ftbsdf.c (*): Various minor changes.

* src/sdf/sdf.c: Change the order of source include
  because `ftsdf.c' change some internal freetype
  defines which are required in `ftbsdf.c'.
2020-08-02 16:33:20 +05:30
Anuj Verma 99a4759290 [sdf -> bsdf renderer] Convert 8bit bitmap to 16bit.
* src/sdf/ftbsdf.c (bsdf_copy_source_to_target): Added
  extra parameter to flip the bitmap vertically.

* src/sdf/ftbsdf.c (bsdf_copy_source_to_target):
  Implemented functionality to convert 8bits per
  pixel bitmap to a 16bits per pixel bitmap, which
  will be used to generate SDF.
2020-08-02 16:33:20 +05:30
Anuj Verma 2c77a8acb2 [sdf] Started the `bsdf' rasterier.
* src/sdf/ftbsdf.c (*): Fix line endings.

* src/sdf/ftbsdf.c (bsdf_copy_source_to_target): Added
  function to copy the source bitmap to the center of
  the target bitmap and also convert it to normalized
  16 bits per pixel bitmap.
2020-08-02 16:33:20 +05:30
Anuj Verma 1d51c5ef7b [sdf] Added interface functions for `bsdf' converter.
* src/base/ftobjs.c (FT_Render_Glyph_Internal): Remove
  the bitmap check which prevent calling renderers
  if the glyph is already a bitmap. The `bsdf' renderer
  requires a bitmap for conversion.

* src/base/ftobjs.c (ft_add_renderer): Remove the glyph
  format check which ensures that the glyph format for
  a renderer is `FT_GLYPH_FORMAT_OUTLINE', again the `bsdf'
  renderer has `FT_GLYPH_FORMAT_BITMAP' as a glyph format,
  so we need to remove the condition to initialize the
  renderer properly.

* src/sdf/ftbsdf.c (*): Added a rasterizer for the
  `bsdf' renderer and created necessary functions.

* src/sdf/ftbsdf.h: Add forward declaration of the
  rasterizer.

* src/sdf/ftsdfrend.c (ft_bitmap_sdf_renderer_class):
  Define the new `bsdf' rendere and add the
  `FT_Renderer_RenderFunc' function, the rest is
  same as the `sdf' renderer.

* src/sdf/ftsdfrend.h: Add forward declaration of the
  renderer.

* src/sdf/rules.mk (SDF_DRV_SRC): Add the new `ftbsdf.c'
  file to the compile list.

* src/sdf/sdf.c: Inclue the `ftbsdf.c' file if making
  single object.
2020-08-02 16:33:20 +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 f41ee8f0c3 [sdf] Added new renderer `bsdf'.
* src/sdf/ftsdfrend.* (*): Added new renderer
  named `bsdf' which basically convert bitmap
  to signed distance fields. This is a part of
  the `sdf' module and not a separate module on
  it's own.

* src/sdf/module.mk (FTMODULE_H_COMMANDS): Add
  the new renderer to the list of modules.

* include/freetype/config/ftmodule.h: Add the
  new renderer to default list of modules when
  not compiling with GNU Make.
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 80ba40341c Revert "[sdfb] Added new module to generate SDF from bitmap."
This reverts commit 2136eddbccfa59b7478d87fe0947b35ca6a157f8.
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 04f2a34a7d [sdfb] Added new module to generate SDF from bitmap.
* src/sdfb/sdfb.c, src/sdfb/ftsdfbrend.c,
  src/sdfb/ftsdfb.c, src/sdfb/ftsdfbrend.h,
  src/sdfb/ftsdfb.h, src/sdfb/ftsdfberrs.h:
  Added files required by the `sdfb' renderer module.

* src/sdfb/rules.mk, src/sdfb/module.mk: Added
  files required to build the `sdfb' module using
  the default build system.

* CMakeLists.txt (BASE_SRCS): Add `src/sdfb/sdfb.c'
  to the variable.

* include/freetype/config/ftmodule.h: Added `sdfb'
  module declaration so that the module can be compiled
  when not compiling with GNU make.

* modules.cfg (RASTER_MODULES): Include `sdfb' module
  to the default rasterizer module list.

* include/freetype/ftmoderr.h: sdfb module error define

* src/sdf/rules.mk: Add EOF.
2020-08-02 16:33:20 +05:30