Mercurial > mplayer.hg
annotate libass/ass_mp.c @ 29762:bb26e1db5c90
Document slice ordering assumption done by sws_scale().
author | stefano |
---|---|
date | Fri, 30 Oct 2009 14:13:25 +0000 |
parents | 0f1b5b68af32 |
children | 73a32da1ef18 |
rev | line source |
---|---|
20008
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19654
diff
changeset
|
1 // -*- c-basic-offset: 8; indent-tabs-mode: t -*- |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19654
diff
changeset
|
2 // vim:ts=8:sw=8:noet:ai: |
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19654
diff
changeset
|
3 /* |
26723 | 4 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com> |
5 * | |
26738
588ce97b44f2
Speak of libass instead of MPlayer in the libass license headers.
diego
parents:
26723
diff
changeset
|
6 * This file is part of libass. |
26723 | 7 * |
26738
588ce97b44f2
Speak of libass instead of MPlayer in the libass license headers.
diego
parents:
26723
diff
changeset
|
8 * libass is free software; you can redistribute it and/or modify |
26723 | 9 * it under the terms of the GNU General Public License as published by |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
26738
588ce97b44f2
Speak of libass instead of MPlayer in the libass license headers.
diego
parents:
26723
diff
changeset
|
13 * libass is distributed in the hope that it will be useful, |
26723 | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License along | |
26738
588ce97b44f2
Speak of libass instead of MPlayer in the libass license headers.
diego
parents:
26723
diff
changeset
|
19 * with libass; if not, write to the Free Software Foundation, Inc., |
26723 | 20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
21 */ | |
20008
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19654
diff
changeset
|
22 |
19405 | 23 #include <inttypes.h> |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
24 #include <string.h> |
19484
6eb79b2384f8
use of malloc without prototype.. very bad on 64bit archs
rfelker
parents:
19405
diff
changeset
|
25 #include <stdlib.h> |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
26 |
19643
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
27 #include "mp_msg.h" |
24242
76f5d8892c04
Clean up the way get_path is handled: Compile get_path.c to an object to link
diego
parents:
23328
diff
changeset
|
28 #include "get_path.h" |
19643
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
29 |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
30 #include "ass.h" |
19646 | 31 #include "ass_utils.h" |
18937 | 32 #include "ass_mp.h" |
20477 | 33 #include "ass_library.h" |
18937 | 34 |
27393 | 35 #ifdef CONFIG_FONTCONFIG |
21632
e3e6d6fbb561
Make -embeddedfonts enabled by default with FontConfig >= 2.4.2.
eugeni
parents:
20706
diff
changeset
|
36 #include <fontconfig/fontconfig.h> |
e3e6d6fbb561
Make -embeddedfonts enabled by default with FontConfig >= 2.4.2.
eugeni
parents:
20706
diff
changeset
|
37 #endif |
e3e6d6fbb561
Make -embeddedfonts enabled by default with FontConfig >= 2.4.2.
eugeni
parents:
20706
diff
changeset
|
38 |
18937 | 39 // libass-related command line options |
20477 | 40 ass_library_t* ass_library; |
18937 | 41 int ass_enabled = 0; |
42 float ass_font_scale = 1.; | |
43 float ass_line_spacing = 0.; | |
44 int ass_top_margin = 0; | |
45 int ass_bottom_margin = 0; | |
21632
e3e6d6fbb561
Make -embeddedfonts enabled by default with FontConfig >= 2.4.2.
eugeni
parents:
20706
diff
changeset
|
46 #if defined(FC_VERSION) && (FC_VERSION >= 20402) |
e3e6d6fbb561
Make -embeddedfonts enabled by default with FontConfig >= 2.4.2.
eugeni
parents:
20706
diff
changeset
|
47 int extract_embedded_fonts = 1; |
e3e6d6fbb561
Make -embeddedfonts enabled by default with FontConfig >= 2.4.2.
eugeni
parents:
20706
diff
changeset
|
48 #else |
18937 | 49 int extract_embedded_fonts = 0; |
21632
e3e6d6fbb561
Make -embeddedfonts enabled by default with FontConfig >= 2.4.2.
eugeni
parents:
20706
diff
changeset
|
50 #endif |
19495 | 51 char **ass_force_style_list = NULL; |
19563 | 52 int ass_use_margins = 0; |
19646 | 53 char* ass_color = NULL; |
54 char* ass_border_color = NULL; | |
19652
2c016957360a
Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents:
19646
diff
changeset
|
55 char* ass_styles_file = NULL; |
23134
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
22886
diff
changeset
|
56 int ass_hinting = ASS_HINTING_NATIVE + 4; // native hinting for unscaled osd |
18937 | 57 |
27393 | 58 #ifdef CONFIG_FONTCONFIG |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
59 extern int font_fontconfig; |
20469
54babf7ca302
If HAVE_FONTCONFIG is not defined, font_fontconfig might be declared both
reimar
parents:
20446
diff
changeset
|
60 #else |
25351 | 61 static int font_fontconfig = -1; |
20469
54babf7ca302
If HAVE_FONTCONFIG is not defined, font_fontconfig might be declared both
reimar
parents:
20446
diff
changeset
|
62 #endif |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
63 extern char* font_name; |
25392 | 64 extern char* sub_font_name; |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
65 extern float text_font_scale_factor; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
66 extern int subtitle_autoscale; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
67 |
27393 | 68 #ifdef CONFIG_ICONV |
20477 | 69 extern char* sub_cp; |
70 #else | |
71 static char* sub_cp = 0; | |
72 #endif | |
73 | |
28051 | 74 void process_force_style(ass_track_t* track); |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
75 |
20477 | 76 ass_track_t* ass_default_track(ass_library_t* library) { |
77 ass_track_t* track = ass_new_track(library); | |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
78 |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
79 track->track_type = TRACK_TYPE_ASS; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
80 track->Timer = 100.; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
81 track->PlayResY = 288; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
82 track->WrapStyle = 0; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
83 |
19652
2c016957360a
Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents:
19646
diff
changeset
|
84 if (ass_styles_file) |
20477 | 85 ass_read_styles(track, ass_styles_file, sub_cp); |
19652
2c016957360a
Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents:
19646
diff
changeset
|
86 |
2c016957360a
Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents:
19646
diff
changeset
|
87 if (track->n_styles == 0) { |
19653
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
88 ass_style_t* style; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
89 int sid; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
90 double fs; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
91 uint32_t c1, c2; |
19652
2c016957360a
Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents:
19646
diff
changeset
|
92 |
19653
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
93 sid = ass_alloc_style(track); |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
94 style = track->styles + sid; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
95 style->Name = strdup("Default"); |
25392 | 96 style->FontName = (font_fontconfig >= 0 && sub_font_name) ? strdup(sub_font_name) : (font_fontconfig >= 0 && font_name) ? strdup(font_name) : strdup("Sans"); |
28860
7fcc0bf5b27a
Treat -font/-subfont as Fontconfig pattern in libass.
eugeni
parents:
28051
diff
changeset
|
97 style->treat_fontname_as_pattern = 1; |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
98 |
23328 | 99 fs = track->PlayResY * text_font_scale_factor / 100.; |
19653
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
100 // approximate autoscale coefficients |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
101 if (subtitle_autoscale == 2) |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
102 fs *= 1.3; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
103 else if (subtitle_autoscale == 3) |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
104 fs *= 1.4; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
105 style->FontSize = fs; |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
106 |
19653
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
107 if (ass_color) c1 = strtoll(ass_color, NULL, 16); |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
108 else c1 = 0xFFFF0000; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
109 if (ass_border_color) c2 = strtoll(ass_border_color, NULL, 16); |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
110 else c2 = 0x00000000; |
19646 | 111 |
19653
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
112 style->PrimaryColour = c1; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
113 style->SecondaryColour = c1; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
114 style->OutlineColour = c2; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
115 style->BackColour = 0x00000000; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
116 style->BorderStyle = 1; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
117 style->Alignment = 2; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
118 style->Outline = 2; |
20138 | 119 style->MarginL = 10; |
120 style->MarginR = 10; | |
121 style->MarginV = 5; | |
19653
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
122 style->ScaleX = 1.; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
123 style->ScaleY = 1.; |
19652
2c016957360a
Add -ass-styles option. It allows to load styles from a file and use them
eugeni
parents:
19646
diff
changeset
|
124 } |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
125 |
19654
ae983f0a1cac
Apply -ass-force-style also to matroska plaintext subs.
eugeni
parents:
19653
diff
changeset
|
126 process_force_style(track); |
19643
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
127 return track; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
128 } |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
129 |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
130 static int check_duplicate_plaintext_event(ass_track_t* track) |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
131 { |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
132 int i; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
133 ass_event_t* evt = track->events + track->n_events - 1; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
134 |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
135 for (i = 0; i<track->n_events - 1; ++i) // ignoring last event, it is the one we are comparing with |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
136 if (track->events[i].Start == evt->Start && |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
137 track->events[i].Duration == evt->Duration && |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
138 strcmp(track->events[i].Text, evt->Text) == 0) |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
139 return 1; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
140 return 0; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
141 } |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
142 |
19643
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
143 /** |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
144 * \brief Convert subtitle to ass_event_t for the given track |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
145 * \param ass_track_t track |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
146 * \param sub subtitle to convert |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
147 * \return event id |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
148 * note: assumes that subtitle is _not_ fps-based; caller must manually correct |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
149 * Start and Duration in other case. |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
150 **/ |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
151 int ass_process_subtitle(ass_track_t* track, subtitle* sub) |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
152 { |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
153 int eid; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
154 ass_event_t* event; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
155 int len = 0, j; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
156 char* p; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
157 char* end; |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
158 |
19643
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
159 eid = ass_alloc_event(track); |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
160 event = track->events + eid; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
161 |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
162 event->Start = sub->start * 10; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
163 event->Duration = (sub->end - sub->start) * 10; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
164 event->Style = 0; |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
165 |
19653
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
166 for (j = 0; j < sub->lines; ++j) |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
167 len += sub->text[j] ? strlen(sub->text[j]) : 0; |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
168 |
19653
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
169 len += 2 * sub->lines; // '\N', including the one after the last line |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
170 len += 6; // {\anX} |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
171 len += 1; // '\0' |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
172 |
19653
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
173 event->Text = malloc(len); |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
174 end = event->Text + len; |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
175 p = event->Text; |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
176 |
19653
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
177 if (sub->alignment) |
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
178 p += snprintf(p, end - p, "{\\an%d}", sub->alignment); |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
179 |
19653
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
180 for (j = 0; j < sub->lines; ++j) |
20495
27c1fa3a228e
Add \N at the end of each subtitle line when converting from subdata.
eugeni
parents:
20477
diff
changeset
|
181 p += snprintf(p, end - p, "%s\\N", sub->text[j]); |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
182 |
21835
5ee5281c78f8
Avoid invalid memory access in ass_process_subtitle for empty subtitles
reimar
parents:
21632
diff
changeset
|
183 if (sub->lines > 0) p-=2; // remove last "\N" |
19653
c03c705573c1
Cosmetics: restore indentation after recent changes.
eugeni
parents:
19652
diff
changeset
|
184 *p = 0; |
19643
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
185 |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
186 if (check_duplicate_plaintext_event(track)) { |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
187 ass_free_event(track, eid); |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
188 track->n_events--; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
189 return -1; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
190 } |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
191 |
20629
e8885ec63928
Introduce MSGT_ASS, use it for all libass messages.
eugeni
parents:
20502
diff
changeset
|
192 mp_msg(MSGT_ASS, MSGL_V, "plaintext event at %" PRId64 ", +%" PRId64 ": %s \n", |
19643
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
193 (int64_t)event->Start, (int64_t)event->Duration, event->Text); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28860
diff
changeset
|
194 |
19643
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
195 return eid; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
196 } |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
197 |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
198 |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
199 /** |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
200 * \brief Convert subdata to ass_track |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
201 * \param subdata subtitles struct from subreader |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
202 * \param fps video framerate |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
203 * \return newly allocated ass_track, filled with subtitles from subdata |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
204 */ |
20477 | 205 ass_track_t* ass_read_subdata(ass_library_t* library, sub_data* subdata, double fps) { |
19643
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
206 ass_track_t* track; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
207 int i; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
208 |
20477 | 209 track = ass_default_track(library); |
19643
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
210 track->name = subdata->filename ? strdup(subdata->filename) : 0; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
211 |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
212 for (i = 0; i < subdata->sub_num; ++i) { |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
213 int eid = ass_process_subtitle(track, subdata->subtitles + i); |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
214 if (eid < 0) |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
215 continue; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
216 if (!subdata->sub_uses_time) { |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
217 track->events[eid].Start *= 100. / fps; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
218 track->events[eid].Duration *= 100. / fps; |
f48d49b400cf
Add support for rendering matroska plaintext subtitles with libass.
eugeni
parents:
19592
diff
changeset
|
219 } |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
220 } |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
221 return track; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
222 } |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
223 |
23134
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
22886
diff
changeset
|
224 void ass_configure(ass_renderer_t* priv, int w, int h, int unscaled) { |
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
22886
diff
changeset
|
225 int hinting; |
20446
e8adc3778348
Split ass_configure() into several smaller functions.
eugeni
parents:
20138
diff
changeset
|
226 ass_set_frame_size(priv, w, h); |
e8adc3778348
Split ass_configure() into several smaller functions.
eugeni
parents:
20138
diff
changeset
|
227 ass_set_margins(priv, ass_top_margin, ass_bottom_margin, 0, 0); |
e8adc3778348
Split ass_configure() into several smaller functions.
eugeni
parents:
20138
diff
changeset
|
228 ass_set_use_margins(priv, ass_use_margins); |
e8adc3778348
Split ass_configure() into several smaller functions.
eugeni
parents:
20138
diff
changeset
|
229 ass_set_font_scale(priv, ass_font_scale); |
23134
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
22886
diff
changeset
|
230 if (!unscaled && (ass_hinting & 4)) |
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
22886
diff
changeset
|
231 hinting = 0; |
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
22886
diff
changeset
|
232 else |
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
22886
diff
changeset
|
233 hinting = ass_hinting & 3; |
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
22886
diff
changeset
|
234 ass_set_hinting(priv, hinting); |
24554 | 235 ass_set_line_spacing(priv, ass_line_spacing); |
20706
6ae01628975f
Initialize fontconfig in VFCTRL_INIT_EOSD handler.
eugeni
parents:
20702
diff
changeset
|
236 } |
20446
e8adc3778348
Split ass_configure() into several smaller functions.
eugeni
parents:
20138
diff
changeset
|
237 |
20706
6ae01628975f
Initialize fontconfig in VFCTRL_INIT_EOSD handler.
eugeni
parents:
20702
diff
changeset
|
238 void ass_configure_fonts(ass_renderer_t* priv) { |
6ae01628975f
Initialize fontconfig in VFCTRL_INIT_EOSD handler.
eugeni
parents:
20702
diff
changeset
|
239 char *dir, *path, *family; |
20446
e8adc3778348
Split ass_configure() into several smaller functions.
eugeni
parents:
20138
diff
changeset
|
240 dir = get_path("fonts"); |
25392 | 241 if (font_fontconfig < 0 && sub_font_name) path = strdup(sub_font_name); |
242 else if (font_fontconfig < 0 && font_name) path = strdup(font_name); | |
20446
e8adc3778348
Split ass_configure() into several smaller functions.
eugeni
parents:
20138
diff
changeset
|
243 else path = get_path("subfont.ttf"); |
25392 | 244 if (font_fontconfig >= 0 && sub_font_name) family = strdup(sub_font_name); |
245 else if (font_fontconfig >= 0 && font_name) family = strdup(font_name); | |
20446
e8adc3778348
Split ass_configure() into several smaller functions.
eugeni
parents:
20138
diff
changeset
|
246 else family = 0; |
e8adc3778348
Split ass_configure() into several smaller functions.
eugeni
parents:
20138
diff
changeset
|
247 |
26582
62ac4f8062ee
Remove libass dependency on global font_fontconfig variable.
eugeni
parents:
25813
diff
changeset
|
248 if (font_fontconfig >= 0) |
62ac4f8062ee
Remove libass dependency on global font_fontconfig variable.
eugeni
parents:
25813
diff
changeset
|
249 ass_set_fonts(priv, path, family); |
62ac4f8062ee
Remove libass dependency on global font_fontconfig variable.
eugeni
parents:
25813
diff
changeset
|
250 else |
62ac4f8062ee
Remove libass dependency on global font_fontconfig variable.
eugeni
parents:
25813
diff
changeset
|
251 ass_set_fonts_nofc(priv, path, family); |
20446
e8adc3778348
Split ass_configure() into several smaller functions.
eugeni
parents:
20138
diff
changeset
|
252 |
e8adc3778348
Split ass_configure() into several smaller functions.
eugeni
parents:
20138
diff
changeset
|
253 free(dir); |
e8adc3778348
Split ass_configure() into several smaller functions.
eugeni
parents:
20138
diff
changeset
|
254 free(path); |
e8adc3778348
Split ass_configure() into several smaller functions.
eugeni
parents:
20138
diff
changeset
|
255 free(family); |
e8adc3778348
Split ass_configure() into several smaller functions.
eugeni
parents:
20138
diff
changeset
|
256 } |
20502 | 257 |
22886 | 258 ass_library_t* ass_init(void) { |
20702 | 259 ass_library_t* priv; |
260 char* path = get_path("fonts"); | |
261 priv = ass_library_init(); | |
262 ass_set_fonts_dir(priv, path); | |
263 ass_set_extract_fonts(priv, extract_embedded_fonts); | |
264 ass_set_style_overrides(priv, ass_force_style_list); | |
265 free(path); | |
266 return priv; | |
20502 | 267 } |
25813 | 268 |
269 int ass_force_reload = 0; // flag set if global ass-related settings were changed | |
270 | |
271 ass_image_t* ass_mp_render_frame(ass_renderer_t *priv, ass_track_t* track, long long now, int* detect_change) { | |
272 if (ass_force_reload) { | |
273 ass_set_margins(priv, ass_top_margin, ass_bottom_margin, 0, 0); | |
274 ass_set_use_margins(priv, ass_use_margins); | |
275 ass_set_font_scale(priv, ass_font_scale); | |
276 ass_force_reload = 0; | |
277 } | |
278 return ass_render_frame(priv, track, now, detect_change); | |
279 } |