Hello All,

>> The basic sdf module is done, now that is left is to
>> optimize it, fix bugs etc. I will start by optimizing it.
>> I have decided to test three optimization method:
>> * Bounding box (BB)
>> * Subdivisions
>> * And also a coarse grid method that Behdad suggested.

I have added all the optimization modes to the module.
By far the fastest method is to subdivide the curve into
a number of line segments.The coarse grid method is
the slowest unless I am doing something wrong.
[
  Behdad, I divided the grid into 8x8 coarse grid and then
  to find the relevant edges of the coarse grid I am using
  the spread value and the half diagonal of the coarse grid.
  So if any edge's nearest distance to a coarse grid is greater
  then spread + ( coarse grid diagonal length / 2 ) I discard it.
  It works well and for each coarse grid I am getting around
  4 edges, but it's still pretty slower than the bounding box and
  the subdivision method. If you need more details please let
  me know.
]
The major downside of the BB and subdivision methods is
that they require a considerable amount of memory usage
(almost 3x of the size of bitmap) because we need to keep
a track of the distances and signs of all the grid points.

>> The image is upside down in linux maybe because in linux the y = 0
>> is at the the top which is different from windows. I'll fix it soon
>> while adding bilinear filtering.

I have updated the demo, added bilinear filtering, shape
reconstruction and has all optimization modes which can
be toggled. I have attached the new list of keys.
(https://github.com/preversewharf45/ft2sdf-demo)

For now I would like to hold the outline implementation for
now and go to the bitmap implementation. After that the module
can be used to generate SDF from bitmaps directly. It will be
pretty fast and will not require any additional memory other than
the bitmap itself at a cost of reduced accuracy. However there
are a few issues.

* `FT_Render_Glyph_Internal' break if the glyph format is already
   a bitmap.
   ```
    case FT_GLYPH_FORMAT_BITMAP:   /* already a bitmap, don't do anything */
      break;
   ```
* `FT_Lookup_Renderer' uses renderer format which is currently
  `FT_GLYPH_FORMAT_OUTLINE' for the `sdf' module. How can
   make it accept both outline and bitmap glyph format ?

I don't like the idea of changing the internals of freetype so is there
any other way in which this can be done ?

Thanks in advance,
Anuj
----------------------------- KEYS ------------------------------

Esc / 'q'      : Quit the program.
               
'z'            : Scale up (This doesn't change point size, it
                 just zoom the image.)
'x'            : Scale Down (same as above)
               
'Up Arrow'     : Increase point size by 1.
'Down Arrow'   : Decrease point size by 1.
'Page UP'      : Increase point size by 25.
'Page Down'    : Decrease point size by 25.

'Left Arrow'   : Previous Glyph
'Right Arrow'  : Next Glyph

'o'            : Increase 'spread' by 1.
'l'            : Decrease 'spread' by 1.

'w', 's',      : Move the glyph Up/Down.
'a', 'd'       : Move the glyph Left/Right.

'f'            : Toggle between Nearest and Bilinear filtering.

-- OPTIMIZATION MODES --

Press the relevant keys to change the optimization mode.

'1'            : None (All grid points against all contours
                 and all edges.)

'2'            : Bounding Box (Use BB to improve performance
                 by only checking the grid points in the 
                 bounding box of a edge.)

'3'            : Subdivision (Subdivide the curve into lines
                 then only check the grid points near the
                 line segment) [FASTEST]

'4'            : Coarse Grid (Divide the area into a number of
                 coarse grids and then only check the edges
                 relevant to the coarse grid.)

-- RECONSTRUCT IMAGE FROM SDF --

'r'            : Toggle between Reconstruction and Raw view.

    ** The keys below are only for Reconstruction mode **
    -----------------------------------------------------

    'i'        : Increase Width. (Make the text bolder)
    'k'        : Decrease Width. (Make the text thinner)

    'u'        : Increase Edge. (Increase smoothness around
                 the edges, similar to anti-aliasing)
    'j'        : Decrease Edge. (Decrease smoothness around
                 the edges, makes the text sharper)

----------------------------- END ------------------------------

Reply via email to