• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavutil/common.h

Go to the documentation of this file.
00001 /*
00002  * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
00003  *
00004  * This file is part of FFmpeg.
00005  *
00006  * FFmpeg is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * FFmpeg is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with FFmpeg; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00026 #ifndef AVUTIL_COMMON_H
00027 #define AVUTIL_COMMON_H
00028 
00029 #include <ctype.h>
00030 #include <errno.h>
00031 #include <inttypes.h>
00032 #include <limits.h>
00033 #include <math.h>
00034 #include <stdio.h>
00035 #include <stdlib.h>
00036 #include <string.h>
00037 
00038 #ifdef __GNUC__
00039 #    define AV_GCC_VERSION_AT_LEAST(x,y) (__GNUC__ > x || __GNUC__ == x && __GNUC_MINOR__ >= y)
00040 #else
00041 #    define AV_GCC_VERSION_AT_LEAST(x,y) 0
00042 #endif
00043 
00044 #ifndef av_always_inline
00045 #if AV_GCC_VERSION_AT_LEAST(3,1)
00046 #    define av_always_inline __attribute__((always_inline)) inline
00047 #else
00048 #    define av_always_inline inline
00049 #endif
00050 #endif
00051 
00052 #ifndef av_noinline
00053 #if AV_GCC_VERSION_AT_LEAST(3,1)
00054 #    define av_noinline __attribute__((noinline))
00055 #else
00056 #    define av_noinline
00057 #endif
00058 #endif
00059 
00060 #ifndef av_pure
00061 #if AV_GCC_VERSION_AT_LEAST(3,1)
00062 #    define av_pure __attribute__((pure))
00063 #else
00064 #    define av_pure
00065 #endif
00066 #endif
00067 
00068 #ifndef av_const
00069 #if AV_GCC_VERSION_AT_LEAST(2,6)
00070 #    define av_const __attribute__((const))
00071 #else
00072 #    define av_const
00073 #endif
00074 #endif
00075 
00076 #ifndef av_cold
00077 #if (!defined(__ICC) || __ICC > 1100) && AV_GCC_VERSION_AT_LEAST(4,3)
00078 #    define av_cold __attribute__((cold))
00079 #else
00080 #    define av_cold
00081 #endif
00082 #endif
00083 
00084 #ifndef av_flatten
00085 #if AV_GCC_VERSION_AT_LEAST(4,1)
00086 #    define av_flatten __attribute__((flatten))
00087 #else
00088 #    define av_flatten
00089 #endif
00090 #endif
00091 
00092 #ifndef attribute_deprecated
00093 #if AV_GCC_VERSION_AT_LEAST(3,1)
00094 #    define attribute_deprecated __attribute__((deprecated))
00095 #else
00096 #    define attribute_deprecated
00097 #endif
00098 #endif
00099 
00100 #ifndef av_unused
00101 #if defined(__GNUC__)
00102 #    define av_unused __attribute__((unused))
00103 #else
00104 #    define av_unused
00105 #endif
00106 #endif
00107 
00108 #ifndef av_uninit
00109 #if defined(__GNUC__) && !defined(__ICC)
00110 #    define av_uninit(x) x=x
00111 #else
00112 #    define av_uninit(x) x
00113 #endif
00114 #endif
00115 
00116 //rounded division & shift
00117 #define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b))
00118 /* assume b>0 */
00119 #define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
00120 #define FFABS(a) ((a) >= 0 ? (a) : (-(a)))
00121 #define FFSIGN(a) ((a) > 0 ? 1 : -1)
00122 
00123 #define FFMAX(a,b) ((a) > (b) ? (a) : (b))
00124 #define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c)
00125 #define FFMIN(a,b) ((a) > (b) ? (b) : (a))
00126 #define FFMIN3(a,b,c) FFMIN(FFMIN(a,b),c)
00127 
00128 #define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)
00129 #define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
00130 
00131 /* misc math functions */
00132 extern const uint8_t ff_log2_tab[256];
00133 
00134 static inline av_const int av_log2(unsigned int v)
00135 {
00136     int n = 0;
00137     if (v & 0xffff0000) {
00138         v >>= 16;
00139         n += 16;
00140     }
00141     if (v & 0xff00) {
00142         v >>= 8;
00143         n += 8;
00144     }
00145     n += ff_log2_tab[v];
00146 
00147     return n;
00148 }
00149 
00150 static inline av_const int av_log2_16bit(unsigned int v)
00151 {
00152     int n = 0;
00153     if (v & 0xff00) {
00154         v >>= 8;
00155         n += 8;
00156     }
00157     n += ff_log2_tab[v];
00158 
00159     return n;
00160 }
00161 
00169 static inline av_const int av_clip(int a, int amin, int amax)
00170 {
00171     if      (a < amin) return amin;
00172     else if (a > amax) return amax;
00173     else               return a;
00174 }
00175 
00181 static inline av_const uint8_t av_clip_uint8(int a)
00182 {
00183     if (a&(~255)) return (-a)>>31;
00184     else          return a;
00185 }
00186 
00192 static inline av_const int16_t av_clip_int16(int a)
00193 {
00194     if ((a+32768) & ~65535) return (a>>31) ^ 32767;
00195     else                    return a;
00196 }
00197 
00205 static inline av_const float av_clipf(float a, float amin, float amax)
00206 {
00207     if      (a < amin) return amin;
00208     else if (a > amax) return amax;
00209     else               return a;
00210 }
00211 
00212 #define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
00213 #define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
00214 
00228 #define GET_UTF8(val, GET_BYTE, ERROR)\
00229     val= GET_BYTE;\
00230     {\
00231         int ones= 7 - av_log2(val ^ 255);\
00232         if(ones==1)\
00233             ERROR\
00234         val&= 127>>ones;\
00235         while(--ones > 0){\
00236             int tmp= GET_BYTE - 128;\
00237             if(tmp>>6)\
00238                 ERROR\
00239             val= (val<<6) + tmp;\
00240         }\
00241     }
00242 
00259 #define PUT_UTF8(val, tmp, PUT_BYTE)\
00260     {\
00261         int bytes, shift;\
00262         uint32_t in = val;\
00263         if (in < 0x80) {\
00264             tmp = in;\
00265             PUT_BYTE\
00266         } else {\
00267             bytes = (av_log2(in) + 4) / 5;\
00268             shift = (bytes - 1) * 6;\
00269             tmp = (256 - (256 >> bytes)) | (in >> shift);\
00270             PUT_BYTE\
00271             while (shift >= 6) {\
00272                 shift -= 6;\
00273                 tmp = 0x80 | ((in >> shift) & 0x3f);\
00274                 PUT_BYTE\
00275             }\
00276         }\
00277     }
00278 
00279 #include "mem.h"
00280 
00281 #ifdef HAVE_AV_CONFIG_H
00282 #    include "config.h"
00283 #    include "internal.h"
00284 #endif /* HAVE_AV_CONFIG_H */
00285 
00286 #endif /* AVUTIL_COMMON_H */

Generated on Sat Feb 16 2013 09:23:15 for ffmpeg by  doxygen 1.7.1