Grigori Goronzy [Thu, 20 Aug 2009 02:36:47 +0000 (04:36 +0200)]
Adjust shearing behavior to match VSFilter
Make horizontal shearing (\fax) shear from top to bottom of a glyph;
scale shearing factors with horizontal and vertical scaling factors.
This makes the shearing operations similar to VSFilter, except for
\fay in some cases, but this is not unexpected. Vertical shearing
is implemented different on purpose.
Grigori Goronzy [Wed, 19 Aug 2009 21:10:24 +0000 (23:10 +0200)]
VSFilter quirk: double-scale widths of opaque boxes
VSFilter double-scales the widths of the opaque box in X direction,
which gives much wider boxes than expected (or much less wider boxes)
if ScaleX != 100. Emulate this behavior, even if it is unbelievably
stupid and no doubt a bug in VSFilter.
Grigori Goronzy [Sat, 15 Aug 2009 01:31:52 +0000 (03:31 +0200)]
Improve and fix outline striker
Exit early if no striking is needed; make sure to strike in reverse
direction for non-truetype font and use the usual return value
convention (0 == no errors).
Grigori Goronzy [Wed, 12 Aug 2009 23:08:22 +0000 (01:08 +0200)]
Use event bbox for collision detection
Consider the bounding box of an event for collision detection instead
of only its vertical position and height. This allows multiple events
per line if they don't overlap.
Grigori Goronzy [Wed, 12 Aug 2009 04:20:26 +0000 (06:20 +0200)]
Always parse colors as hex for ASS tracks
According to the ASS specification, colors can only be specified in hex.
Modify the color parsing accordingly; this especially means that colors
where the hex sigil (the "H") is missing can now be parsed.
Grigori Goronzy [Wed, 12 Aug 2009 03:26:55 +0000 (05:26 +0200)]
Add glyph emboldening fallback
Fallback to embolden manually with FreeType in case a bold face was
requested, but no bold variant is available. The glyphs are slightly
emboldened (much less than FT_GlyphSlot_Embolden would do) and the
metrics are not touched at all.
Grigori Goronzy [Wed, 12 Aug 2009 03:07:13 +0000 (05:07 +0200)]
Fix italic to non-italic space handling
Scan backwards in the glyph array for a glyph with some actual points
when correctin glyph spacing after italic to non-italic style changes.
This is mostly useful in case a space ends italicized text.
Grigori Goronzy [Wed, 12 Aug 2009 01:43:46 +0000 (03:43 +0200)]
Support \q override tag
Parse \q override tag and set a new state variable to its value.
The line wrapping code still needs improvements; wrap style 0/3 are not
entirely correctly implemented and style 1 is not implemented.
Grigori Goronzy [Wed, 12 Aug 2009 00:59:00 +0000 (02:59 +0200)]
Implement BorderStyle 3
The "opaque box" border style renders an opaque box in the glyph area
instead of rendering a regular stroked border. This implementation
replaces the glyph outline by an outline that contains only one
rectangle with the size of the glyph, plus optional extra border.
Grigori Goronzy [Tue, 11 Aug 2009 23:45:39 +0000 (01:45 +0200)]
Fix advance for italic to non-italic style changes
After a italic to non-italic style change the space between the glyphs
is sometimes wrongly calculated, especially if the font doesn't have
an italic version and FreeType falls back to oblique glyphs.
In such cases, add additional space to the glyph's advance to make up
for the slant of the glyph; the amount is calculated from the glyph's
bbox.
Grigori Goronzy [Thu, 6 Aug 2009 11:04:20 +0000 (13:04 +0200)]
Rename typedefs (breaks API)
Rename all typedefs from the convention foo_bar_t, which can possibly
conflict with POSIX types, to FooBar (and ASS_FooBar for public
API typedefs). Fix formatting and stray comments while at it.
Grigori Goronzy [Wed, 29 Jul 2009 19:33:29 +0000 (21:33 +0200)]
Do not round karaoke timing coordinates
Do not round the coordinates of the glyph bbox (when converting 26.6
fixed-point to integer); they are used for timing karaoke. Doing so
can sometimes make \k and \ko karaoke not apply correctly.
Grigori Goronzy [Tue, 28 Jul 2009 09:05:26 +0000 (11:05 +0200)]
Fix \k and \ko tags
The timing calculations for \k and \ko were off and still assumed
int values for a bbox, while it now uses a d6 representation.
This essentially made duration about 64 times as long as it should be.
Grigori Goronzy [Sun, 26 Jul 2009 14:03:37 +0000 (16:03 +0200)]
Improve message callback API
Instead of passing a pointer to a va_list, pass the va_list itself.
Additionally, use const char for the format string and use names in
the prototype that describe the arguments' meaning.
Grigori Goronzy [Sat, 25 Jul 2009 01:59:58 +0000 (03:59 +0200)]
Remove shift vector in ass_render_event
The shift is not calculated when fetching a glyph anymore. Instead,
it is calculated right before rasterizing a glyph. Remove the
shift vector and make get_outline_glyph, the glyph cache and
ass_font_set_transform work without supplying a shift vector.
Grigori Goronzy [Fri, 24 Jul 2009 08:01:41 +0000 (10:01 +0200)]
Fix fontconfig memory leaks
Do not manually use FcConfigFilename; passing a NULL pointer to
FcConfigParseAndLoad is just as effective and also avoids a memory leak
since the string allocated by FcConfigFilename was never freed.
Free FcConfig instance in fontconfig_done; since we're not using the
default configuration anymore it doesn't make sense to keep the
configuration around.
Grigori Goronzy [Wed, 22 Jul 2009 20:49:55 +0000 (22:49 +0200)]
Fallback to default fontconfig configuration
If parsing or loading the fontconfig configuration file, either
using the default or a specified one, fails, try to load the
default fontconfig configuration. This triggers loading a fallback
configuration if no configuration file is available at all. A warning
message is emitted to notify the user about this.
Grigori Goronzy [Wed, 22 Jul 2009 01:24:42 +0000 (03:24 +0200)]
Fix rasterizer error handling (double free)
In case rasterizing a glyph is successful, but rasterizing its outline
is not, do not free the glyph bitmap. It will be freed in cache cleanup
later. Freeing it earlier leads to a double free.
Grigori Goronzy [Wed, 22 Jul 2009 01:21:33 +0000 (03:21 +0200)]
Bold/italic: interpret -1 as "true"
Interpret the value -1 as "true", as specified in the ASS
specifications. Otherwise, clamp the value to 0 for other values <
0, so these are interpreted as "false".
Grigori Goronzy [Tue, 21 Jul 2009 01:06:05 +0000 (03:06 +0200)]
Factor out bitmap buffer copy
For clarity, factor out bitmap copying into a function. Do not pad the
bitmap with stride in the last row; this can not by guaranteed anyway.
Add a comment about this peculiarity to the API documentation in ass.h
Idea by Evgeniy Stepanov.
Grigori Goronzy [Mon, 20 Jul 2009 22:04:24 +0000 (00:04 +0200)]
Animations: allow equal start and end time
Do not set the end time of the animation to the end time of the event
in case end time and start time specified in a \t tag are equal.
This should sort out a problem introduced by commit 1f176b.
Grigori Goronzy [Sun, 19 Jul 2009 22:25:27 +0000 (00:25 +0200)]
Check for table availability when striking a glyph
The glyph striker (underline/strike-through) did not check for table
availability, possibly accessing a NULL pointer. Change this to
only strike the glyph if the table with the appropriate information
is available. Currently there is no fallback for fonts without the
required information.
Grigori Goronzy [Sun, 19 Jul 2009 06:38:49 +0000 (08:38 +0200)]
Introduce simple cache memory management
libass' cache was basically unmanaged; it would grow without any limits,
depending on how complex the subtitles are. Introduce a simple limiting
that resets the cache if certain limits are exceeded. The bitmap cache
is limited to approx. 50 MB size by default, while the glyph cache
allows storing up to 1000 glyphs by default. A few tests with rather
heavily softsubbed fansubs show that these limits are fine.
The API was extended with the function ass_set_cache_limits which allows
modification of these limits.
Grigori Goronzy [Sun, 19 Jul 2009 03:44:06 +0000 (05:44 +0200)]
Fix vertical centering (VALIGN_CENTER)
Match VSFilter behavior when centering non-positioned events
vertically. Previously, libass put the event on top of the vertical
center while VSFilter centered the event evenly. Adjust the centering
to behave like VSFilter.
Grigori Goronzy [Fri, 17 Jul 2009 12:39:20 +0000 (14:39 +0200)]
Improve API headers and documentation
Improve APi documentation; each function is properly documented now.
Add a new macro LIBASS_VERSION that encodes the version in a
hexadecimal format, similar to OpenSSL. Fix formatting of the headers.
Grigori Goronzy [Fri, 17 Jul 2009 00:56:05 +0000 (02:56 +0200)]
Improve fontconfig setup
Add an argument to ass_set_fonts for controlling whether the fontconfig
font cache should be built/updated. Add a new function ass_fonts_update
to make it possible to update fonts later on.
Additionally, stop using FcConfigSetDefault for thread safety.
Grigori Goronzy [Thu, 16 Jul 2009 18:57:39 +0000 (20:57 +0200)]
Clear free list on renderer uninit
The vector clip support introduced a free list that gets freed on
every new frame. Factor out the code for freeing it into a separate
function and make sure it is called when uniniting the ass_renderer.
Grigori Goronzy [Thu, 16 Jul 2009 00:17:06 +0000 (02:17 +0200)]
Implement vector clips
Make it possible to use drawings for clipping with \clip and \iclip.
parse_tag was extended to parse drawings in \clip or \iclip tags in case
parsing them as rectangular clips fails. These clip drawings are later
rasterized and used for blending bitmaps, just after bitmaps are
assembled into a list in render_text. Currently, the cache is not
utilized for storing the parsed drawings or blended bitmaps.
Grigori Goronzy [Mon, 13 Jul 2009 20:21:51 +0000 (22:21 +0200)]
Rework build system
* Remove checks for functions or headers that are part of ANSI C
or C89.
* Make enca optional.
* Conditionally compile the test program depending on libpng
availability.
Grigori Goronzy [Sun, 12 Jul 2009 20:58:23 +0000 (22:58 +0200)]
Proper support for empty lines
Calculate the line height of empty lines the VSFilter way in
measure_text; curiously, VSFilter sets the height of an empty line
to half the height of the line before.
Remove the hack that created empty lines by inserting spaces--it was
wrong anyway.
Grigori Goronzy [Sun, 12 Jul 2009 06:01:23 +0000 (08:01 +0200)]
Allow passing user data to callback
It is often useful or necessary to pass custom data to a callback.
Add an argument to the callback registering function to pass a void
pointer object to the callback each time it is called.
Grigori Goronzy [Sun, 12 Jul 2009 05:21:52 +0000 (07:21 +0200)]
Merge glyph and outline bitmap better
Use a different threshold for merging the outline and glyph and also
adjust the merge amount. This fails to give complete transparency (and
thus will yield slightly darker looking glyphs, usually), but avoids
very ugly looking artefacts at the edge between border and glyph that
were still prevalent.
Grigori Goronzy [Sun, 12 Jul 2009 04:56:48 +0000 (06:56 +0200)]
Redo border calculations for \be and \blur
The last commit related to this overdid it a bit -- in some cases,
with \be5, for example, edges were visible on the outlines. Instead of
using a linear function to map \be applications to border enlargement
value, use a nonlinear function, a simple square root. This seems to
work a lot better, while keeping the enlargement small.
In addition, make it possible to use \be and \blur at the same time. \be
is applied first.
Grigori Goronzy [Sun, 12 Jul 2009 03:42:57 +0000 (05:42 +0200)]
Check whether renderer and track use the same library instance
Add a sanity check to ass_start_frame that checks whether the track that
is currently rendered from and the ass_renderer use the same library
instance.
Grigori Goronzy [Sat, 11 Jul 2009 00:38:21 +0000 (02:38 +0200)]
configure: use pkg-config for libpng, enca
Use pkg-config to check for enca and libpng, like it is already done
for freetype and fontconfig.
Also, use libass/ass.c instead of the test program, test/test.cpp,
as the unique source identification.
Grigori Goronzy [Sat, 11 Jul 2009 00:18:51 +0000 (02:18 +0200)]
Message callback funtionality
Introduce functionality for providing a message callback that is used
for passing messages to the controlling application instead of simply
printing them to standard output. The function pointer to the callback
is stored in the ass_library_t instance. ass_msg needs access to it, so
in many places the library instance needs to be passed around now.
The default behavior is the old one: messages of MSGL_INFO or lower
are printed to the standard output, prefixed with "[ass]".
Grigori Goronzy [Fri, 10 Jul 2009 17:31:07 +0000 (19:31 +0200)]
Slight optimizations for \be, \blur
Enlarge bitmap glyphs less for \be, this is especially effective for
lots of \be applications.
Also make sure that the gaussian blur buffers are only updated if
gaussian blur is actually used for a particular glyph.
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).