sdk-world v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Loading...
Searching...
No Matches
ftsdfcommon.h
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * ftsdfcommon.h
4 *
5 * Auxiliary data for Signed Distance Field support (specification).
6 *
7 * Copyright (C) 2020-2025 by
8 * David Turner, Robert Wilhelm, and Werner Lemberg.
9 *
10 * Written by Anuj Verma.
11 *
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.
17 *
18 */
19
20
21 /****************************************************
22 *
23 * This file contains common functions and properties
24 * for both the 'sdf' and 'bsdf' renderers.
25 *
26 */
27
32#ifndef FTSDFCOMMON_H_
33#define FTSDFCOMMON_H_
34
35#include <ft2build.h>
36#include FT_CONFIG_CONFIG_H
38
39
40FT_BEGIN_HEADER
41
42
43 /**************************************************************************
44 *
45 * default values (cannot be set individually for each renderer)
46 *
47 */
48
49 /* default spread value */
50#define DEFAULT_SPREAD 8
51 /* minimum spread supported by the renderer */
52#define MIN_SPREAD 2
53 /* maximum spread supported by the renderer */
54#define MAX_SPREAD 32
55 /* pixel size in 26.6 */
56#define ONE_PIXEL ( 1 << 6 )
57
58
59 /**************************************************************************
60 *
61 * common definitions (cannot be set individually for each renderer)
62 *
63 */
64
65 /* If this macro is set to 1 the rasterizer uses squared distances for */
66 /* computation. It can greatly improve the performance but there is a */
67 /* chance of overflow and artifacts. You can safely use it up to a */
68 /* pixel size of 128. */
69#ifndef USE_SQUARED_DISTANCES
70#define USE_SQUARED_DISTANCES 0
71#endif
72
73
74 /**************************************************************************
75 *
76 * common macros
77 *
78 */
79
80 /* convert int to 26.6 fixed-point */
81#define FT_INT_26D6( x ) ( x * 64 )
82 /* convert int to 16.16 fixed-point */
83#define FT_INT_16D16( x ) ( x * 65536 )
84 /* convert 26.6 to 16.16 fixed-point */
85#define FT_26D6_16D16( x ) ( x * 1024 )
86
87
88 /* Convenience macro to call a function; it */
89 /* jumps to label `Exit` if an error occurs. */
90#define FT_CALL( x ) do \
91 { \
92 error = ( x ); \
93 if ( error != FT_Err_Ok ) \
94 goto Exit; \
95 } while ( 0 )
96
97
98 /*
99 * The macro `VECTOR_LENGTH_16D16` computes either squared distances or
100 * actual distances, depending on the value of `USE_SQUARED_DISTANCES`.
101 *
102 * By using squared distances the performance can be greatly improved but
103 * there is a risk of overflow.
104 */
105#if USE_SQUARED_DISTANCES
106#define VECTOR_LENGTH_16D16( v ) ( FT_MulFix( v.x, v.x ) + \
107 FT_MulFix( v.y, v.y ) )
108#else
109#define VECTOR_LENGTH_16D16( v ) FT_Vector_Length( &v )
110#endif
111
112
113 /**************************************************************************
114 *
115 * common typedefs
116 *
117 */
118
119 typedef FT_Vector FT_26D6_Vec; /* with 26.6 fixed-point components */
120 typedef FT_Vector FT_16D16_Vec; /* with 16.16 fixed-point components */
121
122 typedef FT_Int32 FT_16D16; /* 16.16 fixed-point representation */
123 typedef FT_Int32 FT_26D6; /* 26.6 fixed-point representation */
124 typedef FT_Byte FT_SDFFormat; /* format to represent SDF data */
125
126 typedef FT_BBox FT_CBox; /* control box of a curve */
127
128
129#define square_root( x ) (FT_16D16)FT_SqrtFixed( (FT_UInt32)( x ) )
130
131 FT_LOCAL( FT_SDFFormat )
132 map_fixed_to_sdf( FT_16D16 dist,
133 FT_16D16 max_value );
134
135 FT_LOCAL( FT_SDFFormat )
136 invert_sign( FT_SDFFormat dist );
137
138
139FT_END_HEADER
140
141#endif /* FTSDFCOMMON_H_ */
142
143
144/* END */