comparison libass/ass_utils.h @ 30200:48d020c5ceca

Update internal libass copy to commit 8db4a5
author greg
date Fri, 08 Jan 2010 18:35:44 +0000
parents 0366ab2c1cb9
children 88eebbbbd6a0
comparison
equal deleted inserted replaced
30199:f9984b2fc1b2 30200:48d020c5ceca
1 // -*- c-basic-offset: 8; indent-tabs-mode: t -*-
2 // vim:ts=8:sw=8:noet:ai:
3 /* 1 /*
4 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com> 2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
5 * 3 *
6 * This file is part of libass. 4 * This file is part of libass.
7 * 5 *
21 */ 19 */
22 20
23 #ifndef LIBASS_UTILS_H 21 #ifndef LIBASS_UTILS_H
24 #define LIBASS_UTILS_H 22 #define LIBASS_UTILS_H
25 23
24 #include <stdio.h>
25 #include <stdarg.h>
26 #include <stdint.h> 26 #include <stdint.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <assert.h>
27 30
28 int mystrtoi(char** p, int* res); 31 #ifdef CONFIG_ENCA
29 int mystrtoll(char** p, long long* res); 32 #include <enca.h>
30 int mystrtou32(char** p, int base, uint32_t* res); 33 #endif
31 int mystrtod(char** p, double* res);
32 int strtocolor(char** q, uint32_t* res);
33 char parse_bool(char* str);
34 34
35 static inline int d6_to_int(int x) { 35 #include "ass.h"
36 return (x + 32) >> 6; 36
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
43
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)
47
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
61
62 /* defined in ass_strtod.c */
63 double ass_strtod(const char *string, char **endPtr);
64
65 static inline int d6_to_int(int x)
66 {
67 return (x + 32) >> 6;
37 } 68 }
38 static inline int d16_to_int(int x) { 69 static inline int d16_to_int(int x)
39 return (x + 32768) >> 16; 70 {
71 return (x + 32768) >> 16;
40 } 72 }
41 static inline int int_to_d6(int x) { 73 static inline int int_to_d6(int x)
42 return x << 6; 74 {
75 return x << 6;
43 } 76 }
44 static inline int int_to_d16(int x) { 77 static inline int int_to_d16(int x)
45 return x << 16; 78 {
79 return x << 16;
46 } 80 }
47 static inline int d16_to_d6(int x) { 81 static inline int d16_to_d6(int x)
48 return (x + 512) >> 10; 82 {
83 return (x + 512) >> 10;
49 } 84 }
50 static inline int d6_to_d16(int x) { 85 static inline int d6_to_d16(int x)
51 return x << 10; 86 {
87 return x << 10;
52 } 88 }
53 static inline double d6_to_double(int x) { 89 static inline double d6_to_double(int x)
54 return x / 64.; 90 {
91 return x / 64.;
55 } 92 }
56 static inline int double_to_d6(double x) { 93 static inline int double_to_d6(double x)
57 return (int)(x * 64); 94 {
95 return (int) (x * 64);
58 } 96 }
59 static inline double d16_to_double(int x) { 97 static inline double d16_to_double(int x)
60 return ((double)x) / 0x10000; 98 {
99 return ((double) x) / 0x10000;
61 } 100 }
62 static inline int double_to_d16(double x) { 101 static inline int double_to_d16(double x)
63 return (int)(x * 0x10000); 102 {
103 return (int) (x * 0x10000);
104 }
105 static inline double d22_to_double(int x)
106 {
107 return ((double) x) / 0x400000;
108 }
109 static inline int double_to_d22(double x)
110 {
111 return (int) (x * 0x400000);
64 } 112 }
65 113
66 #endif /* LIBASS_UTILS_H */ 114 // Calculate cache key for a rotational angle in degrees
115 static inline int rot_key(double a)
116 {
117 const int m = double_to_d22(360.0);
118 return double_to_d22(a) % m;
119 }
120
121 #define FNV1_32A_INIT (unsigned)0x811c9dc5
122
123 static inline unsigned fnv_32a_buf(void *buf, size_t len, unsigned hval)
124 {
125 unsigned char *bp = buf;
126 unsigned char *be = bp + len;
127 while (bp < be) {
128 hval ^= (unsigned) *bp++;
129 hval +=
130 (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) +
131 (hval << 24);
132 }
133 return hval;
134 }
135 static inline unsigned fnv_32a_str(char *str, unsigned hval)
136 {
137 unsigned char *s = (unsigned char *) str;
138 while (*s) {
139 hval ^= (unsigned) *s++;
140 hval +=
141 (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) +
142 (hval << 24);
143 }
144 return hval;
145 }
146
147 #endif /* LIBASS_UTILS_H */