[sdf] Make `make multi` work. * src/sdf/ftsdf.c: Include `ftbitmap.h`. * src/sdf/ftsdfcommon.h: Move function bodies to `ftsdfcommon.c`. Include `ftobjs.h` to get definitions of `FT_LOCAL` and friends. * src/sdf/ftsdfcommon.c: New file. * src/sdf/rules.mk, src/sdf/sdf.c: Updated.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
diff --git a/ChangeLog b/ChangeLog
index 84d0088..c57f562 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2021-06-08 Werner Lemberg <wl@gnu.org>
+
+ [sdf] Make `make multi` work.
+
+ * src/sdf/ftsdf.c: Include `ftbitmap.h`.
+
+ * src/sdf/ftsdfcommon.h: Move function bodies to `ftsdfcommon.c`.
+ Include `ftobjs.h` to get definitions of `FT_LOCAL` and friends.
+
+ * src/sdf/ftsdfcommon.c: New file.
+
+ * src/sdf/rules.mk, src/sdf/sdf.c: Updated.
+
2021-06-08 Anuj Verma <anujv@iitbhilai.ac.in>
[sdf] Use 8 bits for final SDF output instead of 16bits.
diff --git a/src/sdf/ftsdf.c b/src/sdf/ftsdf.c
index a2f38be..b377bde 100644
--- a/src/sdf/ftsdf.c
+++ b/src/sdf/ftsdf.c
@@ -22,6 +22,7 @@
#include <freetype/internal/ftdebug.h>
#include <freetype/ftoutln.h>
#include <freetype/fttrigon.h>
+#include <freetype/ftbitmap.h>
#include "ftsdf.h"
#include "ftsdferrs.h"
diff --git a/src/sdf/ftsdfcommon.c b/src/sdf/ftsdfcommon.c
new file mode 100644
index 0000000..031f2ba
--- /dev/null
+++ b/src/sdf/ftsdfcommon.c
@@ -0,0 +1,147 @@
+/****************************************************************************
+ *
+ * ftsdfcommon.c
+ *
+ * Auxiliary data for Signed Distance Field support (body).
+ *
+ * Copyright (C) 2020-2021 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 )
+ {
+ FT_ULong t, q, b, r;
+
+
+ r = (FT_ULong)val;
+ b = 0x40000000L;
+ q = 0;
+
+ while ( b > 0x40L )
+ {
+ t = q + b;
+
+ if ( r >= t )
+ {
+ r -= t;
+ q = t + b;
+ }
+
+ r <<= 1;
+ b >>= 1;
+ }
+
+ q >>= 8;
+
+ return (FT_16D16)q;
+ }
+
+
+ /**************************************************************************
+ *
+ * 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 )
+ {
+ FT_SDFFormat out;
+ FT_16D16 udist;
+
+
+ /* normalize the distance values */
+ dist = FT_DivFix( dist, max_value );
+
+ udist = dist < 0 ? -dist : dist;
+
+ /* Reduce the distance values to 8 bits. */
+ /* */
+ /* Since +1/-1 in 16.16 takes the 16th bit, we right-shift */
+ /* the number by 9 to make it fit into the 7-bit range. */
+ /* */
+ /* One bit is reserved for the sign. */
+ udist >>= 9;
+
+ /* Since `char` can only store a maximum positive value */
+ /* of 127 we need to make sure it does not wrap around and */
+ /* give a negative value. */
+ if ( dist > 0 && udist > 127 )
+ udist = 127;
+ if ( dist < 0 && udist > 128 )
+ udist = 128;
+
+ /* Output the data; negative values are from [0, 127] and positive */
+ /* from [128, 255]. One important thing is that negative values */
+ /* are inverted here, that means [0, 128] maps to [-128, 0] linearly. */
+ /* More on that in `freetype.h` near the documentation of */
+ /* `FT_RENDER_MODE_SDF`. */
+ out = dist < 0 ? 128 - (FT_SDFFormat)udist
+ : (FT_SDFFormat)udist + 128;
+
+ return out;
+ }
+
+
+ /*
+ * 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 )
+ {
+ return 255 - dist;
+ }
+
+
+/* END */
diff --git a/src/sdf/ftsdfcommon.h b/src/sdf/ftsdfcommon.h
index 7ce49bb..44f6bba 100644
--- a/src/sdf/ftsdfcommon.h
+++ b/src/sdf/ftsdfcommon.h
@@ -2,7 +2,7 @@
*
* ftsdfcommon.h
*
- * Auxiliary data for Signed Distance Field support (specification only).
+ * Auxiliary data for Signed Distance Field support (specification).
*
* Copyright (C) 2020-2021 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
@@ -30,7 +30,7 @@
#include <ft2build.h>
#include FT_CONFIG_CONFIG_H
-#include <freetype/freetype.h>
+#include <freetype/internal/ftobjs.h>
FT_BEGIN_HEADER
@@ -120,116 +120,15 @@ FT_BEGIN_HEADER
typedef FT_BBox FT_CBox; /* control box of a curve */
- /**************************************************************************
- *
- * common functions
- *
- */
-
- /*
- * Original algorithm:
- *
- * https://github.com/chmike/fpsqrt
- *
- * Use this to compute the square root of a 16.16 fixed point number.
- */
- static FT_16D16
- square_root( FT_16D16 val )
- {
- FT_ULong t, q, b, r;
-
-
- r = (FT_ULong)val;
- b = 0x40000000L;
- q = 0;
-
- while ( b > 0x40L )
- {
- t = q + b;
-
- if ( r >= t )
- {
- r -= t;
- q = t + b;
- }
+ FT_LOCAL( FT_16D16 )
+ square_root( FT_16D16 val );
- r <<= 1;
- b >>= 1;
- }
+ FT_LOCAL( FT_SDFFormat )
+ map_fixed_to_sdf( FT_16D16 dist,
+ FT_16D16 max_value );
- q >>= 8;
-
- return (FT_16D16)q;
- }
-
- /**************************************************************************
- *
- * format and sign manipulating functions
- *
- */
-
- /*
- * Convert 16.16 fixed point value to the desired output format.
- * In this case we reduce 16.16 fixed point value 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 8-bit format for `FT_SDFFormat`, or increase buffer size in
- * `ftsdfrend.c`.
- */
- static FT_SDFFormat
- map_fixed_to_sdf( FT_16D16 dist, FT_16D16 max_value )
- {
- FT_SDFFormat out;
- FT_16D16 udist;
-
-
- /* normalize the distance values */
- dist = FT_DivFix( dist, max_value );
-
- udist = dist < 0 ? -dist : dist;
-
- /* Reduce the distance values to 8 bits, +1/-1 in */
- /* 16.16 takes the 16th bit. So we right shift the */
- /* number by 9 to make it fit in the 7 bit range. */
- /* 1 bit is reserved for the sign. */
- udist >>= 9;
-
- /* Since char can only store max positive value */
- /* of 127 we need to make sure it does not wrap */
- /* around and give a negative value. */
- if ( dist > 0 && udist > 127 )
- udist = 127;
- if ( dist < 0 && udist > 128 )
- udist = 128;
-
- /* Output the data; negative values are from [0, 127] and positive */
- /* from [128, 255]. One important thing is that negative values */
- /* are inverted here, that means [0, 128] maps to [-128, 0] linearly. */
- /* More on that in `freetype.h` near `FT_RENDER_MODE_SDF` */
- out = dist < 0 ? 128 - (FT_SDFFormat)udist :
- (FT_SDFFormat)udist + 128;
- return out;
- }
-
- /*
- * 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.
- */
- static FT_SDFFormat
- invert_sign( FT_SDFFormat dist ) {
- return 255 - dist;
- }
+ FT_LOCAL( FT_SDFFormat )
+ invert_sign( FT_SDFFormat dist );
FT_END_HEADER
diff --git a/src/sdf/rules.mk b/src/sdf/rules.mk
index 72f45ff..7e7e4fb 100644
--- a/src/sdf/rules.mk
+++ b/src/sdf/rules.mk
@@ -28,9 +28,10 @@ SDF_COMPILE := $(CC) $(ANSIFLAGS) \
# sdf driver sources (i.e., C files)
#
-SDF_DRV_SRC := $(SDF_DIR)/ftsdfrend.c \
- $(SDF_DIR)/ftsdf.c \
- $(SDF_DIR)/ftbsdf.c
+SDF_DRV_SRC := $(SDF_DIR)/ftsdfrend.c \
+ $(SDF_DIR)/ftsdf.c \
+ $(SDF_DIR)/ftbsdf.c \
+ $(SDF_DIR)/ftsdfcommon.c
# sdf driver headers
diff --git a/src/sdf/sdf.c b/src/sdf/sdf.c
index e3860ef..1bc3fc3 100644
--- a/src/sdf/sdf.c
+++ b/src/sdf/sdf.c
@@ -21,6 +21,7 @@
#define FT_MAKE_OPTION_SINGLE_OBJECT
#include "ftsdfrend.c"
+#include "ftsdfcommon.c"
#include "ftbsdf.c"
#include "ftsdf.c"