ass.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. /*
  2. * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
  3. * Copyright (C) 2011 Grigori Goronzy <greg@chown.ath.cx>
  4. *
  5. * This file is part of libass.
  6. *
  7. * Permission to use, copy, modify, and distribute this software for any
  8. * purpose with or without fee is hereby granted, provided that the above
  9. * copyright notice and this permission notice appear in all copies.
  10. *
  11. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  12. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  13. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  14. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  15. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  16. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  17. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #ifndef LIBASS_ASS_H
  20. #define LIBASS_ASS_H
  21. #include <stdio.h>
  22. #include <stdarg.h>
  23. #include "ass_types.h"
  24. #define LIBASS_VERSION 0x01502000
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. #if (defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))) || defined(__clang__)
  29. #define ASS_DEPRECATED(msg) __attribute__((deprecated(msg)))
  30. #if __GNUC__ > 5 || defined(__clang__)
  31. #define ASS_DEPRECATED_ENUM(msg) __attribute__((deprecated(msg)))
  32. #else
  33. #define ASS_DEPRECATED_ENUM(msg)
  34. #endif
  35. #elif defined(_MSC_VER)
  36. #define ASS_DEPRECATED(msg) __declspec(deprecated(msg))
  37. #define ASS_DEPRECATED_ENUM(msg)
  38. #else
  39. #define ASS_DEPRECATED(msg)
  40. #define ASS_DEPRECATED_ENUM(msg)
  41. #endif
  42. /*
  43. * A linked list of images produced by an ass renderer.
  44. *
  45. * These images have to be rendered in-order for the correct screen
  46. * composition. The libass renderer clips these bitmaps to the frame size.
  47. * w/h can be zero, in this case the bitmap should not be rendered at all.
  48. * The last bitmap row is not guaranteed to be padded up to stride size,
  49. * e.g. in the worst case a bitmap has the size stride * (h - 1) + w.
  50. */
  51. typedef struct ass_image {
  52. int w, h; // Bitmap width/height
  53. int stride; // Bitmap stride
  54. unsigned char *bitmap; // 1bpp stride*h alpha buffer
  55. // Note: the last row may not be padded to
  56. // bitmap stride!
  57. uint32_t color; // Bitmap color and alpha, RGBA
  58. int dst_x, dst_y; // Bitmap placement inside the video frame
  59. struct ass_image *next; // Next image, or NULL
  60. enum {
  61. IMAGE_TYPE_CHARACTER,
  62. IMAGE_TYPE_OUTLINE,
  63. IMAGE_TYPE_SHADOW
  64. } type;
  65. // New fields can be added here in new ABI-compatible library releases.
  66. } ASS_Image;
  67. /*
  68. * Hinting type. (see ass_set_hinting below)
  69. *
  70. * Setting hinting to anything but ASS_HINTING_NONE will put libass in a mode
  71. * that reduces compatibility with vsfilter and many ASS scripts. The main
  72. * problem is that hinting conflicts with smooth scaling, which precludes
  73. * animations and precise positioning.
  74. *
  75. * In other words, enabling hinting might break some scripts severely.
  76. *
  77. * FreeType's native hinter is still buggy sometimes and it is recommended
  78. * to use the light autohinter, ASS_HINTING_LIGHT, instead. For best
  79. * compatibility with problematic fonts, disable hinting.
  80. */
  81. typedef enum {
  82. ASS_HINTING_NONE = 0,
  83. ASS_HINTING_LIGHT,
  84. ASS_HINTING_NORMAL,
  85. ASS_HINTING_NATIVE
  86. } ASS_Hinting;
  87. /**
  88. * \brief Text shaping levels.
  89. *
  90. * SIMPLE is a fast, font-agnostic shaper that can do only substitutions.
  91. * COMPLEX is a slower shaper using OpenType for substitutions and positioning.
  92. *
  93. * libass uses the best shaper available by default.
  94. */
  95. typedef enum {
  96. ASS_SHAPING_SIMPLE = 0,
  97. ASS_SHAPING_COMPLEX
  98. } ASS_ShapingLevel;
  99. /**
  100. * \brief Style override options. See
  101. * ass_set_selective_style_override_enabled() for details.
  102. */
  103. typedef enum {
  104. /**
  105. * Default mode (with no other bits set). All selective override features
  106. * as well as the style set with ass_set_selective_style_override() are
  107. * disabled, but traditional overrides like ass_set_font_scale() are
  108. * applied unconditionally.
  109. */
  110. ASS_OVERRIDE_DEFAULT = 0,
  111. /**
  112. * Apply the style as set with ass_set_selective_style_override() on events
  113. * which look like dialogue. Other style overrides are also applied this
  114. * way, except ass_set_font_scale(). How ass_set_font_scale() is applied
  115. * depends on the ASS_OVERRIDE_BIT_SELECTIVE_FONT_SCALE flag.
  116. *
  117. * This is equivalent to setting all of the following bits:
  118. *
  119. * ASS_OVERRIDE_BIT_FONT_NAME
  120. * ASS_OVERRIDE_BIT_FONT_SIZE_FIELDS
  121. * ASS_OVERRIDE_BIT_COLORS
  122. * ASS_OVERRIDE_BIT_BORDER
  123. * ASS_OVERRIDE_BIT_ATTRIBUTES
  124. */
  125. ASS_OVERRIDE_BIT_STYLE = 1 << 0,
  126. /**
  127. * Apply ass_set_font_scale() only on events which look like dialogue.
  128. * If not set, the font scale is applied to all events. (The behavior and
  129. * name of this flag are unintuitive, but exist for compatibility)
  130. */
  131. ASS_OVERRIDE_BIT_SELECTIVE_FONT_SCALE = 1 << 1,
  132. /**
  133. * Old alias for ASS_OVERRIDE_BIT_SELECTIVE_FONT_SCALE. Deprecated. Do not use.
  134. */
  135. ASS_OVERRIDE_BIT_FONT_SIZE ASS_DEPRECATED_ENUM("replaced by ASS_OVERRIDE_BIT_SELECTIVE_FONT_SCALE") = 1 << 1,
  136. /**
  137. * On dialogue events override: FontSize, Spacing, Blur, ScaleX, ScaleY
  138. */
  139. ASS_OVERRIDE_BIT_FONT_SIZE_FIELDS = 1 << 2,
  140. /**
  141. * On dialogue events override: FontName, treat_fontname_as_pattern
  142. */
  143. ASS_OVERRIDE_BIT_FONT_NAME = 1 << 3,
  144. /**
  145. * On dialogue events override: PrimaryColour, SecondaryColour, OutlineColour, BackColour
  146. */
  147. ASS_OVERRIDE_BIT_COLORS = 1 << 4,
  148. /**
  149. * On dialogue events override: Bold, Italic, Underline, StrikeOut
  150. */
  151. ASS_OVERRIDE_BIT_ATTRIBUTES = 1 << 5,
  152. /**
  153. * On dialogue events override: BorderStyle, Outline, Shadow
  154. */
  155. ASS_OVERRIDE_BIT_BORDER = 1 << 6,
  156. /**
  157. * On dialogue events override: Alignment
  158. */
  159. ASS_OVERRIDE_BIT_ALIGNMENT = 1 << 7,
  160. /**
  161. * On dialogue events override: MarginL, MarginR, MarginV
  162. */
  163. ASS_OVERRIDE_BIT_MARGINS = 1 << 8,
  164. /**
  165. * Unconditionally replace all fields of all styles with the one provided
  166. * with ass_set_selective_style_override().
  167. * Does not apply ASS_OVERRIDE_BIT_SELECTIVE_FONT_SCALE.
  168. * Add ASS_OVERRIDE_BIT_FONT_SIZE_FIELDS and ASS_OVERRIDE_BIT_BORDER if
  169. * you want FontSize, Spacing, Outline, Shadow to be scaled to the script
  170. * resolution given by the ASS_Track.
  171. */
  172. ASS_OVERRIDE_FULL_STYLE = 1 << 9,
  173. /**
  174. * On dialogue events override: Justify
  175. */
  176. ASS_OVERRIDE_BIT_JUSTIFY = 1 << 10,
  177. // New enum values can be added here in new ABI-compatible library releases.
  178. } ASS_OverrideBits;
  179. /**
  180. * \brief Return the version of library. This returns the value LIBASS_VERSION
  181. * was set to when the library was compiled.
  182. * \return library version
  183. */
  184. int ass_library_version(void);
  185. /**
  186. * \brief Default Font provider to load fonts in libass' database
  187. *
  188. * NONE don't use any default font provider for font lookup
  189. * AUTODETECT use the first available font provider
  190. * CORETEXT force a CoreText based font provider (OS X only)
  191. * FONTCONFIG force a Fontconfig based font provider
  192. *
  193. * libass uses the best shaper available by default.
  194. */
  195. typedef enum {
  196. ASS_FONTPROVIDER_NONE = 0,
  197. ASS_FONTPROVIDER_AUTODETECT = 1,
  198. ASS_FONTPROVIDER_CORETEXT,
  199. ASS_FONTPROVIDER_FONTCONFIG,
  200. ASS_FONTPROVIDER_DIRECTWRITE,
  201. } ASS_DefaultFontProvider;
  202. typedef enum {
  203. /**
  204. * Enable libass extensions that would display ASS subtitles incorrectly.
  205. * These may be useful for applications, which use libass as renderer for
  206. * subtitles converted from another format, or which use libass for other
  207. * purposes that do not involve actual ASS subtitles authored for
  208. * distribution.
  209. */
  210. ASS_FEATURE_INCOMPATIBLE_EXTENSIONS,
  211. /**
  212. * Match bracket pairs in bidirectional text according to the revised
  213. * Unicode Bidirectional Algorithm introduced in Unicode 6.3.
  214. * This is incompatible with VSFilter and disabled by default.
  215. *
  216. * (Directional isolates, also introduced in Unicode 6.3,
  217. * are unconditionally processed when FriBidi is new enough.)
  218. *
  219. * This feature may be unavailable at runtime (ass_track_set_feature
  220. * may return -1) if libass was compiled against old FriBidi.
  221. */
  222. ASS_FEATURE_BIDI_BRACKETS,
  223. // New enum values can be added here in new ABI-compatible library releases.
  224. } ASS_Feature;
  225. /**
  226. * \brief Initialize the library.
  227. * \return library handle or NULL if failed
  228. */
  229. ASS_Library *ass_library_init(void);
  230. /**
  231. * \brief Finalize the library
  232. * \param priv library handle
  233. */
  234. void ass_library_done(ASS_Library *priv);
  235. /**
  236. * \brief Set additional fonts directory.
  237. * Optional directory that will be scanned for fonts recursively. The fonts
  238. * found are used for font lookup.
  239. * NOTE: A valid font directory is not needed to support embedded fonts.
  240. *
  241. * \param priv library handle
  242. * \param fonts_dir directory with additional fonts
  243. */
  244. void ass_set_fonts_dir(ASS_Library *priv, const char *fonts_dir);
  245. /**
  246. * \brief Whether fonts should be extracted from track data.
  247. * \param priv library handle
  248. * \param extract whether to extract fonts
  249. */
  250. void ass_set_extract_fonts(ASS_Library *priv, int extract);
  251. /**
  252. * \brief Register style overrides with a library instance.
  253. * The overrides should have the form [Style.]Param=Value, e.g.
  254. * SomeStyle.Font=Arial
  255. * ScaledBorderAndShadow=yes
  256. *
  257. * \param priv library handle
  258. * \param list NULL-terminated list of strings
  259. */
  260. void ass_set_style_overrides(ASS_Library *priv, char **list);
  261. /**
  262. * \brief Explicitly process style overrides for a track.
  263. * \param track track handle
  264. */
  265. void ass_process_force_style(ASS_Track *track);
  266. /**
  267. * \brief Register a callback for debug/info messages.
  268. * If a callback is registered, it is called for every message emitted by
  269. * libass. The callback receives a format string and a list of arguments,
  270. * to be used for the printf family of functions. Additionally, a log level
  271. * from 0 (FATAL errors) to 7 (verbose DEBUG) is passed. Usually, level 5
  272. * should be used by applications.
  273. * If no callback is set, all messages level < 5 are printed to stderr,
  274. * prefixed with [ass].
  275. *
  276. * \param priv library handle
  277. * \param msg_cb pointer to callback function
  278. * \param data additional data, will be passed to callback
  279. */
  280. void ass_set_message_cb(ASS_Library *priv, void (*msg_cb)
  281. (int level, const char *fmt, va_list args, void *data),
  282. void *data);
  283. /**
  284. * \brief Initialize the renderer.
  285. * \param priv library handle
  286. * \return renderer handle or NULL if failed
  287. */
  288. ASS_Renderer *ass_renderer_init(ASS_Library *);
  289. /**
  290. * \brief Finalize the renderer.
  291. * \param priv renderer handle
  292. */
  293. void ass_renderer_done(ASS_Renderer *priv);
  294. /**
  295. * \brief Set the frame size in pixels, including margins.
  296. * The renderer will never return images that are outside of the frame area.
  297. * The value set with this function can influence the pixel aspect ratio used
  298. * for rendering. If the frame size doesn't equal to the video size, you may
  299. * have to use ass_set_pixel_aspect().
  300. * @see ass_set_pixel_aspect()
  301. * @see ass_set_margins()
  302. * \param priv renderer handle
  303. * \param w width
  304. * \param h height
  305. */
  306. void ass_set_frame_size(ASS_Renderer *priv, int w, int h);
  307. /**
  308. * \brief Set the source image size in pixels.
  309. * This is used to calculate the source aspect ratio and the blur scale.
  310. * The source image size can be reset to default by setting w and h to 0.
  311. * The value set with this function can influence the pixel aspect ratio used
  312. * for rendering.
  313. * @see ass_set_pixel_aspect()
  314. * \param priv renderer handle
  315. * \param w width
  316. * \param h height
  317. */
  318. void ass_set_storage_size(ASS_Renderer *priv, int w, int h);
  319. /**
  320. * \brief Set shaping level. This is merely a hint, the renderer will use
  321. * whatever is available if the request cannot be fulfilled.
  322. * \param level shaping level
  323. */
  324. void ass_set_shaper(ASS_Renderer *priv, ASS_ShapingLevel level);
  325. /**
  326. * \brief Set frame margins. These values may be negative if pan-and-scan
  327. * is used. The margins are in pixels. Each value specifies the distance from
  328. * the video rectangle to the renderer frame. If a given margin value is
  329. * positive, there will be free space between renderer frame and video area.
  330. * If a given margin value is negative, the frame is inside the video, i.e.
  331. * the video has been cropped.
  332. *
  333. * The renderer will try to keep subtitles inside the frame area. If possible,
  334. * text is layout so that it is inside the cropped area. Subtitle events
  335. * that can't be moved are cropped against the frame area.
  336. *
  337. * ass_set_use_margins() can be used to allow libass to render subtitles into
  338. * the empty areas if margins are positive, i.e. the video area is smaller than
  339. * the frame. (Traditionally, this has been used to show subtitles in
  340. * the bottom "black bar" between video bottom screen border when playing 16:9
  341. * video on a 4:3 screen.)
  342. *
  343. * When using this function, it is recommended to calculate and set your own
  344. * aspect ratio with ass_set_pixel_aspect(), as the defaults won't make any
  345. * sense.
  346. * @see ass_set_pixel_aspect()
  347. * \param priv renderer handle
  348. * \param t top margin
  349. * \param b bottom margin
  350. * \param l left margin
  351. * \param r right margin
  352. */
  353. void ass_set_margins(ASS_Renderer *priv, int t, int b, int l, int r);
  354. /**
  355. * \brief Whether margins should be used for placing regular events.
  356. * \param priv renderer handle
  357. * \param use whether to use the margins
  358. */
  359. void ass_set_use_margins(ASS_Renderer *priv, int use);
  360. /**
  361. * \brief Set pixel aspect ratio correction.
  362. * This is the ratio of pixel width to pixel height.
  363. *
  364. * Generally, this is (s_w / s_h) / (d_w / d_h), where s_w and s_h is the
  365. * video storage size, and d_w and d_h is the video display size. (Display
  366. * and storage size can be different for anamorphic video, such as DVDs.)
  367. *
  368. * If the pixel aspect ratio is 0, or if the aspect ratio has never been set
  369. * by calling this function, libass will calculate a default pixel aspect ratio
  370. * out of values set with ass_set_frame_size() and ass_set_storage_size(). Note
  371. * that this is useful only if the frame size corresponds to the video display
  372. * size. Keep in mind that the margins set with ass_set_margins() are ignored
  373. * for aspect ratio calculations as well.
  374. * If the storage size has not been set, a pixel aspect ratio of 1 is assumed.
  375. * \param priv renderer handle
  376. * \param par pixel aspect ratio (1.0 means square pixels, 0 means default)
  377. */
  378. void ass_set_pixel_aspect(ASS_Renderer *priv, double par);
  379. /**
  380. * \brief Set aspect ratio parameters.
  381. * This calls ass_set_pixel_aspect(priv, dar / sar).
  382. * @deprecated New code should use ass_set_pixel_aspect().
  383. * \param priv renderer handle
  384. * \param dar display aspect ratio (DAR), prescaled for output PAR
  385. * \param sar storage aspect ratio (SAR)
  386. */
  387. ASS_DEPRECATED("use 'ass_set_pixel_aspect' instead") void ass_set_aspect_ratio(ASS_Renderer *priv, double dar, double sar);
  388. /**
  389. * \brief Set a fixed font scaling factor.
  390. * \param priv renderer handle
  391. * \param font_scale scaling factor, default is 1.0
  392. */
  393. void ass_set_font_scale(ASS_Renderer *priv, double font_scale);
  394. /**
  395. * \brief Set font hinting method.
  396. * \param priv renderer handle
  397. * \param ht hinting method
  398. */
  399. void ass_set_hinting(ASS_Renderer *priv, ASS_Hinting ht);
  400. /**
  401. * \brief Set line spacing. Will not be scaled with frame size.
  402. * \param priv renderer handle
  403. * \param line_spacing line spacing in pixels
  404. */
  405. void ass_set_line_spacing(ASS_Renderer *priv, double line_spacing);
  406. /**
  407. * \brief Set vertical line position.
  408. * \param priv renderer handle
  409. * \param line_position vertical line position of subtitles in percent
  410. * (0-100: 0 = on the bottom (default), 100 = on top)
  411. */
  412. void ass_set_line_position(ASS_Renderer *priv, double line_position);
  413. /**
  414. * \brief Get the list of available font providers. The output array
  415. * is allocated with malloc and can be released with free(). If an
  416. * allocation error occurs, size is set to (size_t)-1.
  417. * \param priv library handle
  418. * \param providers output, list of default providers (malloc'ed array)
  419. * \param size output, number of providers
  420. * \return list of available font providers (user owns the returned array)
  421. */
  422. void ass_get_available_font_providers(ASS_Library *priv,
  423. ASS_DefaultFontProvider **providers,
  424. size_t *size);
  425. /**
  426. * \brief Set font lookup defaults.
  427. * \param default_font path to default font to use. Must be supplied if
  428. * fontconfig is disabled or unavailable.
  429. * \param default_family fallback font family for fontconfig, or NULL
  430. * \param dfp which font provider to use (one of ASS_DefaultFontProvider). In
  431. * older libass version, this could be 0 or 1, where 1 enabled fontconfig.
  432. * Newer relases also accept 0 (ASS_FONTPROVIDER_NONE) and 1
  433. * (ASS_FONTPROVIDER_AUTODETECT), which is almost backward-compatible.
  434. * If the requested fontprovider does not exist or fails to initialize, the
  435. * behavior is the same as when ASS_FONTPROVIDER_NONE was passed.
  436. * \param config path to fontconfig configuration file, or NULL. Only relevant
  437. * if fontconfig is used.
  438. * \param update whether fontconfig cache should be built/updated now. Only
  439. * relevant if fontconfig is used.
  440. *
  441. * NOTE: font lookup must be configured before an ASS_Renderer can be used.
  442. */
  443. void ass_set_fonts(ASS_Renderer *priv, const char *default_font,
  444. const char *default_family, int dfp,
  445. const char *config, int update);
  446. /**
  447. * \brief Set selective style override mode.
  448. * If enabled, the renderer attempts to override the ASS script's styling of
  449. * normal subtitles, without affecting explicitly positioned text. If an event
  450. * looks like a normal subtitle, parts of the font style are copied from the
  451. * user style set with ass_set_selective_style_override().
  452. * Warning: the heuristic used for deciding when to override the style is rather
  453. * rough, and enabling this option can lead to incorrectly rendered
  454. * subtitles. Since the ASS format doesn't have any support for
  455. * allowing end-users to customize subtitle styling, this feature can
  456. * only be implemented on "best effort" basis, and has to rely on
  457. * heuristics that can easily break.
  458. * \param priv renderer handle
  459. * \param bits bit mask comprised of ASS_OverrideBits values.
  460. */
  461. void ass_set_selective_style_override_enabled(ASS_Renderer *priv, int bits);
  462. /**
  463. * \brief Set style for selective style override.
  464. * See ass_set_selective_style_override_enabled().
  465. * \param style style settings to use if override is enabled. Applications
  466. * should initialize it with {0} before setting fields. Strings will be copied
  467. * by the function.
  468. */
  469. void ass_set_selective_style_override(ASS_Renderer *priv, ASS_Style *style);
  470. /**
  471. * \brief This is a stub and does nothing. Old documentation: Update/build font
  472. * cache. This needs to be called if it was disabled when ass_set_fonts was set.
  473. *
  474. * \param priv renderer handle
  475. * \return success
  476. */
  477. ASS_DEPRECATED("it does nothing") int ass_fonts_update(ASS_Renderer *priv);
  478. /**
  479. * \brief Set hard cache limits. Do not set, or set to zero, for reasonable
  480. * defaults.
  481. *
  482. * \param priv renderer handle
  483. * \param glyph_max maximum number of cached glyphs
  484. * \param bitmap_max_size maximum bitmap cache size (in MB)
  485. */
  486. void ass_set_cache_limits(ASS_Renderer *priv, int glyph_max,
  487. int bitmap_max_size);
  488. /**
  489. * \brief Render a frame, producing a list of ASS_Image.
  490. * \param priv renderer handle
  491. * \param track subtitle track
  492. * \param now video timestamp in milliseconds
  493. * \param detect_change compare to the previous call and set to 1
  494. * if positions changed, or set to 2 if content changed.
  495. */
  496. ASS_Image *ass_render_frame(ASS_Renderer *priv, ASS_Track *track,
  497. long long now, int *detect_change);
  498. /*
  499. * The following functions operate on track objects and do not need
  500. * an ass_renderer
  501. */
  502. /**
  503. * \brief Allocate a new empty track object.
  504. * \param library handle
  505. * \return pointer to empty track or NULL on failure
  506. */
  507. ASS_Track *ass_new_track(ASS_Library *);
  508. /**
  509. * \brief Enable or disable certain features
  510. * This manages flags that control the behavior of the renderer and how certain
  511. * tags etc. within the track are interpreted. The defaults on a newly created
  512. * ASS_Track are such that rendering is compatible with traditional renderers
  513. * like VSFilter, and/or old versions of libass. Calling ass_process_data() or
  514. * ass_process_codec_private() may change some of these flags according to file
  515. * headers. (ass_process_chunk() will not change any of the flags.)
  516. * Additions to ASS_Feature are backward compatible to old libass releases (ABI
  517. * compatibility).
  518. * \param track track
  519. * \param feature the specific feature to enable or disable
  520. * \param enable 0 for disable, any non-0 value for enable
  521. * \return 0 if feature set, -1 if feature is unknown
  522. */
  523. int ass_track_set_feature(ASS_Track *track, ASS_Feature feature, int enable);
  524. /**
  525. * \brief Deallocate track and all its child objects (styles and events).
  526. * \param track track to deallocate or NULL
  527. */
  528. void ass_free_track(ASS_Track *track);
  529. /**
  530. * \brief Allocate new style.
  531. * \param track track
  532. * \return newly allocated style id >= 0, or a value < 0 on failure
  533. */
  534. int ass_alloc_style(ASS_Track *track);
  535. /**
  536. * \brief Allocate new event.
  537. * \param track track
  538. * \return newly allocated event id >= 0, or a value < 0 on failure
  539. */
  540. int ass_alloc_event(ASS_Track *track);
  541. /**
  542. * \brief Delete a style.
  543. * \param track track
  544. * \param sid style id
  545. * Deallocates style data. Does not modify track->n_styles.
  546. */
  547. void ass_free_style(ASS_Track *track, int sid);
  548. /**
  549. * \brief Delete an event.
  550. * \param track track
  551. * \param eid event id
  552. * Deallocates event data. Does not modify track->n_events.
  553. */
  554. void ass_free_event(ASS_Track *track, int eid);
  555. /**
  556. * \brief Parse a chunk of subtitle stream data.
  557. * \param track track
  558. * \param data string to parse
  559. * \param size length of data
  560. */
  561. void ass_process_data(ASS_Track *track, char *data, int size);
  562. /**
  563. * \brief Parse Codec Private section of the subtitle stream, in Matroska
  564. * format. See the Matroska specification for details.
  565. * \param track target track
  566. * \param data string to parse
  567. * \param size length of data
  568. */
  569. void ass_process_codec_private(ASS_Track *track, char *data, int size);
  570. /**
  571. * \brief Parse a chunk of subtitle stream data. A chunk contains exactly one
  572. * event in Matroska format. See the Matroska specification for details.
  573. * In later libass versions (since LIBASS_VERSION==0x01300001), using this
  574. * function means you agree not to modify events manually, or using other
  575. * functions manipulating the event list like ass_process_data(). If you do
  576. * anyway, the internal duplicate checking might break. Calling
  577. * ass_flush_events() is still allowed.
  578. * \param track track
  579. * \param data string to parse
  580. * \param size length of data
  581. * \param timecode starting time of the event (milliseconds)
  582. * \param duration duration of the event (milliseconds)
  583. */
  584. void ass_process_chunk(ASS_Track *track, char *data, int size,
  585. long long timecode, long long duration);
  586. /**
  587. * \brief Set whether the ReadOrder field when processing a packet with
  588. * ass_process_chunk() should be used for eliminating duplicates.
  589. * \param check_readorder 0 means do not try to eliminate duplicates; 1 means
  590. * use the ReadOrder field embedded in the packet as unique identifier, and
  591. * discard the packet if there was already a packet with the same ReadOrder.
  592. * Other values are undefined.
  593. * If this function is not called, the default value is 1.
  594. */
  595. void ass_set_check_readorder(ASS_Track *track, int check_readorder);
  596. /**
  597. * \brief Flush buffered events.
  598. * \param track track
  599. */
  600. void ass_flush_events(ASS_Track *track);
  601. /**
  602. * \brief Read subtitles from file.
  603. * \param library library handle
  604. * \param fname file name
  605. * \param codepage encoding (iconv format)
  606. * \return newly allocated track or NULL on failure
  607. */
  608. ASS_Track *ass_read_file(ASS_Library *library, char *fname,
  609. char *codepage);
  610. /**
  611. * \brief Read subtitles from memory.
  612. * \param library library handle
  613. * \param buf pointer to subtitles text
  614. * \param bufsize size of buffer
  615. * \param codepage encoding (iconv format)
  616. * \return newly allocated track or NULL on failure
  617. */
  618. ASS_Track *ass_read_memory(ASS_Library *library, char *buf,
  619. size_t bufsize, char *codepage);
  620. /**
  621. * \brief Read styles from file into already initialized track.
  622. * \param fname file name
  623. * \param codepage encoding (iconv format)
  624. * \return 0 on success
  625. */
  626. int ass_read_styles(ASS_Track *track, char *fname, char *codepage);
  627. /**
  628. * \brief Add a memory font.
  629. * \param library library handle
  630. * \param name attachment name
  631. * \param data binary font data
  632. * \param data_size data size
  633. */
  634. void ass_add_font(ASS_Library *library, const char *name, const char *data,
  635. int data_size);
  636. /**
  637. * \brief Remove all fonts stored in an ass_library object.
  638. * This can only be called safely if all ASS_Track and ASS_Renderer instances
  639. * associated with the library handle have been released first.
  640. * \param library library handle
  641. */
  642. void ass_clear_fonts(ASS_Library *library);
  643. /**
  644. * \brief Calculates timeshift from now to the start of some other subtitle
  645. * event, depending on movement parameter.
  646. * \param track subtitle track
  647. * \param now current time in milliseconds
  648. * \param movement how many events to skip from the one currently displayed
  649. * +2 means "the one after the next", -1 means "previous"
  650. * \return timeshift in milliseconds
  651. */
  652. long long ass_step_sub(ASS_Track *track, long long now, int movement);
  653. #ifdef __cplusplus
  654. }
  655. #endif
  656. #endif /* LIBASS_ASS_H */