OLD | NEW |
1 /* | 1 /* |
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> | 2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> |
3 * | 3 * |
4 * This file is part of FFmpeg. | 4 * This file is part of FFmpeg. |
5 * | 5 * |
6 * FFmpeg is free software; you can redistribute it and/or | 6 * FFmpeg is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Lesser General Public | 7 * modify it under the terms of the GNU Lesser General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2.1 of the License, or (at your option) any later version. | 9 * version 2.1 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 16 matching lines...) Expand all Loading... |
27 #define AVUTIL_COMMON_H | 27 #define AVUTIL_COMMON_H |
28 | 28 |
29 #include <ctype.h> | 29 #include <ctype.h> |
30 #include <errno.h> | 30 #include <errno.h> |
31 #include <inttypes.h> | 31 #include <inttypes.h> |
32 #include <limits.h> | 32 #include <limits.h> |
33 #include <math.h> | 33 #include <math.h> |
34 #include <stdio.h> | 34 #include <stdio.h> |
35 #include <stdlib.h> | 35 #include <stdlib.h> |
36 #include <string.h> | 36 #include <string.h> |
37 | 37 #include "attributes.h" |
38 #ifdef HAVE_AV_CONFIG_H | |
39 #include "config.h" | |
40 #endif | |
41 | |
42 #ifdef __GNUC__ | |
43 # define AV_GCC_VERSION_AT_LEAST(x,y) (__GNUC__ > x || __GNUC__ == x && __GNU
C_MINOR__ >= y) | |
44 #else | |
45 # define AV_GCC_VERSION_AT_LEAST(x,y) 0 | |
46 #endif | |
47 | |
48 #ifndef av_always_inline | |
49 #if AV_GCC_VERSION_AT_LEAST(3,1) | |
50 # define av_always_inline __attribute__((always_inline)) inline | |
51 #else | |
52 # define av_always_inline inline | |
53 #endif | |
54 #endif | |
55 | |
56 #ifndef av_noinline | |
57 #if AV_GCC_VERSION_AT_LEAST(3,1) | |
58 # define av_noinline __attribute__((noinline)) | |
59 #else | |
60 # define av_noinline | |
61 #endif | |
62 #endif | |
63 | |
64 #ifndef av_pure | |
65 #if AV_GCC_VERSION_AT_LEAST(3,1) | |
66 # define av_pure __attribute__((pure)) | |
67 #else | |
68 # define av_pure | |
69 #endif | |
70 #endif | |
71 | |
72 #ifndef av_const | |
73 #if AV_GCC_VERSION_AT_LEAST(2,6) | |
74 # define av_const __attribute__((const)) | |
75 #else | |
76 # define av_const | |
77 #endif | |
78 #endif | |
79 | |
80 #ifndef av_cold | |
81 #if (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(4,3) | |
82 # define av_cold __attribute__((cold)) | |
83 #else | |
84 # define av_cold | |
85 #endif | |
86 #endif | |
87 | |
88 #ifndef av_flatten | |
89 #if (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(4,1) | |
90 # define av_flatten __attribute__((flatten)) | |
91 #else | |
92 # define av_flatten | |
93 #endif | |
94 #endif | |
95 | |
96 #ifndef attribute_deprecated | |
97 #if AV_GCC_VERSION_AT_LEAST(3,1) | |
98 # define attribute_deprecated __attribute__((deprecated)) | |
99 #else | |
100 # define attribute_deprecated | |
101 #endif | |
102 #endif | |
103 | |
104 #ifndef av_unused | |
105 #if defined(__GNUC__) | |
106 # define av_unused __attribute__((unused)) | |
107 #else | |
108 # define av_unused | |
109 #endif | |
110 #endif | |
111 | |
112 #ifndef av_uninit | |
113 #if defined(__GNUC__) && !defined(__ICC) | |
114 # define av_uninit(x) x=x | |
115 #else | |
116 # define av_uninit(x) x | |
117 #endif | |
118 #endif | |
119 | |
120 #ifdef HAVE_AV_CONFIG_H | |
121 # include "intmath.h" | |
122 #endif | |
123 | 38 |
124 //rounded division & shift | 39 //rounded division & shift |
125 #define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)
-1)>>(b)) | 40 #define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)
-1)>>(b)) |
126 /* assume b>0 */ | 41 /* assume b>0 */ |
127 #define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b)) | 42 #define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b)) |
128 #define FFABS(a) ((a) >= 0 ? (a) : (-(a))) | 43 #define FFABS(a) ((a) >= 0 ? (a) : (-(a))) |
129 #define FFSIGN(a) ((a) > 0 ? 1 : -1) | 44 #define FFSIGN(a) ((a) > 0 ? 1 : -1) |
130 | 45 |
131 #define FFMAX(a,b) ((a) > (b) ? (a) : (b)) | 46 #define FFMAX(a,b) ((a) > (b) ? (a) : (b)) |
132 #define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c) | 47 #define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c) |
133 #define FFMIN(a,b) ((a) > (b) ? (b) : (a)) | 48 #define FFMIN(a,b) ((a) > (b) ? (b) : (a)) |
134 #define FFMIN3(a,b,c) FFMIN(FFMIN(a,b),c) | 49 #define FFMIN3(a,b,c) FFMIN(FFMIN(a,b),c) |
135 | 50 |
136 #define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0) | 51 #define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0) |
137 #define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0])) | 52 #define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0])) |
138 #define FFALIGN(x, a) (((x)+(a)-1)&~((a)-1)) | 53 #define FFALIGN(x, a) (((x)+(a)-1)&~((a)-1)) |
139 | 54 |
140 /* misc math functions */ | 55 /* misc math functions */ |
141 extern const uint8_t ff_log2_tab[256]; | 56 extern const uint8_t ff_log2_tab[256]; |
142 | 57 |
143 extern const uint8_t av_reverse[256]; | 58 extern const uint8_t av_reverse[256]; |
144 | 59 |
145 #ifndef av_log2 | 60 static inline av_const int av_log2_c(unsigned int v) |
146 static inline av_const int av_log2(unsigned int v) | |
147 { | 61 { |
148 int n = 0; | 62 int n = 0; |
149 if (v & 0xffff0000) { | 63 if (v & 0xffff0000) { |
150 v >>= 16; | 64 v >>= 16; |
151 n += 16; | 65 n += 16; |
152 } | 66 } |
153 if (v & 0xff00) { | 67 if (v & 0xff00) { |
154 v >>= 8; | 68 v >>= 8; |
155 n += 8; | 69 n += 8; |
156 } | 70 } |
157 n += ff_log2_tab[v]; | 71 n += ff_log2_tab[v]; |
158 | 72 |
159 return n; | 73 return n; |
160 } | 74 } |
161 #endif | |
162 | 75 |
163 #ifndef av_log2_16bit | 76 static inline av_const int av_log2_16bit_c(unsigned int v) |
164 static inline av_const int av_log2_16bit(unsigned int v) | |
165 { | 77 { |
166 int n = 0; | 78 int n = 0; |
167 if (v & 0xff00) { | 79 if (v & 0xff00) { |
168 v >>= 8; | 80 v >>= 8; |
169 n += 8; | 81 n += 8; |
170 } | 82 } |
171 n += ff_log2_tab[v]; | 83 n += ff_log2_tab[v]; |
172 | 84 |
173 return n; | 85 return n; |
174 } | 86 } |
| 87 |
| 88 #ifdef HAVE_AV_CONFIG_H |
| 89 # include "config.h" |
| 90 # include "intmath.h" |
| 91 #endif |
| 92 |
| 93 #ifndef av_log2 |
| 94 # define av_log2 av_log2_c |
| 95 #endif |
| 96 #ifndef av_log2_16bit |
| 97 # define av_log2_16bit av_log2_16bit_c |
175 #endif | 98 #endif |
176 | 99 |
177 /** | 100 /** |
178 * Clips a signed integer value into the amin-amax range. | 101 * Clips a signed integer value into the amin-amax range. |
179 * @param a value to clip | 102 * @param a value to clip |
180 * @param amin minimum value of the clip range | 103 * @param amin minimum value of the clip range |
181 * @param amax maximum value of the clip range | 104 * @param amax maximum value of the clip range |
182 * @return clipped value | 105 * @return clipped value |
183 */ | 106 */ |
184 static inline av_const int av_clip(int a, int amin, int amax) | 107 static inline av_const int av_clip(int a, int amin, int amax) |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 tmp = (256 - (256 >> bytes)) | (in >> shift);\ | 251 tmp = (256 - (256 >> bytes)) | (in >> shift);\ |
329 PUT_BYTE\ | 252 PUT_BYTE\ |
330 while (shift >= 6) {\ | 253 while (shift >= 6) {\ |
331 shift -= 6;\ | 254 shift -= 6;\ |
332 tmp = 0x80 | ((in >> shift) & 0x3f);\ | 255 tmp = 0x80 | ((in >> shift) & 0x3f);\ |
333 PUT_BYTE\ | 256 PUT_BYTE\ |
334 }\ | 257 }\ |
335 }\ | 258 }\ |
336 } | 259 } |
337 | 260 |
| 261 /*! |
| 262 * \def PUT_UTF16(val, tmp, PUT_16BIT) |
| 263 * Converts a 32-bit Unicode character to its UTF-16 encoded form (2 or 4 bytes)
. |
| 264 * \param val is an input-only argument and should be of type uint32_t. It holds |
| 265 * a UCS-4 encoded Unicode character that is to be converted to UTF-16. If |
| 266 * val is given as a function it is executed only once. |
| 267 * \param tmp is a temporary variable and should be of type uint16_t. It |
| 268 * represents an intermediate value during conversion that is to be |
| 269 * output by PUT_16BIT. |
| 270 * \param PUT_16BIT writes the converted UTF-16 data to any proper destination |
| 271 * in desired endianness. It could be a function or a statement, and uses tmp |
| 272 * as the input byte. For example, PUT_BYTE could be "*output++ = tmp;" |
| 273 * PUT_BYTE will be executed 1 or 2 times depending on input character. |
| 274 */ |
| 275 #define PUT_UTF16(val, tmp, PUT_16BIT)\ |
| 276 {\ |
| 277 uint32_t in = val;\ |
| 278 if (in < 0x10000) {\ |
| 279 tmp = in;\ |
| 280 PUT_16BIT\ |
| 281 } else {\ |
| 282 tmp = 0xD800 | ((in - 0x10000) >> 10);\ |
| 283 PUT_16BIT\ |
| 284 tmp = 0xDC00 | ((in - 0x10000) & 0x3FF);\ |
| 285 PUT_16BIT\ |
| 286 }\ |
| 287 }\ |
| 288 |
| 289 |
| 290 |
338 #include "mem.h" | 291 #include "mem.h" |
339 | 292 |
340 #ifdef HAVE_AV_CONFIG_H | 293 #ifdef HAVE_AV_CONFIG_H |
341 # include "internal.h" | 294 # include "internal.h" |
342 #endif /* HAVE_AV_CONFIG_H */ | 295 #endif /* HAVE_AV_CONFIG_H */ |
343 | 296 |
344 #endif /* AVUTIL_COMMON_H */ | 297 #endif /* AVUTIL_COMMON_H */ |
OLD | NEW |