Werner Lemberg pushed to branch master at FreeType / FreeType
Commits:
-
36ee7171
by Werner Lemberg at 2021-06-08T09:00:39+02:00
-
35b21c71
by Werner Lemberg at 2021-06-08T09:06:39+02:00
8 changed files:
- ChangeLog
- include/freetype/freetype.h
- src/sdf/ftbsdf.c
- src/sdf/ftsdf.c
- + src/sdf/ftsdfcommon.c
- src/sdf/ftsdfcommon.h
- src/sdf/rules.mk
- src/sdf/sdf.c
Changes:
1 |
+2021-06-08 Werner Lemberg <wl@gnu.org>
|
|
2 |
+ |
|
3 |
+ [sdf] Make `make multi` work.
|
|
4 |
+ |
|
5 |
+ * src/sdf/ftsdf.c: Include `ftbitmap.h`.
|
|
6 |
+ |
|
7 |
+ * src/sdf/ftsdfcommon.h: Move function bodies to `ftsdfcommon.c`.
|
|
8 |
+ Include `ftobjs.h` to get definitions of `FT_LOCAL` and friends.
|
|
9 |
+ |
|
10 |
+ * src/sdf/ftsdfcommon.c: New file.
|
|
11 |
+ |
|
12 |
+ * src/sdf/rules.mk, src/sdf/sdf.c: Updated.
|
|
13 |
+ |
|
1 | 14 |
2021-06-08 Anuj Verma <anujv@iitbhilai.ac.in>
|
2 | 15 |
|
3 | 16 |
[sdf] Use 8 bits for final SDF output instead of 16bits.
|
4 | 17 |
|
5 | 18 |
Since 8-bits is enough to represent SDF data we no longer require
|
6 |
- 16-bits for this purpose. Also, we now normalize the output data
|
|
7 |
- to use the entire 8-bit range efficiently. For example: if we use
|
|
19 |
+ 16-bits for this purpose. Also, we now normalize the output data
|
|
20 |
+ to use the entire 8-bit range efficiently. For example: if we use
|
|
8 | 21 |
3.5 format with a spread of 1 we basically only use the starting
|
9 |
- 5-bits. By normalizing we can use the entire 8-bit range.
|
|
22 |
+ 5-bits. By normalizing we can use the entire 8-bit range.
|
|
10 | 23 |
|
11 | 24 |
* include/freetype/freetype.h (FT_Render_Mode): Updated description
|
12 | 25 |
for `FT_RENDER_MODE_SDF` regarding this change.
|
... | ... | @@ -3306,8 +3306,9 @@ FT_BEGIN_HEADER |
3306 | 3306 |
* bitmaps. Each pixel in a SDF bitmap contains information about the
|
3307 | 3307 |
* nearest edge of the glyph outline. The distances are calculated
|
3308 | 3308 |
* from the center of the pixel and are positive if they are filled by
|
3309 |
- * the outline (i.e., inside the outline) and negative otherwise. Check
|
|
3310 |
- * the note below on how to convert the output values to usable data.
|
|
3309 |
+ * the outline (i.e., inside the outline) and negative otherwise.
|
|
3310 |
+ * Check the note below on how to convert the output values to usable
|
|
3311 |
+ * data.
|
|
3311 | 3312 |
*
|
3312 | 3313 |
* @note:
|
3313 | 3314 |
* The selected render mode only affects vector glyphs of a font.
|
... | ... | @@ -3315,30 +3316,31 @@ FT_BEGIN_HEADER |
3315 | 3316 |
* @FT_PIXEL_MODE_MONO. You can use @FT_Bitmap_Convert to transform them
|
3316 | 3317 |
* into 8-bit pixmaps.
|
3317 | 3318 |
*
|
3318 |
- * For @FT_RENDER_MODE_SDF output bitmap buffer contains normalized
|
|
3319 |
- * distance values that are packed into unsigned 8-bit buffer. To get
|
|
3320 |
- * pixel values in floating point representation use the following
|
|
3321 |
- * conversion:
|
|
3319 |
+ * For @FT_RENDER_MODE_SDF the output bitmap buffer contains normalized
|
|
3320 |
+ * distances that are packed into unsigned 8-bit values. To get pixel
|
|
3321 |
+ * values in floating point representation use the following pseudo-C
|
|
3322 |
+ * code for the conversion.
|
|
3322 | 3323 |
*
|
3323 | 3324 |
* ```
|
3324 |
- * <load glyph and render using @FT_RENDER_MODE_SDF, then use the
|
|
3325 |
- * output buffer as follows>
|
|
3325 |
+ * // Load glyph and render using FT_RENDER_MODE_SDF,
|
|
3326 |
+ * // then use the output buffer as follows.
|
|
3326 | 3327 |
*
|
3327 | 3328 |
* ...
|
3328 |
- * FT_Byte buffer = glyph->bitmap->buffer;
|
|
3329 |
+ * FT_Byte buffer = glyph->bitmap->buffer;
|
|
3330 |
+ *
|
|
3329 | 3331 |
*
|
3330 | 3332 |
* for pixel in buffer
|
3331 | 3333 |
* {
|
3332 |
- * <`sd` is the signed distance and spread is the current `spread`,
|
|
3333 |
- * the default spread is 2 and can be changed>
|
|
3334 |
+ * // `sd` is the signed distance and `spread` is the current spread;
|
|
3335 |
+ * // the default spread is 2 and can be changed.
|
|
3334 | 3336 |
*
|
3335 |
- * float sd = (float)pixel - 128.0f;
|
|
3337 |
+ * float sd = (float)pixel - 128.0f;
|
|
3336 | 3338 |
*
|
3337 |
- * <convert the to pixel values>
|
|
3338 | 3339 |
*
|
3340 |
+ * // Convert to pixel values.
|
|
3339 | 3341 |
* sd = ( sd / 128.0f ) * spread;
|
3340 | 3342 |
*
|
3341 |
- * <store `sd` in a buffer or use as required>
|
|
3343 |
+ * // Store `sd` in a buffer or use as required.
|
|
3342 | 3344 |
* }
|
3343 | 3345 |
*
|
3344 | 3346 |
* ```
|
... | ... | @@ -1092,12 +1092,13 @@ |
1092 | 1092 |
finalize_sdf( BSDF_Worker* worker,
|
1093 | 1093 |
const FT_Bitmap* target )
|
1094 | 1094 |
{
|
1095 |
- FT_Error error = FT_Err_Ok;
|
|
1095 |
+ FT_Error error = FT_Err_Ok;
|
|
1096 |
+ |
|
1097 |
+ FT_Int w, r;
|
|
1098 |
+ FT_Int i, j;
|
|
1096 | 1099 |
|
1097 |
- FT_Int w, r;
|
|
1098 |
- FT_Int i, j;
|
|
1099 |
- FT_SDFFormat* t_buffer;
|
|
1100 |
- FT_16D16 spread;
|
|
1100 |
+ FT_SDFFormat* t_buffer;
|
|
1101 |
+ FT_16D16 spread;
|
|
1101 | 1102 |
|
1102 | 1103 |
|
1103 | 1104 |
if ( !worker || !target )
|
... | ... | @@ -1128,10 +1129,10 @@ |
1128 | 1129 |
{
|
1129 | 1130 |
for ( i = 0; i < w; i++ )
|
1130 | 1131 |
{
|
1131 |
- FT_Int index;
|
|
1132 |
- FT_16D16 dist;
|
|
1133 |
- FT_SDFFormat final_dist;
|
|
1134 |
- FT_Char sign;
|
|
1132 |
+ FT_Int index;
|
|
1133 |
+ FT_16D16 dist;
|
|
1134 |
+ FT_SDFFormat final_dist;
|
|
1135 |
+ FT_Char sign;
|
|
1135 | 1136 |
|
1136 | 1137 |
|
1137 | 1138 |
index = j * w + i;
|
... | ... | @@ -22,6 +22,7 @@ |
22 | 22 |
#include <freetype/internal/ftdebug.h>
|
23 | 23 |
#include <freetype/ftoutln.h>
|
24 | 24 |
#include <freetype/fttrigon.h>
|
25 |
+#include <freetype/ftbitmap.h>
|
|
25 | 26 |
#include "ftsdf.h"
|
26 | 27 |
|
27 | 28 |
#include "ftsdferrs.h"
|
... | ... | @@ -2898,7 +2899,7 @@ |
2898 | 2899 |
#if 0
|
2899 | 2900 |
|
2900 | 2901 |
#error "DO NOT USE THIS!"
|
2901 |
- #error "The function still output 16-bit data which might cause memory"
|
|
2902 |
+ #error "The function still outputs 16-bit data, which might cause memory"
|
|
2902 | 2903 |
#error "corruption. If required I will add this later."
|
2903 | 2904 |
|
2904 | 2905 |
/**************************************************************************
|
... | ... | @@ -3196,8 +3197,8 @@ |
3196 | 3197 |
FT_Int width, rows, i, j;
|
3197 | 3198 |
FT_Int sp_sq; /* max value to check */
|
3198 | 3199 |
|
3199 |
- SDF_Contour* contours; /* list of all contours */
|
|
3200 |
- FT_SDFFormat* buffer; /* the bitmap buffer */
|
|
3200 |
+ SDF_Contour* contours; /* list of all contours */
|
|
3201 |
+ FT_SDFFormat* buffer; /* the bitmap buffer */
|
|
3201 | 3202 |
|
3202 | 3203 |
/* This buffer has the same size in indices as the */
|
3203 | 3204 |
/* bitmap buffer. When we check a pixel position for */
|
... | ... | @@ -3206,7 +3207,7 @@ |
3206 | 3207 |
/* and also determine the signs properly. */
|
3207 | 3208 |
SDF_Signed_Distance* dists = NULL;
|
3208 | 3209 |
|
3209 |
- const FT_16D16 fixed_spread = FT_INT_16D16( spread );
|
|
3210 |
+ const FT_16D16 fixed_spread = FT_INT_16D16( spread );
|
|
3210 | 3211 |
|
3211 | 3212 |
|
3212 | 3213 |
if ( !shape || !bitmap )
|
... | ... | @@ -3362,14 +3363,12 @@ |
3362 | 3363 |
dists[index].distance = fixed_spread;
|
3363 | 3364 |
|
3364 | 3365 |
/* flip sign if required */
|
3365 |
- dists[index].distance *= internal_params.flip_sign ?
|
|
3366 |
- -current_sign :
|
|
3367 |
- current_sign;
|
|
3366 |
+ dists[index].distance *= internal_params.flip_sign ? -current_sign
|
|
3367 |
+ : current_sign;
|
|
3368 | 3368 |
|
3369 | 3369 |
/* concatenate to appropriate format */
|
3370 |
- buffer[index] = map_fixed_to_sdf(
|
|
3371 |
- dists[index].distance,
|
|
3372 |
- fixed_spread );
|
|
3370 |
+ buffer[index] = map_fixed_to_sdf( dists[index].distance,
|
|
3371 |
+ fixed_spread );
|
|
3373 | 3372 |
}
|
3374 | 3373 |
}
|
3375 | 3374 |
|
... | ... | @@ -3506,9 +3505,9 @@ |
3506 | 3505 |
SDF_Contour* head; /* head of the contour list */
|
3507 | 3506 |
SDF_Shape temp_shape; /* temporary shape */
|
3508 | 3507 |
|
3509 |
- FT_Memory memory; /* to allocate memory */
|
|
3510 |
- FT_SDFFormat* t; /* target bitmap buffer */
|
|
3511 |
- FT_Bool flip_sign; /* filp sign? */
|
|
3508 |
+ FT_Memory memory; /* to allocate memory */
|
|
3509 |
+ FT_SDFFormat* t; /* target bitmap buffer */
|
|
3510 |
+ FT_Bool flip_sign; /* flip sign? */
|
|
3512 | 3511 |
|
3513 | 3512 |
/* orientation of all the separate contours */
|
3514 | 3513 |
SDF_Contour_Orientation* orientations;
|
... | ... | @@ -3644,18 +3643,18 @@ |
3644 | 3643 |
{
|
3645 | 3644 |
for ( i = 0; i < width; i++ )
|
3646 | 3645 |
{
|
3647 |
- FT_Int id = j * width + i; /* index of current pixel */
|
|
3648 |
- FT_Int c; /* contour iterator */
|
|
3646 |
+ FT_Int id = j * width + i; /* index of current pixel */
|
|
3647 |
+ FT_Int c; /* contour iterator */
|
|
3649 | 3648 |
|
3650 |
- FT_SDFFormat val_c = 0; /* max clockwise value */
|
|
3651 |
- FT_SDFFormat val_ac = UCHAR_MAX; /* min counter-clockwise val */
|
|
3649 |
+ FT_SDFFormat val_c = 0; /* max clockwise value */
|
|
3650 |
+ FT_SDFFormat val_ac = UCHAR_MAX; /* min counter-clockwise val */
|
|
3652 | 3651 |
|
3653 | 3652 |
|
3654 | 3653 |
/* iterate through all the contours */
|
3655 | 3654 |
for ( c = 0; c < num_contours; c++ )
|
3656 | 3655 |
{
|
3657 | 3656 |
/* current contour value */
|
3658 |
- FT_SDFFormat temp = ( (FT_SDFFormat*)bitmaps[c].buffer )[id];
|
|
3657 |
+ FT_SDFFormat temp = ( (FT_SDFFormat*)bitmaps[c].buffer )[id];
|
|
3659 | 3658 |
|
3660 | 3659 |
|
3661 | 3660 |
if ( orientations[c] == SDF_ORIENTATION_CW )
|
1 |
+/****************************************************************************
|
|
2 |
+ *
|
|
3 |
+ * ftsdfcommon.c
|
|
4 |
+ *
|
|
5 |
+ * Auxiliary data for Signed Distance Field support (body).
|
|
6 |
+ *
|
|
7 |
+ * Copyright (C) 2020-2021 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 |
+#include <ftsdf.h>
|
|
22 |
+#include <ftsdfcommon.h>
|
|
23 |
+ |
|
24 |
+ |
|
25 |
+ /**************************************************************************
|
|
26 |
+ *
|
|
27 |
+ * common functions
|
|
28 |
+ *
|
|
29 |
+ */
|
|
30 |
+ |
|
31 |
+ /*
|
|
32 |
+ * Original algorithm:
|
|
33 |
+ *
|
|
34 |
+ * https://github.com/chmike/fpsqrt
|
|
35 |
+ *
|
|
36 |
+ * Use this to compute the square root of a 16.16 fixed point number.
|
|
37 |
+ */
|
|
38 |
+ FT_LOCAL_DEF( FT_16D16 )
|
|
39 |
+ square_root( FT_16D16 val )
|
|
40 |
+ {
|
|
41 |
+ FT_ULong t, q, b, r;
|
|
42 |
+ |
|
43 |
+ |
|
44 |
+ r = (FT_ULong)val;
|
|
45 |
+ b = 0x40000000L;
|
|
46 |
+ q = 0;
|
|
47 |
+ |
|
48 |
+ while ( b > 0x40L )
|
|
49 |
+ {
|
|
50 |
+ t = q + b;
|
|
51 |
+ |
|
52 |
+ if ( r >= t )
|
|
53 |
+ {
|
|
54 |
+ r -= t;
|
|
55 |
+ q = t + b;
|
|
56 |
+ }
|
|
57 |
+ |
|
58 |
+ r <<= 1;
|
|
59 |
+ b >>= 1;
|
|
60 |
+ }
|
|
61 |
+ |
|
62 |
+ q >>= 8;
|
|
63 |
+ |
|
64 |
+ return (FT_16D16)q;
|
|
65 |
+ }
|
|
66 |
+ |
|
67 |
+ |
|
68 |
+ /**************************************************************************
|
|
69 |
+ *
|
|
70 |
+ * format and sign manipulating functions
|
|
71 |
+ *
|
|
72 |
+ */
|
|
73 |
+ |
|
74 |
+ /*
|
|
75 |
+ * Convert 16.16 fixed point values to the desired output format.
|
|
76 |
+ * In this case we reduce 16.16 fixed point values to normalized
|
|
77 |
+ * 8-bit values.
|
|
78 |
+ *
|
|
79 |
+ * The `max_value` in the parameter is the maximum value in the
|
|
80 |
+ * distance field map and is equal to the spread. We normalize
|
|
81 |
+ * the distances using this value instead of computing the maximum
|
|
82 |
+ * value for the entire bitmap.
|
|
83 |
+ *
|
|
84 |
+ * You can use this function to map the 16.16 signed values to any
|
|
85 |
+ * format required. Do note that the output buffer is 8-bit, so only
|
|
86 |
+ * use an 8-bit format for `FT_SDFFormat`, or increase the buffer size in
|
|
87 |
+ * `ftsdfrend.c`.
|
|
88 |
+ */
|
|
89 |
+ FT_LOCAL_DEF( FT_SDFFormat )
|
|
90 |
+ map_fixed_to_sdf( FT_16D16 dist,
|
|
91 |
+ FT_16D16 max_value )
|
|
92 |
+ {
|
|
93 |
+ FT_SDFFormat out;
|
|
94 |
+ FT_16D16 udist;
|
|
95 |
+ |
|
96 |
+ |
|
97 |
+ /* normalize the distance values */
|
|
98 |
+ dist = FT_DivFix( dist, max_value );
|
|
99 |
+ |
|
100 |
+ udist = dist < 0 ? -dist : dist;
|
|
101 |
+ |
|
102 |
+ /* Reduce the distance values to 8 bits. */
|
|
103 |
+ /* */
|
|
104 |
+ /* Since +1/-1 in 16.16 takes the 16th bit, we right-shift */
|
|
105 |
+ /* the number by 9 to make it fit into the 7-bit range. */
|
|
106 |
+ /* */
|
|
107 |
+ /* One bit is reserved for the sign. */
|
|
108 |
+ udist >>= 9;
|
|
109 |
+ |
|
110 |
+ /* Since `char` can only store a maximum positive value */
|
|
111 |
+ /* of 127 we need to make sure it does not wrap around and */
|
|
112 |
+ /* give a negative value. */
|
|
113 |
+ if ( dist > 0 && udist > 127 )
|
|
114 |
+ udist = 127;
|
|
115 |
+ if ( dist < 0 && udist > 128 )
|
|
116 |
+ udist = 128;
|
|
117 |
+ |
|
118 |
+ /* Output the data; negative values are from [0, 127] and positive */
|
|
119 |
+ /* from [128, 255]. One important thing is that negative values */
|
|
120 |
+ /* are inverted here, that means [0, 128] maps to [-128, 0] linearly. */
|
|
121 |
+ /* More on that in `freetype.h` near the documentation of */
|
|
122 |
+ /* `FT_RENDER_MODE_SDF`. */
|
|
123 |
+ out = dist < 0 ? 128 - (FT_SDFFormat)udist
|
|
124 |
+ : (FT_SDFFormat)udist + 128;
|
|
125 |
+ |
|
126 |
+ return out;
|
|
127 |
+ }
|
|
128 |
+ |
|
129 |
+ |
|
130 |
+ /*
|
|
131 |
+ * Invert the signed distance packed into the corresponding format.
|
|
132 |
+ * So if the values are negative they will become positive in the
|
|
133 |
+ * chosen format.
|
|
134 |
+ *
|
|
135 |
+ * [Note]: This function should only be used after converting the
|
|
136 |
+ * 16.16 signed distance values to `FT_SDFFormat`. If that
|
|
137 |
+ * conversion has not been done, then simply invert the sign
|
|
138 |
+ * and use the above function to pack the values.
|
|
139 |
+ */
|
|
140 |
+ FT_LOCAL_DEF( FT_SDFFormat )
|
|
141 |
+ invert_sign( FT_SDFFormat dist )
|
|
142 |
+ {
|
|
143 |
+ return 255 - dist;
|
|
144 |
+ }
|
|
145 |
+ |
|
146 |
+ |
|
147 |
+/* END */
|
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 |
*
|
3 | 3 |
* ftsdfcommon.h
|
4 | 4 |
*
|
5 |
- * Auxiliary data for Signed Distance Field support (specification only).
|
|
5 |
+ * Auxiliary data for Signed Distance Field support (specification).
|
|
6 | 6 |
*
|
7 | 7 |
* Copyright (C) 2020-2021 by
|
8 | 8 |
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
... | ... | @@ -30,7 +30,7 @@ |
30 | 30 |
|
31 | 31 |
#include <ft2build.h>
|
32 | 32 |
#include FT_CONFIG_CONFIG_H
|
33 |
-#include <freetype/freetype.h>
|
|
33 |
+#include <freetype/internal/ftobjs.h>
|
|
34 | 34 |
|
35 | 35 |
|
36 | 36 |
FT_BEGIN_HEADER
|
... | ... | @@ -120,116 +120,15 @@ FT_BEGIN_HEADER |
120 | 120 |
typedef FT_BBox FT_CBox; /* control box of a curve */
|
121 | 121 |
|
122 | 122 |
|
123 |
- /**************************************************************************
|
|
124 |
- *
|
|
125 |
- * common functions
|
|
126 |
- *
|
|
127 |
- */
|
|
128 |
- |
|
129 |
- /*
|
|
130 |
- * Original algorithm:
|
|
131 |
- *
|
|
132 |
- * https://github.com/chmike/fpsqrt
|
|
133 |
- *
|
|
134 |
- * Use this to compute the square root of a 16.16 fixed point number.
|
|
135 |
- */
|
|
136 |
- static FT_16D16
|
|
137 |
- square_root( FT_16D16 val )
|
|
138 |
- {
|
|
139 |
- FT_ULong t, q, b, r;
|
|
140 |
- |
|
141 |
- |
|
142 |
- r = (FT_ULong)val;
|
|
143 |
- b = 0x40000000L;
|
|
144 |
- q = 0;
|
|
145 |
- |
|
146 |
- while ( b > 0x40L )
|
|
147 |
- {
|
|
148 |
- t = q + b;
|
|
149 |
- |
|
150 |
- if ( r >= t )
|
|
151 |
- {
|
|
152 |
- r -= t;
|
|
153 |
- q = t + b;
|
|
154 |
- }
|
|
123 |
+ FT_LOCAL( FT_16D16 )
|
|
124 |
+ square_root( FT_16D16 val );
|
|
155 | 125 |
|
156 |
- r <<= 1;
|
|
157 |
- b >>= 1;
|
|
158 |
- }
|
|
126 |
+ FT_LOCAL( FT_SDFFormat )
|
|
127 |
+ map_fixed_to_sdf( FT_16D16 dist,
|
|
128 |
+ FT_16D16 max_value );
|
|
159 | 129 |
|
160 |
- q >>= 8;
|
|
161 |
- |
|
162 |
- return (FT_16D16)q;
|
|
163 |
- }
|
|
164 |
- |
|
165 |
- /**************************************************************************
|
|
166 |
- *
|
|
167 |
- * format and sign manipulating functions
|
|
168 |
- *
|
|
169 |
- */
|
|
170 |
- |
|
171 |
- /*
|
|
172 |
- * Convert 16.16 fixed point value to the desired output format.
|
|
173 |
- * In this case we reduce 16.16 fixed point value to normalized
|
|
174 |
- * 8-bit values.
|
|
175 |
- * The `max_value` in the parameter is the maximum value in the
|
|
176 |
- * distance field map and is equal to the spread. We normalize
|
|
177 |
- * the distances using this value instead of computing the maximum
|
|
178 |
- * value for the entire bitmap.
|
|
179 |
- * You can use this function to map the 16.16 signed values to any
|
|
180 |
- * format required. Do note that the output buffer is 8-bit, so only
|
|
181 |
- * use 8-bit format for `FT_SDFFormat`, or increase buffer size in
|
|
182 |
- * `ftsdfrend.c`.
|
|
183 |
- */
|
|
184 |
- static FT_SDFFormat
|
|
185 |
- map_fixed_to_sdf( FT_16D16 dist, FT_16D16 max_value )
|
|
186 |
- {
|
|
187 |
- FT_SDFFormat out;
|
|
188 |
- FT_16D16 udist;
|
|
189 |
- |
|
190 |
- |
|
191 |
- /* normalize the distance values */
|
|
192 |
- dist = FT_DivFix( dist, max_value );
|
|
193 |
- |
|
194 |
- udist = dist < 0 ? -dist : dist;
|
|
195 |
- |
|
196 |
- /* Reduce the distance values to 8 bits, +1/-1 in */
|
|
197 |
- /* 16.16 takes the 16th bit. So we right shift the */
|
|
198 |
- /* number by 9 to make it fit in the 7 bit range. */
|
|
199 |
- /* 1 bit is reserved for the sign. */
|
|
200 |
- udist >>= 9;
|
|
201 |
- |
|
202 |
- /* Since char can only store max positive value */
|
|
203 |
- /* of 127 we need to make sure it does not wrap */
|
|
204 |
- /* around and give a negative value. */
|
|
205 |
- if ( dist > 0 && udist > 127 )
|
|
206 |
- udist = 127;
|
|
207 |
- if ( dist < 0 && udist > 128 )
|
|
208 |
- udist = 128;
|
|
209 |
- |
|
210 |
- /* Output the data; negative values are from [0, 127] and positive */
|
|
211 |
- /* from [128, 255]. One important thing is that negative values */
|
|
212 |
- /* are inverted here, that means [0, 128] maps to [-128, 0] linearly. */
|
|
213 |
- /* More on that in `freetype.h` near `FT_RENDER_MODE_SDF` */
|
|
214 |
- out = dist < 0 ? 128 - (FT_SDFFormat)udist :
|
|
215 |
- (FT_SDFFormat)udist + 128;
|
|
216 |
- return out;
|
|
217 |
- }
|
|
218 |
- |
|
219 |
- /*
|
|
220 |
- * Invert the signed distance packed into the corresponding format.
|
|
221 |
- * So if the values are negative they will become positive in the
|
|
222 |
- * chosen format.
|
|
223 |
- *
|
|
224 |
- * [Note]: This function should only be used after converting the
|
|
225 |
- * 16.16 signed distance values to `FT_SDFFormat`, if that
|
|
226 |
- * conversion has not been done, then simply invert the sign
|
|
227 |
- * and use the above function to pack the values.
|
|
228 |
- */
|
|
229 |
- static FT_SDFFormat
|
|
230 |
- invert_sign( FT_SDFFormat dist ) {
|
|
231 |
- return 255 - dist;
|
|
232 |
- }
|
|
130 |
+ FT_LOCAL( FT_SDFFormat )
|
|
131 |
+ invert_sign( FT_SDFFormat dist );
|
|
233 | 132 |
|
234 | 133 |
|
235 | 134 |
FT_END_HEADER
|
... | ... | @@ -28,9 +28,10 @@ SDF_COMPILE := $(CC) $(ANSIFLAGS) \ |
28 | 28 |
|
29 | 29 |
# sdf driver sources (i.e., C files)
|
30 | 30 |
#
|
31 |
-SDF_DRV_SRC := $(SDF_DIR)/ftsdfrend.c \
|
|
32 |
- $(SDF_DIR)/ftsdf.c \
|
|
33 |
- $(SDF_DIR)/ftbsdf.c
|
|
31 |
+SDF_DRV_SRC := $(SDF_DIR)/ftsdfrend.c \
|
|
32 |
+ $(SDF_DIR)/ftsdf.c \
|
|
33 |
+ $(SDF_DIR)/ftbsdf.c \
|
|
34 |
+ $(SDF_DIR)/ftsdfcommon.c
|
|
34 | 35 |
|
35 | 36 |
|
36 | 37 |
# sdf driver headers
|
... | ... | @@ -21,6 +21,7 @@ |
21 | 21 |
#define FT_MAKE_OPTION_SINGLE_OBJECT
|
22 | 22 |
|
23 | 23 |
#include "ftsdfrend.c"
|
24 |
+#include "ftsdfcommon.c"
|
|
24 | 25 |
#include "ftbsdf.c"
|
25 | 26 |
#include "ftsdf.c"
|
26 | 27 |
|