annotate libass/ass_render_api.c @ 31882:ef30e1505969

Do not call *_aid_from_lang when audio_lang is NULL.
author reimar
date Mon, 16 Aug 2010 10:33:33 +0000
parents e64df5862cea
children 88eebbbbd6a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31853
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
1 /*
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
3 * Copyright (C) 2010 Grigori Goronzy <greg@geekmind.org>
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
4 *
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
5 * This file is part of libass.
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
6 *
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
7 * libass is free software; you can redistribute it and/or modify
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
10 * (at your option) any later version.
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
11 *
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
12 * libass is distributed in the hope that it will be useful,
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
15 * GNU General Public License for more details.
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
16 *
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License along
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
18 * with libass; if not, write to the Free Software Foundation, Inc.,
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
20 */
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
21
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
22 #include "config.h"
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
23 #include "ass_render.h"
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
24
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
25 static void ass_reconfigure(ASS_Renderer *priv)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
26 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
27 ASS_Settings *settings = &priv->settings;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
28
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
29 priv->render_id++;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
30 priv->cache.glyph_cache =
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
31 ass_glyph_cache_reset(priv->cache.glyph_cache);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
32 priv->cache.bitmap_cache =
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
33 ass_bitmap_cache_reset(priv->cache.bitmap_cache);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
34 priv->cache.composite_cache =
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
35 ass_composite_cache_reset(priv->cache.composite_cache);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
36 ass_free_images(priv->prev_images_root);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
37 priv->prev_images_root = 0;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
38
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
39 priv->width = settings->frame_width;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
40 priv->height = settings->frame_height;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
41 priv->orig_width = settings->frame_width - settings->left_margin -
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
42 settings->right_margin;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
43 priv->orig_height = settings->frame_height - settings->top_margin -
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
44 settings->bottom_margin;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
45 priv->orig_width_nocrop =
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
46 settings->frame_width - FFMAX(settings->left_margin, 0) -
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
47 FFMAX(settings->right_margin, 0);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
48 priv->orig_height_nocrop =
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
49 settings->frame_height - FFMAX(settings->top_margin, 0) -
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
50 FFMAX(settings->bottom_margin, 0);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
51 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
52
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
53 void ass_set_frame_size(ASS_Renderer *priv, int w, int h)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
54 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
55 if (priv->settings.frame_width != w || priv->settings.frame_height != h) {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
56 priv->settings.frame_width = w;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
57 priv->settings.frame_height = h;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
58 if (priv->settings.aspect == 0.) {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
59 priv->settings.aspect = ((double) w) / h;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
60 priv->settings.storage_aspect = ((double) w) / h;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
61 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
62 ass_reconfigure(priv);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
63 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
64 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
65
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
66 void ass_set_margins(ASS_Renderer *priv, int t, int b, int l, int r)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
67 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
68 if (priv->settings.left_margin != l || priv->settings.right_margin != r ||
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
69 priv->settings.top_margin != t || priv->settings.bottom_margin != b) {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
70 priv->settings.left_margin = l;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
71 priv->settings.right_margin = r;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
72 priv->settings.top_margin = t;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
73 priv->settings.bottom_margin = b;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
74 ass_reconfigure(priv);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
75 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
76 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
77
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
78 void ass_set_use_margins(ASS_Renderer *priv, int use)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
79 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
80 priv->settings.use_margins = use;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
81 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
82
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
83 void ass_set_aspect_ratio(ASS_Renderer *priv, double dar, double sar)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
84 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
85 if (priv->settings.aspect != dar || priv->settings.storage_aspect != sar) {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
86 priv->settings.aspect = dar;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
87 priv->settings.storage_aspect = sar;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
88 ass_reconfigure(priv);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
89 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
90 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
91
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
92 void ass_set_font_scale(ASS_Renderer *priv, double font_scale)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
93 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
94 if (priv->settings.font_size_coeff != font_scale) {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
95 priv->settings.font_size_coeff = font_scale;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
96 ass_reconfigure(priv);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
97 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
98 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
99
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
100 void ass_set_hinting(ASS_Renderer *priv, ASS_Hinting ht)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
101 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
102 if (priv->settings.hinting != ht) {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
103 priv->settings.hinting = ht;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
104 ass_reconfigure(priv);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
105 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
106 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
107
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
108 void ass_set_line_spacing(ASS_Renderer *priv, double line_spacing)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
109 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
110 priv->settings.line_spacing = line_spacing;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
111 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
112
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
113 void ass_set_fonts(ASS_Renderer *priv, const char *default_font,
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
114 const char *default_family, int fc, const char *config,
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
115 int update)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
116 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
117 free(priv->settings.default_font);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
118 free(priv->settings.default_family);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
119 priv->settings.default_font = default_font ? strdup(default_font) : 0;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
120 priv->settings.default_family =
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
121 default_family ? strdup(default_family) : 0;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
122
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
123 if (priv->fontconfig_priv)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
124 fontconfig_done(priv->fontconfig_priv);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
125 priv->fontconfig_priv =
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
126 fontconfig_init(priv->library, priv->ftlibrary, default_family,
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
127 default_font, fc, config, update);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
128 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
129
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
130 int ass_fonts_update(ASS_Renderer *render_priv)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
131 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
132 return fontconfig_update(render_priv->fontconfig_priv);
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
133 }
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
134
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
135 void ass_set_cache_limits(ASS_Renderer *render_priv, int glyph_max,
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
136 int bitmap_max)
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
137 {
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
138 render_priv->cache.glyph_max = glyph_max ? glyph_max : GLYPH_CACHE_MAX;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
139 render_priv->cache.bitmap_max_size = bitmap_max ? 1048576 * bitmap_max :
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
140 BITMAP_CACHE_MAX_SIZE;
e64df5862cea Import libass 0.9.10
greg
parents:
diff changeset
141 }