* 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.
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.
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.
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.
* 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.
* 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.
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.
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'.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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]'
* 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.
* 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.
* 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.
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.
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'.
* 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.
* 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.
* 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.
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.
* 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.
* 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.
* 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.