/**************************************************************************** * * ftsdfcommon.c * * Auxiliary data for Signed Distance Field support (body). * * Copyright (C) 2020-2023 by * David Turner, Robert Wilhelm, and Werner Lemberg. * * Written by Anuj Verma. * * This file is part of the FreeType project, and may only be used, * modified, and distributed under the terms of the FreeType project * license, LICENSE.TXT. By continuing to use, modify, or distribute * this file you indicate that you have read the license and * understand and accept it fully. * */ #include "ftsdf.h" #include "ftsdfcommon.h" /************************************************************************** * * common functions * */ /* * Original algorithm: * * https://github.com/chmike/fpsqrt * * Use this to compute the square root of a 16.16 fixed-point number. */ FT_LOCAL_DEF( FT_16D16 ) square_root( FT_16D16 val ) { … } /************************************************************************** * * format and sign manipulating functions * */ /* * Convert 16.16 fixed-point values to the desired output format. * In this case we reduce 16.16 fixed-point values to normalized * 8-bit values. * * The `max_value` in the parameter is the maximum value in the * distance field map and is equal to the spread. We normalize * the distances using this value instead of computing the maximum * value for the entire bitmap. * * You can use this function to map the 16.16 signed values to any * format required. Do note that the output buffer is 8-bit, so only * use an 8-bit format for `FT_SDFFormat`, or increase the buffer size in * `ftsdfrend.c`. */ FT_LOCAL_DEF( FT_SDFFormat ) map_fixed_to_sdf( FT_16D16 dist, FT_16D16 max_value ) { … } /* * Invert the signed distance packed into the corresponding format. * So if the values are negative they will become positive in the * chosen format. * * [Note]: This function should only be used after converting the * 16.16 signed distance values to `FT_SDFFormat`. If that * conversion has not been done, then simply invert the sign * and use the above function to pack the values. */ FT_LOCAL_DEF( FT_SDFFormat ) invert_sign( FT_SDFFormat dist ) { … } /* END */