1 /****************************************************************************
5 * Auxiliary data for Signed Distance Field support (specification).
7 * Copyright (C) 2020-2023 by
8 * David Turner, Robert Wilhelm, and Werner Lemberg.
10 * Written by Anuj Verma.
12 * This file is part of the FreeType project, and may only be used,
13 * modified, and distributed under the terms of the FreeType project
14 * license, LICENSE.TXT. By continuing to use, modify, or distribute
15 * this file you indicate that you have read the license and
16 * understand and accept it fully.
21 /****************************************************
23 * This file contains common functions and properties
24 * for both the 'sdf' and 'bsdf' renderers.
28 #ifndef FTSDFCOMMON_H_
29 #define FTSDFCOMMON_H_
32 #include FT_CONFIG_CONFIG_H
33 #include <freetype/internal/ftobjs.h>
39 /**************************************************************************
41 * default values (cannot be set individually for each renderer)
45 /* default spread value */
46 #define DEFAULT_SPREAD 8
47 /* minimum spread supported by the renderer */
49 /* maximum spread supported by the renderer */
51 /* pixel size in 26.6 */
52 #define ONE_PIXEL ( 1 << 6 )
55 /**************************************************************************
57 * common definitions (cannot be set individually for each renderer)
61 /* If this macro is set to 1 the rasterizer uses squared distances for */
62 /* computation. It can greatly improve the performance but there is a */
63 /* chance of overflow and artifacts. You can safely use it up to a */
64 /* pixel size of 128. */
65 #ifndef USE_SQUARED_DISTANCES
66 #define USE_SQUARED_DISTANCES 0
70 /**************************************************************************
76 /* convert int to 26.6 fixed-point */
77 #define FT_INT_26D6( x ) ( x * 64 )
78 /* convert int to 16.16 fixed-point */
79 #define FT_INT_16D16( x ) ( x * 65536 )
80 /* convert 26.6 to 16.16 fixed-point */
81 #define FT_26D6_16D16( x ) ( x * 1024 )
84 /* Convenience macro to call a function; it */
85 /* jumps to label `Exit` if an error occurs. */
86 #define FT_CALL( x ) do \
89 if ( error != FT_Err_Ok ) \
95 * The macro `VECTOR_LENGTH_16D16` computes either squared distances or
96 * actual distances, depending on the value of `USE_SQUARED_DISTANCES`.
98 * By using squared distances the performance can be greatly improved but
99 * there is a risk of overflow.
101 #if USE_SQUARED_DISTANCES
102 #define VECTOR_LENGTH_16D16( v ) ( FT_MulFix( v.x, v.x ) + \
103 FT_MulFix( v.y, v.y ) )
105 #define VECTOR_LENGTH_16D16( v ) FT_Vector_Length( &v )
109 /**************************************************************************
115 typedef FT_Vector FT_26D6_Vec; /* with 26.6 fixed-point components */
116 typedef FT_Vector FT_16D16_Vec; /* with 16.16 fixed-point components */
118 typedef FT_Int32 FT_16D16; /* 16.16 fixed-point representation */
119 typedef FT_Int32 FT_26D6; /* 26.6 fixed-point representation */
120 typedef FT_Byte FT_SDFFormat; /* format to represent SDF data */
122 typedef FT_BBox FT_CBox; /* control box of a curve */
126 square_root( FT_16D16 val );
128 FT_LOCAL( FT_SDFFormat )
129 map_fixed_to_sdf( FT_16D16 dist,
130 FT_16D16 max_value );
132 FT_LOCAL( FT_SDFFormat )
133 invert_sign( FT_SDFFormat dist );
138 #endif /* FTSDFCOMMON_H_ */