Mercurial > mplayer.hg
annotate libass/ass_mp.c @ 19489:87c339558bc1
fix menu toggle/hide issues
author | ben |
---|---|
date | Tue, 22 Aug 2006 19:40:50 +0000 |
parents | 6eb79b2384f8 |
children | 31ac2e1a5695 |
rev | line source |
---|---|
19405 | 1 #include <inttypes.h> |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
2 #include <string.h> |
19484
6eb79b2384f8
use of malloc without prototype.. very bad on 64bit archs
rfelker
parents:
19405
diff
changeset
|
3 #include <stdlib.h> |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
4 |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
5 #include "ass.h" |
18937 | 6 #include "ass_mp.h" |
7 | |
8 // libass-related command line options | |
9 int ass_enabled = 0; | |
10 float ass_font_scale = 1.; | |
11 float ass_line_spacing = 0.; | |
12 int ass_top_margin = 0; | |
13 int ass_bottom_margin = 0; | |
14 int extract_embedded_fonts = 0; | |
15 | |
19401
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
16 extern int font_fontconfig; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
17 extern char* font_name; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
18 extern float text_font_scale_factor; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
19 extern int subtitle_autoscale; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
20 |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
21 extern double ass_internal_font_size_coeff; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
22 |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
23 /** |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
24 * \brief Convert subdata to ass_track |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
25 * \param subdata subtitles struct from subreader |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
26 * \param fps video framerate |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
27 * \return newly allocated ass_track, filled with subtitles from subdata |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
28 */ |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
29 ass_track_t* ass_read_subdata(sub_data* subdata, double fps) { |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
30 ass_track_t* track = ass_new_track(); |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
31 ass_style_t* style; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
32 ass_event_t* event; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
33 subtitle* sub; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
34 int sid, eid; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
35 int i; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
36 double fs; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
37 |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
38 track->track_type = TRACK_TYPE_ASS; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
39 track->name = subdata->filename ? strdup(subdata->filename) : 0; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
40 track->Timer = 100.; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
41 track->PlayResX = 384; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
42 track->PlayResY = 288; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
43 track->WrapStyle = 0; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
44 |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
45 sid = ass_alloc_style(track); |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
46 style = track->styles + sid; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
47 style->Name = strdup("Default"); |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
48 style->FontName = font_fontconfig ? strdup(font_name) : strdup("Tahoma"); |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
49 |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
50 fs = track->PlayResY * text_font_scale_factor / 100. / ass_internal_font_size_coeff; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
51 // approximate autoscale coefficients |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
52 if (subtitle_autoscale == 2) |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
53 fs *= 1.3; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
54 else if (subtitle_autoscale == 3) |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
55 fs *= 1.4; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
56 style->FontSize = fs; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
57 |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
58 style->PrimaryColour = 0xC0E9FE00; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
59 style->SecondaryColour = 0x1B429E00; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
60 style->OutlineColour = 0x1B429E00; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
61 style->BackColour = 0x00000000; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
62 style->BorderStyle = 1; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
63 style->Alignment = 2; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
64 style->Outline = 2; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
65 style->MarginL = 30; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
66 style->MarginR = 30; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
67 style->MarginV = 20; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
68 style->ScaleX = 1.; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
69 style->ScaleY = 1.; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
70 |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
71 for (i = 0; i < subdata->sub_num; ++i) { |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
72 int len = 0, j; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
73 char* p; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
74 char* end; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
75 sub = subdata->subtitles + i; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
76 eid = ass_alloc_event(track); |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
77 event = track->events + eid; |
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 event->Start = sub->start * 10; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
80 event->Duration = (sub->end - sub->start) * 10; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
81 if (!subdata->sub_uses_time) { |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
82 event->Start *= 100. / fps; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
83 event->Duration *= 100. / fps; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
84 } |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
85 |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
86 event->Style = sid; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
87 |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
88 for (j = 0; j < sub->lines; ++j) |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
89 len += sub->text[j] ? strlen(sub->text[j]) : 0; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
90 |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
91 len += 2 * sub->lines; // '\N', including the one after the last line |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
92 len += 6; // {\anX} |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
93 len += 1; // '\0' |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
94 |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
95 event->Text = malloc(len); |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
96 end = event->Text + len; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
97 p = event->Text; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
98 |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
99 if (sub->alignment) |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
100 p += snprintf(p, end - p, "{\\an%d}", sub->alignment); |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
101 |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
102 for (j = 0; j < sub->lines; ++j) |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
103 p += snprintf(p, end - p, "%s ", sub->text[j]); |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
104 |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
105 p--; // remove last ' ' |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
106 *p = 0; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
107 } |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
108 return track; |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
109 } |
c0c3a2f8bb32
Add subdata to ass_track conversion for external subtitles.
eugeni
parents:
18937
diff
changeset
|
110 |