annotate libass/ass_utils.c @ 29297:dbc412fcde45

Initialize local variable, avoids a possible crash due to using an uninitialized variable as array index for mono files.
author reimar
date Mon, 01 Jun 2009 10:43:41 +0000
parents 0f1b5b68af32
children 48d020c5ceca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20008
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19405
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: 19405
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: 19405
diff changeset
3 /*
26723
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
4 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
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
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
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
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
9 * it under the terms of the GNU General Public License as published by
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
11 * (at your option) any later version.
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
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
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
16 * GNU General Public License for more details.
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
17 *
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
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
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
21 */
20008
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19405
diff changeset
22
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
23 #include "config.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
24
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
25 #include <stdlib.h>
19405
0797e1b4a4be Replace stdint.h with inttypes.h.
eugeni
parents: 19003
diff changeset
26 #include <inttypes.h>
26034
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
27 #include <ft2build.h>
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
28 #include FT_GLYPH_H
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
29
21026
d138463e820b Collect all includes of mplayer headers in libass in a single file (mputils.h).
eugeni
parents: 20629
diff changeset
30 #include "mputils.h"
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
31 #include "ass_utils.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
32
28718
e3b5070f671d Remove unused function argument.
eugeni
parents: 28717
diff changeset
33 int mystrtoi(char** p, int* res)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
34 {
28717
7bbe6626f0e0 Support fractional arguments for some override tags.
eugeni
parents: 26738
diff changeset
35 // NOTE: base argument is ignored, but not used in libass anyway
7bbe6626f0e0 Support fractional arguments for some override tags.
eugeni
parents: 26738
diff changeset
36 double temp_res;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
37 char* start = *p;
28717
7bbe6626f0e0 Support fractional arguments for some override tags.
eugeni
parents: 26738
diff changeset
38 temp_res = strtod(*p, p);
7bbe6626f0e0 Support fractional arguments for some override tags.
eugeni
parents: 26738
diff changeset
39 *res = (int) (temp_res + 0.5);
7bbe6626f0e0 Support fractional arguments for some override tags.
eugeni
parents: 26738
diff changeset
40 if (*p != start) return 1;
7bbe6626f0e0 Support fractional arguments for some override tags.
eugeni
parents: 26738
diff changeset
41 else return 0;
7bbe6626f0e0 Support fractional arguments for some override tags.
eugeni
parents: 26738
diff changeset
42 }
7bbe6626f0e0 Support fractional arguments for some override tags.
eugeni
parents: 26738
diff changeset
43
28718
e3b5070f671d Remove unused function argument.
eugeni
parents: 28717
diff changeset
44 int mystrtoll(char** p, long long* res)
28717
7bbe6626f0e0 Support fractional arguments for some override tags.
eugeni
parents: 26738
diff changeset
45 {
7bbe6626f0e0 Support fractional arguments for some override tags.
eugeni
parents: 26738
diff changeset
46 double temp_res;
7bbe6626f0e0 Support fractional arguments for some override tags.
eugeni
parents: 26738
diff changeset
47 char* start = *p;
7bbe6626f0e0 Support fractional arguments for some override tags.
eugeni
parents: 26738
diff changeset
48 temp_res = strtod(*p, p);
7bbe6626f0e0 Support fractional arguments for some override tags.
eugeni
parents: 26738
diff changeset
49 *res = (long long) (temp_res + 0.5);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
50 if (*p != start) return 1;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
51 else return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
52 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
53
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
54 int mystrtou32(char** p, int base, uint32_t* res)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
55 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
56 char* start = *p;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
57 *res = strtoll(*p, p, base);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
58 if (*p != start) return 1;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
59 else return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
60 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
61
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
62 int mystrtod(char** p, double* res)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
63 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
64 char* start = *p;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
65 *res = strtod(*p, p);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
66 if (*p != start) return 1;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
67 else return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
68 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
69
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
70 int strtocolor(char** q, uint32_t* res)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
71 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
72 uint32_t color = 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
73 int result;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
74 char* p = *q;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28785
diff changeset
75
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28785
diff changeset
76 if (*p == '&') ++p;
20629
e8885ec63928 Introduce MSGT_ASS, use it for all libass messages.
eugeni
parents: 20503
diff changeset
77 else mp_msg(MSGT_ASS, MSGL_DBG2, "suspicious color format: \"%s\"\n", p);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28785
diff changeset
78
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28785
diff changeset
79 if (*p == 'H' || *p == 'h') {
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
80 ++p;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
81 result = mystrtou32(&p, 16, &color);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
82 } else {
19003
9dc06456af0f Support some recently discovered color formats.
eugeni
parents: 18937
diff changeset
83 result = mystrtou32(&p, 0, &color);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
84 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28785
diff changeset
85
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
86 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
87 unsigned char* tmp = (unsigned char*)(&color);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
88 unsigned char b;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
89 b = tmp[0]; tmp[0] = tmp[3]; tmp[3] = b;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
90 b = tmp[1]; tmp[1] = tmp[2]; tmp[2] = b;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
91 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
92 if (*p == '&') ++p;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
93 *q = p;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
94
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
95 *res = color;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
96 return result;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
97 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
98
28785
0366ab2c1cb9 Support ScaledBorderAndShadow property.
greg
parents: 28718
diff changeset
99 // Return a boolean value for a string
0366ab2c1cb9 Support ScaledBorderAndShadow property.
greg
parents: 28718
diff changeset
100 char parse_bool(char* str) {
0366ab2c1cb9 Support ScaledBorderAndShadow property.
greg
parents: 28718
diff changeset
101 while (*str == ' ' || *str == '\t')
0366ab2c1cb9 Support ScaledBorderAndShadow property.
greg
parents: 28718
diff changeset
102 str++;
0366ab2c1cb9 Support ScaledBorderAndShadow property.
greg
parents: 28718
diff changeset
103 if (!strncasecmp(str, "yes", 3))
0366ab2c1cb9 Support ScaledBorderAndShadow property.
greg
parents: 28718
diff changeset
104 return 1;
0366ab2c1cb9 Support ScaledBorderAndShadow property.
greg
parents: 28718
diff changeset
105 else if (strtol(str, NULL, 10) > 0)
0366ab2c1cb9 Support ScaledBorderAndShadow property.
greg
parents: 28718
diff changeset
106 return 1;
0366ab2c1cb9 Support ScaledBorderAndShadow property.
greg
parents: 28718
diff changeset
107 return 0;
0366ab2c1cb9 Support ScaledBorderAndShadow property.
greg
parents: 28718
diff changeset
108 }
0366ab2c1cb9 Support ScaledBorderAndShadow property.
greg
parents: 28718
diff changeset
109
26036
8d8c52a169ad Comment out dump_glyph(): it is unused and, as it is now, breaks compilation.
eugeni
parents: 26034
diff changeset
110 #if 0
26034
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
111 static void sprint_tag(uint32_t tag, char* dst)
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
112 {
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
113 dst[0] = (tag >> 24) & 0xFF;
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
114 dst[1] = (tag >> 16) & 0xFF;
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
115 dst[2] = (tag >> 8) & 0xFF;
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
116 dst[3] = tag & 0xFF;
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
117 dst[4] = 0;
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
118 }
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
119
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
120 void dump_glyph(FT_Glyph g)
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
121 {
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
122 char tag[5];
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
123 int i;
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
124 FT_OutlineGlyph og = (FT_OutlineGlyph)g;
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
125 FT_Outline* o = &(og->outline);
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
126 sprint_tag(g->format, tag);
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
127 printf("glyph: %p \n", g);
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
128 printf("format: %s \n", tag);
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
129 printf("outline: %p \n", o);
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
130 printf("contours: %d, points: %d, points ptr: %p \n", o->n_contours, o->n_points, o->points);
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
131 for (i = 0; i < o->n_points; ++i) {
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
132 printf(" point %f, %f \n", d6_to_double(o->points[i].x), d6_to_double(o->points[i].y));
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
133 }
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
134 }
26036
8d8c52a169ad Comment out dump_glyph(): it is unused and, as it is now, breaks compilation.
eugeni
parents: 26034
diff changeset
135 #endif