Grigori Goronzy [Wed, 8 Jul 2009 12:43:58 +0000 (14:43 +0200)]
Use better method for stroking with \xbord, \ybord
Instead of stroking in two passes using the regular stroker use
the outline emboldener in case different x and y stroke widths are
requested.
The regular outline stroker draws circular arcs, adding points to
the outline. The number of points can vary according to the width
of the stroker. This makes it impossible to reliably stroke in
two passes with it.
The outline emboldener does not produce outlines looking as nice
as the stroker outlines, but it never adds points to the outline,
making it suitable for two-pass emboldening with different x and y
width.
Grigori Goronzy [Tue, 7 Jul 2009 22:07:52 +0000 (00:07 +0200)]
Turn down subpixel accuracy to 1/8th pixel
Using the full accuracy range of 1/64th pixel seems unnecessary--1/8th
pixel is "good enough". Mask out the three lowest bits to lower cache
and CPU usage; a short test shows that this almost halves the amount
of glyphs with different subpixel shifts being generated and cached.
Grigori Goronzy [Tue, 7 Jul 2009 18:25:55 +0000 (20:25 +0200)]
Support for underline and strikethrough
Add support for the underline (\u) and strikethrough/strikeout (\s)
properties. This is a bit tricky, since FreeType doesn't offer
any method of adding the lines, so you have to draw them yourself.
libass uses various information from TrueType tables to get position
and size of the lines, does a few simple consistency checks (some fonts
might be broken) and if everything is alright, adds new contours for
the lines.
Sometimes, rendering errors can occur:
- Currently, kerning isn't taken into account, which means the lines
can overlap a little, leading to small optical glitches.
- Some (broken) fonts use the wrong winding direction. In this case,
the FreeType stroker will only consider the added lines to be "outside"
and only stroke the line instead of the whole glyph.
Grigori Goronzy [Thu, 2 Jul 2009 14:37:52 +0000 (16:37 +0200)]
Fix crash when event format spec is missing
libass didn't properly initialize its idea about the event format
specification (the Format: line in the [Events] section) in case none
was explicitly specified. This ends in a crash due to access to a null
pointer. It was changed so that the event format is initialized to
a reasonable default, the way it is also done for embedded subtitles.
Grigori Goronzy [Mon, 6 Jul 2009 02:13:24 +0000 (04:13 +0200)]
Implement drawing mode (\p)
Finally implement the drawing mode, which allows drawing of custom
vector graphics. Drawings are intercepted in ass_render_event; a hash
of the drawing string is generated which is then used for looking
up drawings and bitmaps of drawings in the cache. The drawings
itself are "fake" glyphs. They are created by parsing the simple
drawing description language, evaluating the curves described (lines,
cubic beziers and/or a special kind of b-splines) and creating vector
outlines. Afterwards, these drawings are (with a few exceptions, e.g.
ascender/descender) exactly handled like regular glyphs.
Support for vector clippings is still missing, but otherwise the
implementation should be complete and compatible with VSFilter.
The libass integration of the drawing parsing/processing code is still a
bit sketchy and should be refactored.
History:
WIP: Drawing mode infrastructure
WIP: Drawing tokenizer
WIP: Parse drawing tokens, call evaluators
WIP: Bezier/b-spline evaluator
WIP: Final pieces for the drawing mode
WIP: Heavy modifications to the drawing parser/tokenizer
WIP: Dynamic outline memory allocation
WIP: Drawing position fixes
WIP: more drawing position fixup (similar to VSFilter now)
WIP: Lots of cleanup and fixes for drawings.
WIP: Drawing mode integration into ass_render_event
Grigori Goronzy [Tue, 30 Jun 2009 22:49:28 +0000 (00:49 +0200)]
Scale rotation constants with font scale
Rotations use a "magic" constant of, by default, 20000. This number
is more or less taken from VSFilter; I'm not even really sure what is
(viewing distance, maybe), but scaling it according to font_scale
solves problems with distortions of rotations in case the rendering
resolution differs from the video resolution.
Grigori Goronzy [Tue, 30 Jun 2009 22:16:20 +0000 (00:16 +0200)]
Assume pixel ratio equals aspect ratio
In ass_set_frame_size pixel_ratio will be set alongside aspect ratio to
the same value. This makes it possible to use libass without
explicitely specifying an aspect ratio.
Grigori Goronzy [Tue, 30 Jun 2009 11:39:14 +0000 (13:39 +0200)]
Support for \iclip (inverse clipping)
Inverse clipping means to display everything outside the clipping
rectangle. It is implemented by splitting up a bitmap into up
to 4 parts, as needed by the clipping rectangle. Afterwards, the
bitmap is clipped against the screen boundaries as usual. Finally,
each bitmap is split up into left and right and colored different,
in case \kf karaoke is in effect.
Grigori Goronzy [Tue, 30 Jun 2009 11:10:03 +0000 (13:10 +0200)]
Fix karaoke (\kf) timing
The timing for the \kf karaoke which gradually fills the character from
left to right, uses clipping and isn't aware of subpixel accuracy. This
is simply fixed by casting these value to int.
Grigori Goronzy [Mon, 29 Jun 2009 16:57:18 +0000 (18:57 +0200)]
Move subpixel shift out of transform_3d
Instead of adding the subpixel shift to the glyph in transform_3d, do it
directly in get_bitmap_glyph. This saves a few cycles for glyphs that
are not transformed (rotated or sheared).
Grigori Goronzy [Mon, 29 Jun 2009 15:05:44 +0000 (17:05 +0200)]
PAR correction for rendering at non-video resolution
The most prominent ASS/SSA renderer (VSFilter) conveniently ignores the
real aspect ratio, and everyone seems to rely on that. This is fine
when the subtitles are rendered before anamorphic video is stretched
to its native aspect ratio, but results in wrongly stretched text with
native renderers (EOSD). It can be fixed by making libass aware of
the pixel ratio of the video. ass_set_aspect_ratio now requires an
extra argument that specifies the pixel ratio, which is just width /
height of the video after decoding.
Glyphs are stretched in x direction before transformation (rotation,
shearing), so there are still issues with transformed glyphs to be
fixed.
Grigori Goronzy [Mon, 29 Jun 2009 12:16:46 +0000 (14:16 +0200)]
Restrict symbols exported in the DSO
Only export those symbols into the shared object which are defined in
the API (ass.h). A file libass.sym which contains a list of symbols
was added and libtool configured to use it.
Grigori Goronzy [Mon, 29 Jun 2009 03:19:40 +0000 (05:19 +0200)]
Fix two-pass stroking for \xbord, \ybord
The two-pass stroker blindly assumed that the number of points of
the stroked glyph is the same, no matter the size of the stroker.
Unfortunately, this is not the case every time. In such cases, the
coordinates will only be replaced up to mininum of points of both
glyphs. It's incredibly hacky, but seems to work well (and look good).
Grigori Goronzy [Mon, 29 Jun 2009 00:10:02 +0000 (02:10 +0200)]
Subpixel accurate shadow rendering
Shadows are handled different from glyph and outline. A shadow
is the sum of glyph and outline bitmap; therefore shifting to the
correct subpixel amount before rasterization is out of the question.
Instead, the bitmap is shifted by its subpixel amount after being
built from shadow and glyph.
The bitmap cache was extended for this.
Grigori Goronzy [Sat, 27 Jun 2009 20:28:22 +0000 (22:28 +0200)]
Support \xshad and \yshad override tags
Split up shadow displacement into x and y and allow parsing of the tags
\xshad and \yshad to set it. This makes it possible to displace a
shadow differently in x and y direction.
Grigori Goronzy [Sat, 27 Jun 2009 20:06:32 +0000 (22:06 +0200)]
Support \xbord and \ybord override tags
Improve get_outline_glyph with a second pass which can be used for
stroking with different width in x and y direction. This is done
by first stroking in y direction, and if the stroke size for the x
direction differs, stroking a copy of the glyph in x direction again.
The x coordinates of the first stroker result are afterwards replaced
by the coordinates of the second stroking.
The cache hash keys for bitmaps and glyphs have been extended to carry
the new properties.
Grigori Goronzy [Sat, 27 Jun 2009 13:20:28 +0000 (15:20 +0200)]
Fix memory leak in render_overlap
render_overlap allocated memory for its hashmap key and values on the
heap, relying on the cache cleanup to free them. However, these
pointers are not directly inserted into the cache, but memcpy()'ed in
hashmap_insert, leading to a pretty bad memory leak.
Allocate the key and value on the stack instead to fix this problem.
Grigori Goronzy [Sat, 27 Jun 2009 04:31:45 +0000 (06:31 +0200)]
Incorporate mputils.c into ass_utils.c
Move helper functions originating from MPlayer into ass_utils.c.
Remove some debugging code that is #if 0'ed for ages now. Delete
mputils.c and mputils.h and remove them from the build system.
Grigori Goronzy [Sat, 27 Jun 2009 04:38:49 +0000 (06:38 +0200)]
Improve positioning for full subpixel accuracy
Completely overhaul positioning for full subpixel accuracy (as much as
FreeType offers, 1/64 pixel) for all positioning/typesetting related
calculations and the final rendering.
Positions are now calculated with doubles. FreeType uses a fixed-point
26.6 representation internally. Where needed, these are converted into
double values as well.
Finally, for the on-screen rendering, a subpixel shift for the
rasterization is calculated (bitmaps cannot be rendered onto the video
with subpixel accuracy).
Grigori Goronzy [Wed, 24 Jun 2009 22:05:04 +0000 (00:05 +0200)]
Test program: nicer-looking background
Use a uniformly colored background in the test program. This looks
better than the randomly-looking pattern that was used before.
A chessboard pattern would be even better, but this will do for now.
Grigori Goronzy [Wed, 24 Jun 2009 21:48:05 +0000 (23:48 +0200)]
Correct vertical glyph positioning for \fay
Offset the next glyph by the total shear of the glyph before.
This is done before line-wrapping, so that a line that is vertically
sheared will get as much higher, as it is sheared. Fine by me, but
vsfilter probably does it in a different way.
greg [Tue, 23 Jun 2009 00:55:04 +0000 (02:55 +0200)]
Initial support for \fax, \fay override tags
This adds support for the \fax and \fay override tags which can be used
for shearing the text horizontally and vertically. At the moment, this
works correctly on a per-glyph basis, however, the glyph positioning is
wrong, which is especially evident with \fay.
Uoti Urpala [Fri, 19 Jun 2009 16:26:36 +0000 (19:26 +0300)]
Use safe hash functions for composite bitmaps
Previously the composite bitmap hash keys were compared and hashed
based on all the bytes in the struct, which could cause problems
because of padding bytes. Change the code to use field-by-field
operations as already done for other hash key types.
The composite hash key contains two bitmap hash keys. The hashing
function currently handles those by calling the function to calculate
the corresponding bitmap hash, and then updating the composite hash by
treating the result of the function call as a byte buffer. An
alternative would be to change the hash functions so that the initial
hash value could be passed as a parameter to the recursively called
function.
greg [Fri, 19 Jun 2009 05:34:03 +0000 (07:34 +0200)]
Add hack to support empty lines of text
Consecutive forced breaks (\N\N) can be used to create empty lines of
text in other renderers. This doesn't work with the current text
layouter (wrap_lines_smart). This hack inserts a space glyph between two
consecutive forced breaks to get around this limitation.
greg [Fri, 19 Jun 2009 03:33:40 +0000 (05:33 +0200)]
Remove wrappers for ass_set_fonts
ass_set_fonts_ was wrapped through ass_set_fonts and ass_set_fonts_nofc
to either use fontconfig or not. This is not very useful, since a simple
parameter to ass_set_fonts_ can be used instead. Remove the wrapper
functions and rename the real function to ass_set_fonts.
greg [Thu, 18 Jun 2009 12:16:07 +0000 (14:16 +0200)]
Fix up glyph stroker to avoid buggy rendering.
This adds pre-processing to the stroker which removes certain contours
that'd lead to areas wrongly getting not filled. The approach is very
simple, but works well enough for most cases.
greg [Fri, 19 Jun 2009 03:13:07 +0000 (05:13 +0200)]
From uau: libass: Fix cache lookup problem causing memory bloat
The cache code did hash lookups by storing key values in struct fields
and then hashing and comparing the struct as a single memory block. In
at least one case such a struct contained uninitialized padding bytes
which prevented the complete memory area of the struct from matching
even though the fields did. As a result the code failed to find
existing objects in the cache and stored new versions of them, causing
gigabytes of memory use in some circumstances. Initializing the struct
memory to zero before writing the fields avoided such memory use in
tests but is not guaranteed to work if I interpret the C standard
correctly (the compiler is allowed to write garbage over padding bytes
when changing struct member values).
Change the code to use struct-specific hashing and comparison
functions that work field by field to guarantee correct behavior.
Create these by replacing the struct definition with a template that
lists the fields and can be used the generate each of struct
definition, hash function and compare function with some preprocessor
magic (otherwise every field would need to be listed separately in all
three).
reimar [Sat, 28 Mar 2009 19:21:34 +0000 (19:21 +0000)]
Initialize all structs to 0 before using them.
This is consistent with the remaining code (which uses e.g. calloc) and makes
it easier to extend the structs in the future.
As a side effect it fixes several valgrind errors in hashmap_hash/hashmap_key_compare
caused by padding in the structures, but it is not a correct fix for that issue.