[sdf] Formatting and improved comments.
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
diff --git a/ChangeLog b/ChangeLog
index 09f468f..84d0088 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,10 +3,10 @@
[sdf] Use 8 bits for final SDF output instead of 16bits.
Since 8-bits is enough to represent SDF data we no longer require
- 16-bits for this purpose. Also, we now normalize the output data
- to use the entire 8-bit range efficiently. For example: if we use
+ 16-bits for this purpose. Also, we now normalize the output data
+ to use the entire 8-bit range efficiently. For example: if we use
3.5 format with a spread of 1 we basically only use the starting
- 5-bits. By normalizing we can use the entire 8-bit range.
+ 5-bits. By normalizing we can use the entire 8-bit range.
* include/freetype/freetype.h (FT_Render_Mode): Updated description
for `FT_RENDER_MODE_SDF` regarding this change.
diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h
index ebb129f..a66d45a 100644
--- a/include/freetype/freetype.h
+++ b/include/freetype/freetype.h
@@ -3306,8 +3306,9 @@ FT_BEGIN_HEADER
* bitmaps. Each pixel in a SDF bitmap contains information about the
* nearest edge of the glyph outline. The distances are calculated
* from the center of the pixel and are positive if they are filled by
- * the outline (i.e., inside the outline) and negative otherwise. Check
- * the note below on how to convert the output values to usable data.
+ * the outline (i.e., inside the outline) and negative otherwise.
+ * Check the note below on how to convert the output values to usable
+ * data.
*
* @note:
* The selected render mode only affects vector glyphs of a font.
@@ -3315,30 +3316,31 @@ FT_BEGIN_HEADER
* @FT_PIXEL_MODE_MONO. You can use @FT_Bitmap_Convert to transform them
* into 8-bit pixmaps.
*
- * For @FT_RENDER_MODE_SDF output bitmap buffer contains normalized
- * distance values that are packed into unsigned 8-bit buffer. To get
- * pixel values in floating point representation use the following
- * conversion:
+ * For @FT_RENDER_MODE_SDF the output bitmap buffer contains normalized
+ * distances that are packed into unsigned 8-bit values. To get pixel
+ * values in floating point representation use the following pseudo-C
+ * code for the conversion.
*
* ```
- * <load glyph and render using @FT_RENDER_MODE_SDF, then use the
- * output buffer as follows>
+ * // Load glyph and render using FT_RENDER_MODE_SDF,
+ * // then use the output buffer as follows.
*
* ...
- * FT_Byte buffer = glyph->bitmap->buffer;
+ * FT_Byte buffer = glyph->bitmap->buffer;
+ *
*
* for pixel in buffer
* {
- * <`sd` is the signed distance and spread is the current `spread`,
- * the default spread is 2 and can be changed>
+ * // `sd` is the signed distance and `spread` is the current spread;
+ * // the default spread is 2 and can be changed.
*
- * float sd = (float)pixel - 128.0f;
+ * float sd = (float)pixel - 128.0f;
*
- * <convert the to pixel values>
*
+ * // Convert to pixel values.
* sd = ( sd / 128.0f ) * spread;
*
- * <store `sd` in a buffer or use as required>
+ * // Store `sd` in a buffer or use as required.
* }
*
* ```
diff --git a/src/sdf/ftbsdf.c b/src/sdf/ftbsdf.c
index 659e0de..db4a2dd 100644
--- a/src/sdf/ftbsdf.c
+++ b/src/sdf/ftbsdf.c
@@ -1092,12 +1092,13 @@
finalize_sdf( BSDF_Worker* worker,
const FT_Bitmap* target )
{
- FT_Error error = FT_Err_Ok;
+ FT_Error error = FT_Err_Ok;
+
+ FT_Int w, r;
+ FT_Int i, j;
- FT_Int w, r;
- FT_Int i, j;
- FT_SDFFormat* t_buffer;
- FT_16D16 spread;
+ FT_SDFFormat* t_buffer;
+ FT_16D16 spread;
if ( !worker || !target )
@@ -1128,10 +1129,10 @@
{
for ( i = 0; i < w; i++ )
{
- FT_Int index;
- FT_16D16 dist;
- FT_SDFFormat final_dist;
- FT_Char sign;
+ FT_Int index;
+ FT_16D16 dist;
+ FT_SDFFormat final_dist;
+ FT_Char sign;
index = j * w + i;
diff --git a/src/sdf/ftsdf.c b/src/sdf/ftsdf.c
index 335b800..a2f38be 100644
--- a/src/sdf/ftsdf.c
+++ b/src/sdf/ftsdf.c
@@ -2898,7 +2898,7 @@
#if 0
#error "DO NOT USE THIS!"
- #error "The function still output 16-bit data which might cause memory"
+ #error "The function still outputs 16-bit data, which might cause memory"
#error "corruption. If required I will add this later."
/**************************************************************************
@@ -3196,8 +3196,8 @@
FT_Int width, rows, i, j;
FT_Int sp_sq; /* max value to check */
- SDF_Contour* contours; /* list of all contours */
- FT_SDFFormat* buffer; /* the bitmap buffer */
+ SDF_Contour* contours; /* list of all contours */
+ FT_SDFFormat* buffer; /* the bitmap buffer */
/* This buffer has the same size in indices as the */
/* bitmap buffer. When we check a pixel position for */
@@ -3206,7 +3206,7 @@
/* and also determine the signs properly. */
SDF_Signed_Distance* dists = NULL;
- const FT_16D16 fixed_spread = FT_INT_16D16( spread );
+ const FT_16D16 fixed_spread = FT_INT_16D16( spread );
if ( !shape || !bitmap )
@@ -3362,14 +3362,12 @@
dists[index].distance = fixed_spread;
/* flip sign if required */
- dists[index].distance *= internal_params.flip_sign ?
- -current_sign :
- current_sign;
+ dists[index].distance *= internal_params.flip_sign ? -current_sign
+ : current_sign;
/* concatenate to appropriate format */
- buffer[index] = map_fixed_to_sdf(
- dists[index].distance,
- fixed_spread );
+ buffer[index] = map_fixed_to_sdf( dists[index].distance,
+ fixed_spread );
}
}
@@ -3506,9 +3504,9 @@
SDF_Contour* head; /* head of the contour list */
SDF_Shape temp_shape; /* temporary shape */
- FT_Memory memory; /* to allocate memory */
- FT_SDFFormat* t; /* target bitmap buffer */
- FT_Bool flip_sign; /* filp sign? */
+ FT_Memory memory; /* to allocate memory */
+ FT_SDFFormat* t; /* target bitmap buffer */
+ FT_Bool flip_sign; /* flip sign? */
/* orientation of all the separate contours */
SDF_Contour_Orientation* orientations;
@@ -3644,18 +3642,18 @@
{
for ( i = 0; i < width; i++ )
{
- FT_Int id = j * width + i; /* index of current pixel */
- FT_Int c; /* contour iterator */
+ FT_Int id = j * width + i; /* index of current pixel */
+ FT_Int c; /* contour iterator */
- FT_SDFFormat val_c = 0; /* max clockwise value */
- FT_SDFFormat val_ac = UCHAR_MAX; /* min counter-clockwise val */
+ FT_SDFFormat val_c = 0; /* max clockwise value */
+ FT_SDFFormat val_ac = UCHAR_MAX; /* min counter-clockwise val */
/* iterate through all the contours */
for ( c = 0; c < num_contours; c++ )
{
/* current contour value */
- FT_SDFFormat temp = ( (FT_SDFFormat*)bitmaps[c].buffer )[id];
+ FT_SDFFormat temp = ( (FT_SDFFormat*)bitmaps[c].buffer )[id];
if ( orientations[c] == SDF_ORIENTATION_CW )