summaryrefslogtreecommitdiffstats
path: root/libass/ass_render_api.c
Commit message (Collapse)AuthorAgeFilesLines
* renderer: fix subtitles to full screen frame iff use_marginsOleg Oshmyan2020-07-051-6/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Based on a commit by wm4. Nowadays, margins are used by players such as mpv to implement video zoom & pan, although this was not expected when margins were first implemented in libass. This results in unpleasant rendering when panning too far, and it is argued that subtitles should not change size or move when panning and zooming at all. libass also makes an attempt to keep subtitles on screen even when the use of margins is disabled. This is unintuitive and prone to break. Fix this by strictly separating events which render as if they were part of the video, and events which should use margins. The latter will now use the entire screen as canvas, rather than using the video frame. This actually simplifies the various y2scr functions. To preserve scaling (mainly for styled subtitles where line breaks are carefully chosen based on font/video size ratio) and to avoid badly stretching out things like ASS Margins due to aspect ratio differences between video and screen, estimate the unpanned & unzoomed video size from the video aspect ratio and the screen size, and base all scaling on that. This means that if the user plays a video in letterboxed mode without extra margins, they get the same scaling as if they were playing the same video with the same video rectangle size without any margins at all (with some elements merely spaced out to make use of the black bars); and when they zoom & pan afterwards, the subtitles don't move or change size. This changes behavior even with ass_set_use_margins(_, 0). Before this, normal dialogue was forced into the visible video area (if negative margins were set); now it renders it as if it were part of the video. This also changes the behavior of left and right margins even with ass_set_use_margins(_, 1). Before this, normal dialogue was forced into the visible video width (with both positive and negative margins); now it renders across the entire width of the screen/window. For 4:3 video letterboxed on 16:9 screen, this means text will cross the edges of the video, which may look worse than before.
* ass_set_fonts: empty cache as wellRodger Combs2017-10-221-0/+4
|
* render_api: do not discard old images on reconfigurationwm42017-01-131-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I noticed that when resizing the mpv window while playback is ongoing and with subtitles, that subtitles could sometimes get "stuck" on the screen. The stuck subtitle would remain until the next subtitle event, or until seeking to a position that has subtitles again. It turned out that this was a libass change detection bug. The following steps should reproduce the problem: 1. call ass_render_frame() with a time that has subtitles 2. call ass_set_frame_size() with a different size 3. call ass_render_frame() with a time that has no subtitles The previous call will return with *detect_change==0. To make this worse, libass will deallocate image data before the next ass_render_frame() or ass_renderer_done(), which violates the API and could possibly make some API users crash. (That the user can rely on this is not documented though.) There are two possible solutions: 1. Set a flag in ass_reconfigure(), that makes the next ass_render_frame() call always return *detect_change==2. 2. Do not discard the previous subtitles (images_root), so change detection can work reliably. This commit implements 2. - I prefer this in part because it doesn't clobber the previously returned image list before the next ass_render_frame() call. (As pointed out above, this might be unexpected behavior to the API user.) This is a regression and was possibly broken by commit dd06ca and later. I did not check whether it actually behaved sanely before that change, but it probably did to a degree.
* api: make ass_set_cache_limits() work on total bitmap cache sizesDr.Smile2016-12-291-2/+12
| | | | | | Previously was possible to set only bitmap_max_size, now requested memory amount is divided between bitmap_max_size and composite_max_size.
* render: add refcounting functionality to image listsDr.Smile2016-06-301-2/+2
|
* render: keep track of any associated resources within ASS_ImageDr.Smile2016-06-301-2/+2
| | | | | That resources can be cached composite bitmap or raw bitmap buffer. Consequently, free lists are no longer needed.
* cache: switch to gradual cache clearingDr.Smile2016-06-301-3/+3
| | | | | | | | | | | Advantages over the old algorithm consist of the following. * There are no glitches due to full cache clearing. Items are arranged into linked list ordered by time of last use. Only the oldest items get deleted at the clearing event. * Each item now keeps track of number of references. Referenced cache values are immune to clearing. * Reduced amount of total cache memory for the same performance. * Reduced number of memory allocations per cache item.
* Fully fix compilation with MSVC/ICLOleg Oshmyan2015-09-171-0/+2
| | | | | | | | | As before, this does not add any build system support: a config.h file and a project must still be manually created (or the compiler can be run manually instead of using a project). Signed-off-by: Grigori Goronzy <greg@kinoho.net> Signed-off-by: Oleg Oshmyan <chortos@inbox.lv>
* render_api: fix crash when calling ass_set_fonts() after renderingwm42015-08-281-0/+2
| | | | | | | | | | The caches may reference data which belongs to the font provider. If the font selector and the font provider are destroyed, it can leave dangling pointers in the renderer cache. (At least that's what it looks like.) For some reason, this didn't even trigger valgrind warnings with the fontconfig font provider. Possibly the dangling pointers were FT_Face pointers, and fontconfig might cache these process-wide.
* ass: restore ABI compatibility with older versions (more or less)wm42015-08-281-1/+1
| | | | | | | | | | | While enums normally are ints on most systems, it isn't guaranteed. This might also make C++ code fail to compile, since C++ doesn't allow implicit conversion of ints to enums. If the API user ever passed anything other than 0 or 1, compatibility will still break, but I guess we have to live with this. Also extend the doxygen.
* fontselect: expose a fontprovider selection APIStefano Pigozzi2015-07-101-3/+3
| | | | | | | | | Allow the user of libass to select the font provider from ass_set_fonts. This API change actually doesn't break client code which was passing `fc=1`; now the same value will autodetect a usable font provider. Also add an api to list available font providers as that is useful for client code to show drop down menus with a font provider to choose from.
* Export font provider interfaceGrigori Goronzy2015-07-101-0/+7
| | | | | | | Add wrapper to the ASS_Renderer to create a font provider from its internal font selector and shuffle some code around to export everything that's needed for font providers to the public. Document font provider functions.
* Restore fontconfig runtime configurationGrigori Goronzy2015-07-101-2/+2
| | | | | | | | | | | Pass the fontconfig configuration file option and enable switch through into the font selector. This restores some of the old functionality related to fontconfig. However, the functionality to delay the fontconfig database update will not come back. This is not a big problem. Later it will be possible to manually add the fontconfig provider, which will delay the update in a comparable way.
* Custom font matching and font sourcesGrigori Goronzy2015-07-101-6/+6
| | | | | | | Implement a simple font sorter (FontSelector) and an interface to deal with multiple font sources (FontProvider). Unfinished business, but works for the most part. Currently the only implemented FontProvider uses fontconfig.
* Allow more fine grained control over style overrideswm42015-02-261-1/+0
| | | | | | | | Add tons of ASS_OVERRIDE_ flags, which control whether certain ASS_Style fields are copied when doing selective style overrides with ass_set_selective_style_override_enabled(). This comes with some cleanup. It should be fully backwards-compatible.
* Provide slightly more fine-grained control over style overrideswm42014-10-171-4/+3
|
* Add a mechanism for selective style overrideswm42014-06-051-0/+18
| | | | | | | | | | | | | | | This adds 2 new API functions: ass_set_selective_style_override() ass_set_selective_style_override_enabled() They can be used to force dialog text to use a specific ASS_Style. It uses a fuzzy heuristic for that, and the quality of results may vary. It does style overriding selectively and tries not to override things that need explicit styling. The heuristic for that isn't set in stone either, and can change with future libass versions. Closes libass#88.
* Simplify storage size handlingOleg Oshmyan2014-01-261-7/+0
| | | | No functional changes.
* Add ass_set_pixel_aspect(), deprecate ass_set_aspect_ratio()wm42013-03-291-1/+5
| | | | | | | | | | | | ass_set_aspect_ratio() is confusing, because it takes a DAR and SAR value, while libass just needs a single pixel aspect ratio. Introduce ass_set_pixel_aspect(), which sets the pixel aspect ratio directly. ass_set_aspect_ratio() is considered deprecated. There's no reason to remove it, but hopefully directing users to ass_set_pixel_aspect() will make for a simpler API. Improve the doxygen and document what ass_set_margins() actually does.
* Don't overwrite user-defined aspect ratio settingswm42013-03-291-13/+3
| | | | | | | | | | | | | | | | | | | | | ass_set_storage_size() overwrote the user-defined aspect ratio set with ass_set_aspect_ratio(). Change it so that if ass_set_aspect_ratio() is used, the ass_set_storage_size() parameters are not used for any aspect ratio calculations. (The storage size is still used for calculating the blur scale.) This simplifies the code as well, because the aspect ratio is now centrally calculated in ass_start_frame(). Update the doxygen. Make it clear that ass_set_storage_size() will be used for aspect ratio calculation, unless ass_set_aspect_ratio() is used. Also mention what libass actually does with the dar and sar parameters: it uses them to calculate a pixel aspect ratio, nothing else. Explicitly allow resetting the storage size with w=h=0. Document that it's allowed to remove the user defined aspect ratio by setting a pixel aspedct ratio of 0. See issue 6.
* Add ass_set_storage_size and fix related scaling issuesOleg Oshmyan2013-03-031-2/+25
| | | | | | | | \blur radius is not scaled from script to storage resolution but is scaled from storage to display resolution. The same applies to borders and shadows if ScaledBorderAndShadow is "no". (If it is "yes", borders and shadows are scaled from script to display resolution just like before.)
* Add ass_set_line_position() API function for subtitle positionwm42012-10-011-0/+8
| | | | | | | | This allows users to change the vertical position of normal subtitles. MPlayer has such a feature as -sub-pos option using its internal subtitle renderer. Bump LIBASS_VERSION to indicate the API addition.
* Add compile time switch for HarfBuzz supportGrigori Goronzy2011-08-081-0/+2
| | | | | | | | | | | | | Now that it's possible to switch shapers at runtime, it also becomes a lot easier to disable them at compile time. Add ifdefs and build system changes so that HarfBuzz can be safely disabled. It's autodetected now and enabled if available. This shuffles a bit of code around, but there are no functional changes. Note that FriBidi remains mandatory for the time being, but this shouldn't pose any problems, since it is a small and very portable library without any special dependencies.
* Runtime shaper selectionGrigori Goronzy2011-08-081-0/+9
| | | | | | | Add an API call, ass_set_shaper, and infrastructure to make shapers selectable at runtime. Currently, this allows to switch between two shapers: a SIMPLE shaper that maps to FriBidi and a COMPLEX shaper that maps to HarfBuzz.
* cache: unified outline cache for glyphs/drawingsGrigori Goronzy2011-06-271-1/+1
| | | | | | | | | Glyphs and drawings have wildly different hash keys. Subclass the hash keys of glyphs and drawings in a new, unified outline cache. This also fixes some issues with drawings in the glyph cache. Now, the textual description of the drawing is included in the key (the hash value isn't really good enough, especially not fnv32) and the baseline offset is saved as well.
* Much improved cache/hashmap implementationGrigori Goronzy2011-06-071-6/+3
| | | | | | | | - less code, cleaner - decoupled from ASS_Library - better data encapsulation - simpler interface - avoids a nasty hack
* Relicense to ISCGrigori Goronzy2010-09-281-12/+10
| | | | | | In hope to make libass as useful as possible, relicense libass to ISC, a simplified 2-clause BSD license. All contributors who provided non-trivial changes have granted their permission for this.
* refactor: move ASS_Renderer getters/setters/etc into separate fileGrigori Goronzy2010-08-011-0/+141