Handle illegal \a tags like VSFilter
[libass.git] / libass / ass_utils.h
blobbade57804dc5a2dca6bc8f7a495310e23bb52671
1 /*
2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
4 * This file is part of libass.
6 * libass is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * libass is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with libass; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #ifndef LIBASS_UTILS_H
22 #define LIBASS_UTILS_H
24 #include <stdio.h>
25 #include <stdarg.h>
26 #include <stdint.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <assert.h>
31 #ifdef CONFIG_ENCA
32 #include <enca.h>
33 #endif
35 #include "ass.h"
37 #define MSGL_FATAL 0
38 #define MSGL_ERR 1
39 #define MSGL_WARN 2
40 #define MSGL_INFO 4
41 #define MSGL_V 6
42 #define MSGL_DBG2 7
44 #define FFMAX(a,b) ((a) > (b) ? (a) : (b))
45 #define FFMIN(a,b) ((a) > (b) ? (b) : (a))
46 #define FFMINMAX(c,a,b) FFMIN(FFMAX(c, a), b)
48 int mystrtoi(char **p, int *res);
49 int mystrtoll(char **p, long long *res);
50 int mystrtou32(char **p, int base, uint32_t *res);
51 int mystrtod(char **p, double *res);
52 int strtocolor(ASS_Library *library, char **q, uint32_t *res, int hex);
53 char parse_bool(char *str);
54 unsigned ass_utf8_get_char(char **str);
55 void ass_msg(ASS_Library *priv, int lvl, char *fmt, ...);
56 #ifdef CONFIG_ENCA
57 void *ass_guess_buffer_cp(ASS_Library *library, unsigned char *buffer,
58 int buflen, char *preferred_language,
59 char *fallback);
60 #endif
62 static inline int d6_to_int(int x)
64 return (x + 32) >> 6;
66 static inline int d16_to_int(int x)
68 return (x + 32768) >> 16;
70 static inline int int_to_d6(int x)
72 return x << 6;
74 static inline int int_to_d16(int x)
76 return x << 16;
78 static inline int d16_to_d6(int x)
80 return (x + 512) >> 10;
82 static inline int d6_to_d16(int x)
84 return x << 10;
86 static inline double d6_to_double(int x)
88 return x / 64.;
90 static inline int double_to_d6(double x)
92 return (int) (x * 64);
94 static inline double d16_to_double(int x)
96 return ((double) x) / 0x10000;
98 static inline int double_to_d16(double x)
100 return (int) (x * 0x10000);
103 #define FNV1_32A_INIT (unsigned)0x811c9dc5
105 static inline unsigned fnv_32a_buf(void *buf, size_t len, unsigned hval)
107 unsigned char *bp = buf;
108 unsigned char *be = bp + len;
109 while (bp < be) {
110 hval ^= (unsigned) *bp++;
111 hval +=
112 (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) +
113 (hval << 24);
115 return hval;
117 static inline unsigned fnv_32a_str(char *str, unsigned hval)
119 unsigned char *s = (unsigned char *) str;
120 while (*s) {
121 hval ^= (unsigned) *s++;
122 hval +=
123 (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) +
124 (hval << 24);
126 return hval;
129 #endif /* LIBASS_UTILS_H */