summaryrefslogtreecommitdiffstats
path: root/libass/ass_render.c
Commit message (Collapse)AuthorAgeFilesLines
* opaque box: do not subtract glyph from borderGrigori Goronzy2009-09-011-1/+2
| | | | | Similar to VSFilter, do not subtract the glyph bitmap from the border bitmap when BorderStyle 3 is used.
* Calculate glyph slant width correctlyGrigori Goronzy2009-08-311-4/+7
| | | | | | If a glyph is wider than its advance width for italic to non-italic style changes, assume it was obliqued by FreeType's FT_GlyphSlot_Oblique function and offset the next glyph accordingly.
* Fix order of pen advance assignmentsGrigori Goronzy2009-08-231-3/+3
|
* Fix opaque box sizing againGrigori Goronzy2009-08-231-7/+20
| | | | | | | | | Another try to get it to work like in VSFilter. Hopefully it's behaving the same now (except in some cases, since VSFilter layouts word-based, but libass is glyph-based). Additionally, make sure horizontal letter spacing (\fsp) is scaled according to ScaleX.
* Fix glyph overlap blendingGrigori Goronzy2009-08-231-14/+13
| | | | | | | | | | Use the bitmap pointer for the cache hash key. This preserves the blending history, which fixes occasional corruptions due to previous replacements not being dealt with correctly. It also simplifies the hash key a lot and thus speeds up cache lookups. Additionally, change the blending equation from max(a, b) to min(a + b, 0xff), i.e. a saturating addition. Usually this looks a lot better.
* Scale kerning according to x font scaling factorGrigori Goronzy2009-08-221-2/+4
|
* Trim whitespace after line wrappingGrigori Goronzy2009-08-221-6/+85
| | | | | Mark leading and trailing spaces on lines and adjust layouting code to respect these marks and skip the spaces.
* Clip vector blending: do not copy last row paddingGrigori Goronzy2009-08-201-1/+1
| | | | | | Do not copy the padding on the last row into the new buffer since we cannot rely on the padding actually existing; might fix a segfault in some obscure cases.
* Adjust shearing behavior to match VSFilterGrigori Goronzy2009-08-201-9/+15
| | | | | | | | 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.
* VSFilter quirk: double-scale widths of opaque boxesGrigori Goronzy2009-08-201-0/+5
| | | | | | | 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.
* Fix caching of underlined/striked out glyphsGrigori Goronzy2009-08-151-0/+2
|
* Implement wrap style 1Grigori Goronzy2009-08-141-5/+4
| | | | | Skip application of the algorithm that moves words between the lines to equalize line length for wrap style 1.
* Cosmetics: ass_render.c formattingGrigori Goronzy2009-08-141-19/+18
|
* Use event bbox for collision detectionGrigori Goronzy2009-08-131-6/+24
| | | | | | 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.
* Scale ascender/descender for opaque boxesGrigori Goronzy2009-08-131-0/+4
|
* Do not draw opaque box if border size zeroGrigori Goronzy2009-08-121-1/+3
| | | | This follows VSFilter's behavior.
* BorderStyle cache integrationGrigori Goronzy2009-08-121-0/+4
| | | | | Add new fields to the cache hash key for BorderStyle 3 (glyph cache and bitmap cache).
* Always parse colors as hex for ASS tracksGrigori Goronzy2009-08-121-3/+6
| | | | | | 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.
* Fix italic to non-italic space handlingGrigori Goronzy2009-08-121-4/+6
| | | | | | 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.
* Support \q override tagGrigori Goronzy2009-08-121-2/+10
| | | | | | 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.
* Implement BorderStyle 3Grigori Goronzy2009-08-121-3/+48
| | | | | | | 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.
* Fix advance for italic to non-italic style changesGrigori Goronzy2009-08-121-0/+9
| | | | | | | | | 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.
* Factor out renderer types into separate fileGrigori Goronzy2009-08-071-216/+1
|
* Rename typedefs (breaks API)Grigori Goronzy2009-08-061-219/+222
| | | | | | 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.
* Fix typoGrigori Goronzy2009-08-051-1/+1
|
* Clarify the AR parameter meaningsGrigori Goronzy2009-08-051-7/+7
| | | | Use the correct terms (SAR/DAR) for the aspect ratio parameters.
* Get rid of MAX_EVENTS limitGrigori Goronzy2009-07-301-3/+3
| | | | | Allocate the maximum possible number of used events in fix_collisions dynamically, eliminating the MAX_EVENTS limit.
* Do not round karaoke timing coordinatesGrigori Goronzy2009-07-291-2/+2
| | | | | | 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.
* Fix \k and \ko tagsGrigori Goronzy2009-07-281-2/+2
| | | | | | 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.
* Clean up typedefs/structsGrigori Goronzy2009-07-281-15/+15
| | | | | Remove useless _s suffix from struct names and remove struct name where not needed (only the typedef'd struct is used). Clean up API headers.
* Remove shift vector in ass_render_eventGrigori Goronzy2009-07-251-9/+3
| | | | | | | 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.
* Assume 4:3 AR when calculating missing PlayResX/YGrigori Goronzy2009-07-251-7/+2
| | | | | In case only one PlayResX/Y component is specified, calculate the other component by assuming a 4:3 aspect ratio. This is similar to vsfilter.
* Handle clip vector rasterizer errorsGrigori Goronzy2009-07-241-1/+8
| | | | | If rasterizing the clip vector fails, actually handle the situation instead of crashing.
* Fix renderer memory leaksGrigori Goronzy2009-07-241-3/+13
| | | | | | | | | | Use the correct free order when freeing a ass_renderer and make sure that the latest list of ass_images is freed, too. Protect the font family string against double free and make sure it is freed in free_render_context. Leaks and access problems were found by valgrind/memcheck.
* Move render_id into ass_rendererGrigori Goronzy2009-07-241-3/+1
| | | | | The render_id (last_render_id) variable was the last remaining static data object; move it into render_priv.
* Bold/italic: interpret -1 as "true"Grigori Goronzy2009-07-221-6/+6
| | | | | | 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".
* Do not double free default font/family buffersGrigori Goronzy2009-07-211-5/+0
| | | | Reported by Martin Sourada.
* Factor out bitmap buffer copyGrigori Goronzy2009-07-211-6/+16
| | | | | | | 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.
* Clamp clip rectangle to frame sizeGrigori Goronzy2009-07-211-4/+4
| | | | | Make sure the clip rectangle is inside the screen boundaries. Idea by Evgeniy Stepanov.
* Animations: allow equal start and end timeGrigori Goronzy2009-07-211-2/+2
| | | | | | 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.
* Fix borders when a x/y component is zeroGrigori Goronzy2009-07-191-1/+1
|
* Fix drawing parser memory leakGrigori Goronzy2009-07-191-1/+0
| | | | | Always free the drawing glyph in ass_drawing_free; do not double free clip vector bitmap.
* Introduce simple cache memory managementGrigori Goronzy2009-07-191-5/+39
| | | | | | | | | | | 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.
* Fix vertical centering (VALIGN_CENTER)Grigori Goronzy2009-07-191-1/+1
| | | | | | | 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.
* Fix ascender/descender calculation for empty linesGrigori Goronzy2009-07-191-5/+8
| | | | | Take ascender/descender from the last valid glyph when empty lines occur. This makes multiple empty lines (\N\N\N etc.) work correctly.
* Improve fontconfig setupGrigori Goronzy2009-07-171-4/+8
| | | | | | | 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.
* Clear free list on renderer uninitGrigori Goronzy2009-07-161-11/+17
| | | | | | 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.
* Implement vector clipsGrigori Goronzy2009-07-161-14/+212
| | | | | | | | | 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.
* Proper support for empty linesGrigori Goronzy2009-07-121-9/+8
| | | | | | | | 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.
* Check whether renderer and track use the same library instanceGrigori Goronzy2009-07-121-0/+3
| | | | | | 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.
* Message callback funtionalityGrigori Goronzy2009-07-111-52/+60
| | | | | | | | | | | 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]".
* Replace string defines with real stringsGrigori Goronzy2009-07-111-42/+39
| | | | | | Instead of referencing string defines from help_mp.h, use the strings directly in ass_msg. Consequently, help_mp.h is useless and can be deleted.
* Slight optimizations for \be, \blurGrigori Goronzy2009-07-101-1/+1
| | | | | | | 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.
* Use better method for stroking with \xbord, \ybordGrigori Goronzy2009-07-081-86/+62
| | | | | | | | | | | | | | | 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.
* Turn down subpixel accuracy to 1/8th pixelGrigori Goronzy2009-07-081-3/+4
| | | | | | | 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.
* Support for underline and strikethroughGrigori Goronzy2009-07-071-1/+19
| | | | | | | | | | | | | | | | | 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.
* Implement drawing mode (\p)Grigori Goronzy2009-07-061-40/+110
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Scale letter spacing with font scaleGrigori Goronzy2009-07-011-1/+2
|
* Scale rotation constants with font scaleGrigori Goronzy2009-07-011-10/+15
| | | | | | | | 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.
* Assume pixel ratio equals aspect ratioGrigori Goronzy2009-07-011-1/+3
| | | | | | 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.
* Support for \iclip (inverse clipping)Grigori Goronzy2009-06-301-2/+127
| | | | | | | | | 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.
* Fix karaoke (\kf) timingGrigori Goronzy2009-06-301-3/+3
| | | | | | 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.
* Move subpixel shift out of transform_3dGrigori Goronzy2009-06-291-10/+19
| | | | | | 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).
* PAR correction for rendering at non-video resolutionGrigori Goronzy2009-06-291-3/+7
| | | | | | | | | | | | | | | 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.
* Fix two-pass stroking for \xbord, \ybordGrigori Goronzy2009-06-291-2/+3
| | | | | | | | 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).
* Handle conflicting \t time intervalsGrigori Goronzy2009-06-291-2/+2
| | | | | If end <= start for a time interval specification, set end to the end of the event. VSFilter handles it like that, too.
* Subpixel accurate shadow renderingGrigori Goronzy2009-06-291-4/+14
| | | |