[sdf] Formatting and improved comments.

This commit is contained in:
Werner Lemberg 2021-06-08 09:00:39 +02:00
parent 2b1d556269
commit 36ee71714f
4 changed files with 45 additions and 44 deletions

View File

@ -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;
*
*
* 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;
*
* <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.
* }
*
* ```

View File

@ -1096,6 +1096,7 @@
FT_Int w, r;
FT_Int i, j;
FT_SDFFormat* t_buffer;
FT_16D16 spread;

View File

@ -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."
/**************************************************************************
@ -3362,13 +3362,11 @@
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,
buffer[index] = map_fixed_to_sdf( dists[index].distance,
fixed_spread );
}
}
@ -3508,7 +3506,7 @@
FT_Memory memory; /* to allocate memory */
FT_SDFFormat* t; /* target bitmap buffer */
FT_Bool flip_sign; /* filp sign? */
FT_Bool flip_sign; /* flip sign? */
/* orientation of all the separate contours */
SDF_Contour_Orientation* orientations;