2020-07-25 Anuj Verma [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-07-24 Anuj Verma [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-07-19 Anuj Verma [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-07-19 Anuj Verma [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-07-19 Anuj Verma [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-07-18 Anuj Verma [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-07-18 Anuj Verma [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-07-18 Anuj Verma [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-07-17 Anuj Verma [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-07-17 Anuj Verma [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-07-15 Anuj Verma * src/sdf/ftsdfrend.c (sdf_property_set): Minor fix. 2020-07-14 Anuj Verma [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-07-13 Anuj Verma [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-07-13 Anuj Verma [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-07-12 Anuj Verma [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-07-11 Anuj Verma * src/sdf/ftsdf.c (*): Fixed warnings. Fixed various warnings and other few errors. 2020-07-11 Anuj Verma * 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-07-11 Anuj Verma * 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-07-11 Anuj Verma [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-07-10 Anuj Verma [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-07-10 Anuj Verma [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-07-10 Anuj Verma [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-07-09 Anuj Verma [sdf] Added subdivision optimization. * src/sdf/ftsdf.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-07-09 Anuj Verma [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-07-09 Anuj Verma * src/sdf/ftsdf.c (split_sdf_shape): Typo. 2020-07-08 Anuj Verma * 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-07-08 Anuj Verma [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-07-06 Anuj Verma * [GSoC]ChangLog: Fixed typos. 2020-07-06 Anuj Verma * src/sdf/ftsdfrend.c (sdf_generate_bounding_box): Due to the way we use the bounding box, we need to keep a track of signed distances of each pixel so later the sign can be determined properly. The method is certainly faster then checking all the pixels against all the edges, but also require a decent amount of memory to work. 2020-07-06 Anuj Verma [sdf] Precompute the orthogonality. * src/sdf/ftsdf.c (SDF_Signed_Distance): Remove unused fields. * src/sdf/ftsdf.c (resolve_corner): The function can be simplified to a single line. Instead of computing orthogonality here, we precompute it in the corresponding `get_min_distance_' functions more efficiently. * src/sdf/ftsdf.c (get_min_distance_): Precompute orthogonality/ cross product of direction and the distance vector. Since in these function we know that weather the distance vector and the direction are perpendicular, we can simply set the cross to 1 (sin(90) = 1) in case they are perpendicular. This can reduce the number of `FT_Vector_NormLen' calls. 2020-07-05 Anuj Verma [sdf] Added bounding box optimization. * src/sdf/ftsdfrend.c (sdf_generate_bounding_box): The function generate SDF just like the `sdf_generate' function, but uses bounding box to check pixels efficiently. * src/sdf/ftsdfrend.c (get_control_box): Added function to get control box of a `SDF_Edge'. 2020-07-04 Anuj Verma * src/sdf/ftsdfrend.c (sdf_shape_dump): Use `%ld' to printf `signed long' otherwise it gives wrong output. 2020-07-04 Anuj Verma * src/sdf/ftsdfrend.c (ft_sdf_render): Don't negate unsigned integers. 2020-07-03 Anuj Verma * src/sdf/ftsdf.c: Use ASCII single quote (') instead of back tick (`) for derivatives. Looks cleaner. 2020-07-03 Anuj Verma [sdf] Added function to find shortest distance from a point to a cubic bezier. Now the sdf module can render all types of fonts, but still has some issues. * src/sdf/ftsdf.c (get_min_distance_cubic): The function calculates shortest distance from a point to a cubic bezier curve. * src/sdf/ftsdf.c (sdf_edge_get_min_distance): Add the `get_min_distance_cubic' function call. 2020-07-03 Anuj Verma * src/sdf/ftsdf.c (resolve_corner): [Bug] Remove the nearest_point check. Two distances can be same and can give opposite sign, but they may not have a common nearest_point. Also remove distance check because due to precision errors the two distances can be really really close. Therefore use epsilon instead. * src/sdf/ftsdf.c (sdf_contour_get_min_distance): Use epsilon for comparing distances. 2020-07-03 Anuj Verma * src/sdf/ftsdf.c (sdf_shape_dump): Add more info to the debug output. 2020-07-03 Anuj Verma * src/sdf/ftsdf.c (MAX_NEWTON_ITERATION => MAX_NEWTON_DIVISIONS): Renamed to avoid confusion. 2020-07-02 Anuj Verma [sdf] Added Newton's method for shortest distance from a point to a conic. * src/sdf/ftsdf.c (get_min_distance_conic): Created a new function with same name which uses Newton's iteration for finding shortest distance from a point to a conic curve. This doesn't causes underflow. * src/sdf/ftsdf.c (USE_NEWTON_FOR_CONIC): This macro can be used to toggle between Newton or analytical cubic solving method. 2020-07-01 Anuj Verma * src/sdf/ftsdf.c (get_min_distance_conic): Add more details to why we clamp the roots. * src/sdf/ftsdf.c: Make sure preprocessor # is always on the first line. 2020-07-01 Anuj Verma [sdf] Make squared distances toggleable. * src/sdf/ftsdf.c (SDF_Signed_Distance): Renamed squared_distance to distance. It can now represent both squared as well as actual distances. * src/sdf/ftsdf.c (USE_SQUARED_DISTANCES): Added macro which control weather to do computation is squared distances or actual distances. This can be used to avoid overflow when generating large SDF bitmaps. * src/sdf/ftsdf.c: Make sure not to exceed line length of 78. 2020-07-01 Anuj Verma * src/sdf/ftsdf.c (get_min_distance_conic): In case the cubic equation returns zero root, use endpoints for calculating the shortest distance. 2020-07-01 Anuj Verma [sdf] Added function to find shortest distance from a point to a conic bezier. Now the sdf module can render ttf fonts or fonts with line and conic segments. * src/sdf/ftsdf.c (get_min_distance_conic): The function calculates shortest distance from a point to a conic bezier curve. * src/sdf/ftsdf.c (sdf_edge_get_min_distance): Add the `get_min_distance_conic' function call. 2020-07-01 Anuj Verma * src/sdf/ftsdf.c (get_min_distance_line): First check pointer before using or dereferencing them. 2020-06-30 Anuj Verma * src/sdf/ftsdf.c: Avoid parentheses if there is only one statement inside a control-flow statement. 2020-06-30 Anuj Verma [sdf] Added functions to solve polynomial equations. * src/sdf/ftsdf.c (solve_quadratic_equation, solve_cubic_equation): Added functions to solve quadratic and cubic equations. These will be used for conic bezier curves only. 2020-06-30 Anuj Verma * src/sdf/ftsdf.c (square_root, cube_root, arc_cos): Use FT_16D16 instead of FT_Fixed to avoid confusion. 2020-06-30 Anuj Verma * src/sdf/ftsdf.c (cube_root, arc_cos): Added a few essential math functions. 2020-06-30 Anuj Verma [sdf] Fixed compilation under gnumake. * src/sdf/rules.mk (DRV_OBJ_ => DRV_OBJS_): Fixed variable name so that the sdf can compile. * src/sdf/module.mk: Fixed spacing. * src/sdf/*.c: Fixed all compiler warnings. * [GSoC]ChangLog: Fixed dates. 2020-06-29 Anuj Verma [sdf] Added function to resolve corners in case of ambiguity. * src/sdf/ftsdf.c (resolve_corner): Added function to determine the correct sign in case there are two sign for the same shortest distance (happens around corners). * src/sdf/ftsdf.c: Typo neartest_point -> nearest_point. 2020-06-29 Anuj Verma [sdf] The module can now generate signed distance fields for outline with only lines. * src/sdf/ftsdf.c (get_min_distance_line): Calculation mistake. * src/sdf/ftsdf.c (square_root): Added function to calculate square root of a 16.16 fixed point integer. * src/sdf/ftsdf.c (sdf_generate): Assign values to the output bitmap, currently the output is 6.10 fixed point which can contain values from [-32, 32]. Also fixed a bug which was causing upside down images. * src/sdf/ftsdfrend.c (ft_sdf_render): Fixed alignment issues. 2020-06-28 Anuj Verma [sdf] Added function to find shortest distance from a point to a line. * src/sdf/ftsdf.c (get_min_distance_line): The function calculate the shortest signed distance from a point to a line segment. * src/sdf/ftsdf.c (sdf_contour_get_min_distance): Typo. * src/sdf/ftsdf.c (SDF_Signed_Distance): Use squared distance instead of actual distance for performance. 2020-06-28 Anuj Verma * src/sdf/ftsdf.c (SDF_Iterator_IO): Removed. * src/sdf/ftsdf.c (sdf_edge_iterator_func => sdf_edge_get_min_distance sdf_contour_iterator_func => sdf_contour_get_min_distance): Renamed. Manually iterate through the lists instead of `FT_List_Iterate' to avoid io structs and looks a bit cleaner. 2020-06-28 Anuj Verma [sdf] Added basic outline of the functions required to generate sdf. * src/sdf/ftsdf.c (SDF_Signed_Distance): Added struct which represent a complete signed distance and can be used to get cross, dot, sign etc. * src/sdf/ftsdf.c (SDF_Iterator_IO): This struct will be used while `FT_List_Iterate'. * src/sdf/ftsdf.c (sdf_generate): Added function which generate SDF from `SDF_Shape'. * src/sdf/ftsdf.c (sdf_edge_iterator_func, sdf_contour_iterator_func): Added functions which iterate through contours and edges and return the shortest distance. 2020-06-27 Anuj Verma [sdf] Added `SDF_Raster_Params' struct which extends `FT_Raster_Params' and has a few extra fields. This is done to pass extra data to the sdf rasterizer which is required while rasterizing. * src/sdf/ftsdf.h (SDF_Raster_Params): Added a struct which extends `FT_Raster_Params' and has the `spread' parameter. Also moved the max, min and default spread values to this header file. * src/sdf/ftsdf.c (sdf_raster_render): Added parameter and attribute checking in order to pick errors and return early. * src//sdf/ftsdfrend.c (ft_sdf_render): Setup the `SDF_Raster_Params' and pass it to the rasterizer instead of `FT_Raster_Params'. 2020-06-27 Anuj Verma * include/freetype/ftimage.h (FT_RASTER_FLAG_): Added a new raster flag `FT_RASTER_FLAG_SDF'. The `ftsdf' rasterizer will only render if this flag is set. * src/sdf/ftsdfrend.c (ft_sdf_render): Set the `flags' field of `FT_Raster_Params' to `FT_RASTER_FLAG_SDF'. 2020-06-26 Anuj Verma * src/sdf/ftsdf.c (sdf_shape_dump): Use `FT_TRACEX' instead of `printf'. 2020-06-26 Anuj Verma * src/sdf/ftsdf.c (sdf_shape_dump): Added function to dump the `SDF_Shape' on the console for debugging. 2020-06-26 Anuj Verma [sdf] Added functions to de-allocate `SDF_' structs. * src/sdf/ftsdf.c (SDF_Contour, SDF_Shape): Use `FT_ListRec' instead of `FT_List' to avoid a few extra allocations. * src/sdf/ftsdf.c (SDF_Edge, SDF_Contour, SDF_Shape): Added functions to de-allocate these structs and their members. * src/sdf/ftsdfrenc.c: Typo. 2020-06-25 Anuj Verma [sdf] Decompose outline and store it in a temporary `SDF_Shape' object for easy iteration and pre-computing some variables. * src/sdf/ftsdf.c (sdf_outline_decompose): Added function to decompost outline and store it in a `SDF_Shape' object. This allows us to pre-compute some variable. 2020-06-25 Anuj Verma [sdf] Added essential enums and structs required. * src/freetype/internal/fttrace.h: Remove tabs. * src/sdf/ftsdfrend.c (ft_sdf_render): Calculate padding using the `spread'. * src/sdf/ftsdf.c (SDF_Edge_Type, SDF_Edge, SDF_Contour, SDF_Shape): Added structures and their initializer functions. 2020-06-23 Anuj Verma [sdf] Added functionality to set and get module properties. Also added a `spread' property. * src/freetype/internal/fttrace.h: Added sdf module trace define. * src/sdf/ftsdf.c (sdf_TRaster => SDF_TRaster): Use capital character for structs. * src/sdf/ftsdfrend.h (SDF_Renderer_Module): Added a struct which extends the `FT_RendererRec' and added the `spread' property. * src/sdf/ftsdfrend.c: Synchronized the code to use the new `SDF_Renderer_Module' and added functions to get/set the properties. 2020-06-20 Anuj Verma [sdf] Implemented a few functions required by a renderer module. * src/sdf/ftsdf.c (sdf_TRaster_): Added new structure to hold the memory allocator `FT_Memory'. * src/sdf/ftsdf.c (ft_sdf_raster): Implemented a few essential functions required by `FT_Raster'. * src/sdf/ftsdfrend.c (ft_sdf_renderer_class): Implemented a few essential functions required by `FT_Renderer'. * src/sdf/ftsdfrend.c (ft_sdf_render): Added functionality to compute shift and padding before rendering the outline. 2020-06-19 Anuj Verma * include/freetype/ftimage.h (FT_Render_Mode_): Added new pixel mode `FT_PIXEL_MODE_GRAY16' which will be used to represent signed values while rendering to SDF bitmap. 2020-06-19 Anuj Verma * include/freetype/freetype.h (FT_Render_Mode_): Added new rendermode `FT_RENDER_MODE_SDF' which will be used by the `sdf' module to generate signed distance fields from glyph's outline. * src/sdf/ftsdfrend.h, src/sdf/module.mk, src/sdf/rules.mk: Add a new line at the end of files. 2020-06-18 Anuj Verma [sdf] Added the structure of a new module to render signed distance fields. * src/sdf/sdf.c, src/sdf/ftsdfrend.c, src/sdf/ftsdf.c, src/sdf/ftsdfrend.h, src/sdf/ftsdf.h, src/sdf/ftsdferrs.h: Added files required by the `sdf' renderer module and added the basic structure and functions required. * src/sdf/rules.mk, src/sdf/module.mk: Added files required to build the `sdf' module using the default build system. * CMakeLists.txt (BASE_SRCS): Add `src/sdf/sdf.c' to the variable. * include/freetype/config/ftmodule.h: Added `sdf' module declaration so that the module can be compiled when not compiling with GNU make. * modules.cfg (RASTER_MODULES): Include `sdf' module to the default rasterizer module list. * include/freetype/ftmoderr.h: sdf module error define