Mercurial > libavutil.hg
comparison common.h @ 979:a3c26f53e6fa libavutil
Allow arch-overrides for all common.h clip and log2 functions
author | mru |
---|---|
date | Wed, 07 Jul 2010 17:27:45 +0000 |
parents | 009d2ce554b2 |
children | 3aefb6df1f86 |
comparison
equal
deleted
inserted
replaced
978:009d2ce554b2 | 979:a3c26f53e6fa |
---|---|
98 * @param a value to clip | 98 * @param a value to clip |
99 * @param amin minimum value of the clip range | 99 * @param amin minimum value of the clip range |
100 * @param amax maximum value of the clip range | 100 * @param amax maximum value of the clip range |
101 * @return clipped value | 101 * @return clipped value |
102 */ | 102 */ |
103 static inline av_const int av_clip(int a, int amin, int amax) | 103 static inline av_const int av_clip_c(int a, int amin, int amax) |
104 { | 104 { |
105 if (a < amin) return amin; | 105 if (a < amin) return amin; |
106 else if (a > amax) return amax; | 106 else if (a > amax) return amax; |
107 else return a; | 107 else return a; |
108 } | 108 } |
110 /** | 110 /** |
111 * Clip a signed integer value into the 0-255 range. | 111 * Clip a signed integer value into the 0-255 range. |
112 * @param a value to clip | 112 * @param a value to clip |
113 * @return clipped value | 113 * @return clipped value |
114 */ | 114 */ |
115 static inline av_const uint8_t av_clip_uint8(int a) | 115 static inline av_const uint8_t av_clip_uint8_c(int a) |
116 { | 116 { |
117 if (a&(~0xFF)) return (-a)>>31; | 117 if (a&(~0xFF)) return (-a)>>31; |
118 else return a; | 118 else return a; |
119 } | 119 } |
120 | 120 |
121 /** | 121 /** |
122 * Clip a signed integer value into the -128,127 range. | 122 * Clip a signed integer value into the -128,127 range. |
123 * @param a value to clip | 123 * @param a value to clip |
124 * @return clipped value | 124 * @return clipped value |
125 */ | 125 */ |
126 static inline av_const int8_t av_clip_int8(int a) | 126 static inline av_const int8_t av_clip_int8_c(int a) |
127 { | 127 { |
128 if ((a+0x80) & ~0xFF) return (a>>31) ^ 0x7F; | 128 if ((a+0x80) & ~0xFF) return (a>>31) ^ 0x7F; |
129 else return a; | 129 else return a; |
130 } | 130 } |
131 | 131 |
132 /** | 132 /** |
133 * Clip a signed integer value into the 0-65535 range. | 133 * Clip a signed integer value into the 0-65535 range. |
134 * @param a value to clip | 134 * @param a value to clip |
135 * @return clipped value | 135 * @return clipped value |
136 */ | 136 */ |
137 static inline av_const uint16_t av_clip_uint16(int a) | 137 static inline av_const uint16_t av_clip_uint16_c(int a) |
138 { | 138 { |
139 if (a&(~0xFFFF)) return (-a)>>31; | 139 if (a&(~0xFFFF)) return (-a)>>31; |
140 else return a; | 140 else return a; |
141 } | 141 } |
142 | 142 |
143 /** | 143 /** |
144 * Clip a signed integer value into the -32768,32767 range. | 144 * Clip a signed integer value into the -32768,32767 range. |
145 * @param a value to clip | 145 * @param a value to clip |
146 * @return clipped value | 146 * @return clipped value |
147 */ | 147 */ |
148 static inline av_const int16_t av_clip_int16(int a) | 148 static inline av_const int16_t av_clip_int16_c(int a) |
149 { | 149 { |
150 if ((a+0x8000) & ~0xFFFF) return (a>>31) ^ 0x7FFF; | 150 if ((a+0x8000) & ~0xFFFF) return (a>>31) ^ 0x7FFF; |
151 else return a; | 151 else return a; |
152 } | 152 } |
153 | 153 |
154 /** | 154 /** |
155 * Clip a signed 64-bit integer value into the -2147483648,2147483647 range. | 155 * Clip a signed 64-bit integer value into the -2147483648,2147483647 range. |
156 * @param a value to clip | 156 * @param a value to clip |
157 * @return clipped value | 157 * @return clipped value |
158 */ | 158 */ |
159 static inline av_const int32_t av_clipl_int32(int64_t a) | 159 static inline av_const int32_t av_clipl_int32_c(int64_t a) |
160 { | 160 { |
161 if ((a+0x80000000u) & ~UINT64_C(0xFFFFFFFF)) return (a>>63) ^ 0x7FFFFFFF; | 161 if ((a+0x80000000u) & ~UINT64_C(0xFFFFFFFF)) return (a>>63) ^ 0x7FFFFFFF; |
162 else return a; | 162 else return a; |
163 } | 163 } |
164 | 164 |
167 * @param a value to clip | 167 * @param a value to clip |
168 * @param amin minimum value of the clip range | 168 * @param amin minimum value of the clip range |
169 * @param amax maximum value of the clip range | 169 * @param amax maximum value of the clip range |
170 * @return clipped value | 170 * @return clipped value |
171 */ | 171 */ |
172 static inline av_const float av_clipf(float a, float amin, float amax) | 172 static inline av_const float av_clipf_c(float a, float amin, float amax) |
173 { | 173 { |
174 if (a < amin) return amin; | 174 if (a < amin) return amin; |
175 else if (a > amax) return amax; | 175 else if (a > amax) return amax; |
176 else return a; | 176 else return a; |
177 } | 177 } |
178 | 178 |
179 /** Compute ceil(log2(x)). | 179 /** Compute ceil(log2(x)). |
180 * @param x value used to compute ceil(log2(x)) | 180 * @param x value used to compute ceil(log2(x)) |
181 * @return computed ceiling of log2(x) | 181 * @return computed ceiling of log2(x) |
182 */ | 182 */ |
183 static inline av_const int av_ceil_log2(int x) | 183 static inline av_const int av_ceil_log2_c(int x) |
184 { | 184 { |
185 return av_log2((x - 1) << 1); | 185 return av_log2((x - 1) << 1); |
186 } | 186 } |
187 | 187 |
188 #define MKTAG(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24)) | 188 #define MKTAG(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24)) |
318 # define av_log2 av_log2_c | 318 # define av_log2 av_log2_c |
319 #endif | 319 #endif |
320 #ifndef av_log2_16bit | 320 #ifndef av_log2_16bit |
321 # define av_log2_16bit av_log2_16bit_c | 321 # define av_log2_16bit av_log2_16bit_c |
322 #endif | 322 #endif |
323 #ifndef av_ceil_log2 | |
324 # define av_ceil_log2 av_ceil_log2_c | |
325 #endif | |
326 #ifndef av_clip | |
327 # define av_clip av_clip_c | |
328 #endif | |
329 #ifndef av_clip_uint8 | |
330 # define av_clip_uint8 av_clip_uint8_c | |
331 #endif | |
332 #ifndef av_clip_int8 | |
333 # define av_clip_int8 av_clip_int8_c | |
334 #endif | |
335 #ifndef av_clip_uint16 | |
336 # define av_clip_uint16 av_clip_uint16_c | |
337 #endif | |
338 #ifndef av_clip_int16 | |
339 # define av_clip_int16 av_clip_int16_c | |
340 #endif | |
341 #ifndef av_clipl_int32 | |
342 # define av_clipl_int32 av_clipl_int32_c | |
343 #endif | |
344 #ifndef av_clipf | |
345 # define av_clipf av_clipf_c | |
346 #endif |