Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > VSs > VSs__H264__App
diff libavutil/common.h @ 2:897f711a7157
rearrange to work with autoconf
| author | Nina Engelhardt <nengel@mailbox.tu-berlin.de> |
|---|---|
| date | Tue, 25 Sep 2012 15:55:33 +0200 |
| parents | |
| children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libavutil/common.h Tue Sep 25 15:55:33 2012 +0200 1.3 @@ -0,0 +1,298 @@ 1.4 +/* 1.5 + * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> 1.6 + * 1.7 + * This file is part of FFmpeg. 1.8 + * 1.9 + * FFmpeg is free software; you can redistribute it and/or 1.10 + * modify it under the terms of the GNU Lesser General Public 1.11 + * License as published by the Free Software Foundation; either 1.12 + * version 2.1 of the License, or (at your option) any later version. 1.13 + * 1.14 + * FFmpeg is distributed in the hope that it will be useful, 1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1.17 + * Lesser General Public License for more details. 1.18 + * 1.19 + * You should have received a copy of the GNU Lesser General Public 1.20 + * License along with FFmpeg; if not, write to the Free Software 1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 1.22 + */ 1.23 + 1.24 +/** 1.25 + * @file 1.26 + * common internal and external API header 1.27 + */ 1.28 + 1.29 +#ifndef AVUTIL_COMMON_H 1.30 +#define AVUTIL_COMMON_H 1.31 + 1.32 +#include <ctype.h> 1.33 +#include <errno.h> 1.34 +#include <inttypes.h> 1.35 +#include <limits.h> 1.36 +#include <math.h> 1.37 +#include <stdio.h> 1.38 +#include <stdlib.h> 1.39 +#include <string.h> 1.40 +#include "attributes.h" 1.41 + 1.42 +//rounded division & shift 1.43 +#define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b)) 1.44 +/* assume b>0 */ 1.45 +#define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b)) 1.46 +#define FFABS(a) ((a) >= 0 ? (a) : (-(a))) 1.47 +#define FFSIGN(a) ((a) > 0 ? 1 : -1) 1.48 + 1.49 +#define FFMAX(a,b) ((a) > (b) ? (a) : (b)) 1.50 +#define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c) 1.51 +#define FFMIN(a,b) ((a) > (b) ? (b) : (a)) 1.52 +#define FFMIN3(a,b,c) FFMIN(FFMIN(a,b),c) 1.53 + 1.54 +#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0) 1.55 +#define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0])) 1.56 +#define FFALIGN(x, a) (((x)+(a)-1)&~((a)-1)) 1.57 + 1.58 +/* misc math functions */ 1.59 +extern const uint8_t ff_log2_tab[256]; 1.60 + 1.61 +static inline av_const int av_log2_c(unsigned int v) 1.62 +{ 1.63 + int n = 0; 1.64 + if (v & 0xffff0000) { 1.65 + v >>= 16; 1.66 + n += 16; 1.67 + } 1.68 + if (v & 0xff00) { 1.69 + v >>= 8; 1.70 + n += 8; 1.71 + } 1.72 + n += ff_log2_tab[v]; 1.73 + 1.74 + return n; 1.75 +} 1.76 + 1.77 +static inline av_const int av_log2_16bit_c(unsigned int v) 1.78 +{ 1.79 + int n = 0; 1.80 + if (v & 0xff00) { 1.81 + v >>= 8; 1.82 + n += 8; 1.83 + } 1.84 + n += ff_log2_tab[v]; 1.85 + 1.86 + return n; 1.87 +} 1.88 + 1.89 +#ifdef HAVE_AV_CONFIG_H 1.90 +# include "config.h" 1.91 +#endif 1.92 + 1.93 +/** 1.94 + * Clips a signed integer value into the amin-amax range. 1.95 + * @param a value to clip 1.96 + * @param amin minimum value of the clip range 1.97 + * @param amax maximum value of the clip range 1.98 + * @return clipped value 1.99 + */ 1.100 +static inline av_const int av_clip(int a, int amin, int amax) 1.101 +{ 1.102 + if (a < amin) return amin; 1.103 + else if (a > amax) return amax; 1.104 + else return a; 1.105 +} 1.106 + 1.107 +/** 1.108 + * Clips a signed integer value into the 0-255 range. 1.109 + * @param a value to clip 1.110 + * @return clipped value 1.111 + */ 1.112 +static inline av_const uint8_t av_clip_uint8(int a) 1.113 +{ 1.114 + if (a&(~0xFF)) return (-a)>>31; 1.115 + else return a; 1.116 +} 1.117 + 1.118 +/** 1.119 + * Clips a signed integer value into the 0-65535 range. 1.120 + * @param a value to clip 1.121 + * @return clipped value 1.122 + */ 1.123 +static inline av_const uint16_t av_clip_uint16(int a) 1.124 +{ 1.125 + if (a&(~0xFFFF)) return (-a)>>31; 1.126 + else return a; 1.127 +} 1.128 + 1.129 +/** 1.130 + * Clips a signed integer value into the -32768,32767 range. 1.131 + * @param a value to clip 1.132 + * @return clipped value 1.133 + */ 1.134 +static inline av_const int16_t av_clip_int16(int a) 1.135 +{ 1.136 + if ((a+0x8000) & ~0xFFFF) return (a>>31) ^ 0x7FFF; 1.137 + else return a; 1.138 +} 1.139 + 1.140 +/** 1.141 + * Clips a signed 64-bit integer value into the -2147483648,2147483647 range. 1.142 + * @param a value to clip 1.143 + * @return clipped value 1.144 + */ 1.145 +static inline av_const int32_t av_clipl_int32(int64_t a) 1.146 +{ 1.147 + if ((a+0x80000000u) & ~UINT64_C(0xFFFFFFFF)) return (a>>63) ^ 0x7FFFFFFF; 1.148 + else return a; 1.149 +} 1.150 + 1.151 +/** 1.152 + * Clips a float value into the amin-amax range. 1.153 + * @param a value to clip 1.154 + * @param amin minimum value of the clip range 1.155 + * @param amax maximum value of the clip range 1.156 + * @return clipped value 1.157 + */ 1.158 +static inline av_const float av_clipf(float a, float amin, float amax) 1.159 +{ 1.160 + if (a < amin) return amin; 1.161 + else if (a > amax) return amax; 1.162 + else return a; 1.163 +} 1.164 + 1.165 +/** Computes ceil(log2(x)). 1.166 + * @param x value used to compute ceil(log2(x)) 1.167 + * @return computed ceiling of log2(x) 1.168 + */ 1.169 +static inline av_const int av_ceil_log2(int x) 1.170 +{ 1.171 + return av_log2_c((x - 1) << 1); 1.172 +} 1.173 + 1.174 +#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24)) 1.175 +#define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24)) 1.176 + 1.177 +/*! 1.178 + * \def GET_UTF8(val, GET_BYTE, ERROR) 1.179 + * Converts a UTF-8 character (up to 4 bytes long) to its 32-bit UCS-4 encoded form 1.180 + * \param val is the output and should be of type uint32_t. It holds the converted 1.181 + * UCS-4 character and should be a left value. 1.182 + * \param GET_BYTE gets UTF-8 encoded bytes from any proper source. It can be 1.183 + * a function or a statement whose return value or evaluated value is of type 1.184 + * uint8_t. It will be executed up to 4 times for values in the valid UTF-8 range, 1.185 + * and up to 7 times in the general case. 1.186 + * \param ERROR action that should be taken when an invalid UTF-8 byte is returned 1.187 + * from GET_BYTE. It should be a statement that jumps out of the macro, 1.188 + * like exit(), goto, return, break, or continue. 1.189 + */ 1.190 +#define GET_UTF8(val, GET_BYTE, ERROR)\ 1.191 + val= GET_BYTE;\ 1.192 + {\ 1.193 + int ones= 7 - av_log2(val ^ 255);\ 1.194 + if(ones==1)\ 1.195 + ERROR\ 1.196 + val&= 127>>ones;\ 1.197 + while(--ones > 0){\ 1.198 + int tmp= GET_BYTE - 128;\ 1.199 + if(tmp>>6)\ 1.200 + ERROR\ 1.201 + val= (val<<6) + tmp;\ 1.202 + }\ 1.203 + } 1.204 + 1.205 +/*! 1.206 + * \def GET_UTF16(val, GET_16BIT, ERROR) 1.207 + * Converts a UTF-16 character (2 or 4 bytes) to its 32-bit UCS-4 encoded form 1.208 + * \param val is the output and should be of type uint32_t. It holds the converted 1.209 + * UCS-4 character and should be a left value. 1.210 + * \param GET_16BIT gets two bytes of UTF-16 encoded data converted to native endianness. 1.211 + * It can be a function or a statement whose return value or evaluated value is of type 1.212 + * uint16_t. It will be executed up to 2 times. 1.213 + * \param ERROR action that should be taken when an invalid UTF-16 surrogate is 1.214 + * returned from GET_BYTE. It should be a statement that jumps out of the macro, 1.215 + * like exit(), goto, return, break, or continue. 1.216 + */ 1.217 +#define GET_UTF16(val, GET_16BIT, ERROR)\ 1.218 + val = GET_16BIT;\ 1.219 + {\ 1.220 + unsigned int hi = val - 0xD800;\ 1.221 + if (hi < 0x800) {\ 1.222 + val = GET_16BIT - 0xDC00;\ 1.223 + if (val > 0x3FFU || hi > 0x3FFU)\ 1.224 + ERROR\ 1.225 + val += (hi<<10) + 0x10000;\ 1.226 + }\ 1.227 + }\ 1.228 + 1.229 +/*! 1.230 + * \def PUT_UTF8(val, tmp, PUT_BYTE) 1.231 + * Converts a 32-bit Unicode character to its UTF-8 encoded form (up to 4 bytes long). 1.232 + * \param val is an input-only argument and should be of type uint32_t. It holds 1.233 + * a UCS-4 encoded Unicode character that is to be converted to UTF-8. If 1.234 + * val is given as a function it is executed only once. 1.235 + * \param tmp is a temporary variable and should be of type uint8_t. It 1.236 + * represents an intermediate value during conversion that is to be 1.237 + * output by PUT_BYTE. 1.238 + * \param PUT_BYTE writes the converted UTF-8 bytes to any proper destination. 1.239 + * It could be a function or a statement, and uses tmp as the input byte. 1.240 + * For example, PUT_BYTE could be "*output++ = tmp;" PUT_BYTE will be 1.241 + * executed up to 4 times for values in the valid UTF-8 range and up to 1.242 + * 7 times in the general case, depending on the length of the converted 1.243 + * Unicode character. 1.244 + */ 1.245 +#define PUT_UTF8(val, tmp, PUT_BYTE)\ 1.246 + {\ 1.247 + int bytes, shift;\ 1.248 + uint32_t in = val;\ 1.249 + if (in < 0x80) {\ 1.250 + tmp = in;\ 1.251 + PUT_BYTE\ 1.252 + } else {\ 1.253 + bytes = (av_log2(in) + 4) / 5;\ 1.254 + shift = (bytes - 1) * 6;\ 1.255 + tmp = (256 - (256 >> bytes)) | (in >> shift);\ 1.256 + PUT_BYTE\ 1.257 + while (shift >= 6) {\ 1.258 + shift -= 6;\ 1.259 + tmp = 0x80 | ((in >> shift) & 0x3f);\ 1.260 + PUT_BYTE\ 1.261 + }\ 1.262 + }\ 1.263 + } 1.264 + 1.265 +/*! 1.266 + * \def PUT_UTF16(val, tmp, PUT_16BIT) 1.267 + * Converts a 32-bit Unicode character to its UTF-16 encoded form (2 or 4 bytes). 1.268 + * \param val is an input-only argument and should be of type uint32_t. It holds 1.269 + * a UCS-4 encoded Unicode character that is to be converted to UTF-16. If 1.270 + * val is given as a function it is executed only once. 1.271 + * \param tmp is a temporary variable and should be of type uint16_t. It 1.272 + * represents an intermediate value during conversion that is to be 1.273 + * output by PUT_16BIT. 1.274 + * \param PUT_16BIT writes the converted UTF-16 data to any proper destination 1.275 + * in desired endianness. It could be a function or a statement, and uses tmp 1.276 + * as the input byte. For example, PUT_BYTE could be "*output++ = tmp;" 1.277 + * PUT_BYTE will be executed 1 or 2 times depending on input character. 1.278 + */ 1.279 +#define PUT_UTF16(val, tmp, PUT_16BIT)\ 1.280 + {\ 1.281 + uint32_t in = val;\ 1.282 + if (in < 0x10000) {\ 1.283 + tmp = in;\ 1.284 + PUT_16BIT\ 1.285 + } else {\ 1.286 + tmp = 0xD800 | ((in - 0x10000) >> 10);\ 1.287 + PUT_16BIT\ 1.288 + tmp = 0xDC00 | ((in - 0x10000) & 0x3FF);\ 1.289 + PUT_16BIT\ 1.290 + }\ 1.291 + }\ 1.292 + 1.293 + 1.294 + 1.295 +#include "mem.h" 1.296 + 1.297 +#ifdef HAVE_AV_CONFIG_H 1.298 +# include "internal.h" 1.299 +#endif /* HAVE_AV_CONFIG_H */ 1.300 + 1.301 +#endif /* AVUTIL_COMMON_H */
