Use DECLARE_ALIGNED macro instead of gcc __attribute__.
[mplayer/glamo.git] / libass / ass_utils.c
blob9a89e8afae426622fb90f60fbe22dd3b0d877eea
1 // -*- c-basic-offset: 8; indent-tabs-mode: t -*-
2 // vim:ts=8:sw=8:noet:ai:
3 /*
4 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
6 * This file is part of libass.
8 * libass is free software; you can redistribute it and/or modify
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.
13 * libass is distributed in the hope that it will be useful,
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.
18 * You should have received a copy of the GNU General Public License along
19 * with libass; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "config.h"
25 #include <stdlib.h>
26 #include <inttypes.h>
27 #include <ft2build.h>
28 #include FT_GLYPH_H
30 #include "mputils.h"
31 #include "ass_utils.h"
33 int mystrtoi(char** p, int* res)
35 // NOTE: base argument is ignored, but not used in libass anyway
36 double temp_res;
37 char* start = *p;
38 temp_res = strtod(*p, p);
39 *res = (int) (temp_res + 0.5);
40 if (*p != start) return 1;
41 else return 0;
44 int mystrtoll(char** p, long long* res)
46 double temp_res;
47 char* start = *p;
48 temp_res = strtod(*p, p);
49 *res = (long long) (temp_res + 0.5);
50 if (*p != start) return 1;
51 else return 0;
54 int mystrtou32(char** p, int base, uint32_t* res)
56 char* start = *p;
57 *res = strtoll(*p, p, base);
58 if (*p != start) return 1;
59 else return 0;
62 int mystrtod(char** p, double* res)
64 char* start = *p;
65 *res = strtod(*p, p);
66 if (*p != start) return 1;
67 else return 0;
70 int strtocolor(char** q, uint32_t* res)
72 uint32_t color = 0;
73 int result;
74 char* p = *q;
76 if (*p == '&') ++p;
77 else mp_msg(MSGT_ASS, MSGL_DBG2, "suspicious color format: \"%s\"\n", p);
79 if (*p == 'H' || *p == 'h') {
80 ++p;
81 result = mystrtou32(&p, 16, &color);
82 } else {
83 result = mystrtou32(&p, 0, &color);
87 unsigned char* tmp = (unsigned char*)(&color);
88 unsigned char b;
89 b = tmp[0]; tmp[0] = tmp[3]; tmp[3] = b;
90 b = tmp[1]; tmp[1] = tmp[2]; tmp[2] = b;
92 if (*p == '&') ++p;
93 *q = p;
95 *res = color;
96 return result;
99 // Return a boolean value for a string
100 char parse_bool(char* str) {
101 while (*str == ' ' || *str == '\t')
102 str++;
103 if (!strncasecmp(str, "yes", 3))
104 return 1;
105 else if (strtol(str, NULL, 10) > 0)
106 return 1;
107 return 0;
110 #if 0
111 static void sprint_tag(uint32_t tag, char* dst)
113 dst[0] = (tag >> 24) & 0xFF;
114 dst[1] = (tag >> 16) & 0xFF;
115 dst[2] = (tag >> 8) & 0xFF;
116 dst[3] = tag & 0xFF;
117 dst[4] = 0;
120 void dump_glyph(FT_Glyph g)
122 char tag[5];
123 int i;
124 FT_OutlineGlyph og = (FT_OutlineGlyph)g;
125 FT_Outline* o = &(og->outline);
126 sprint_tag(g->format, tag);
127 printf("glyph: %p \n", g);
128 printf("format: %s \n", tag);
129 printf("outline: %p \n", o);
130 printf("contours: %d, points: %d, points ptr: %p \n", o->n_contours, o->n_points, o->points);
131 for (i = 0; i < o->n_points; ++i) {
132 printf(" point %f, %f \n", d6_to_double(o->points[i].x), d6_to_double(o->points[i].y));
135 #endif