OLD | NEW |
1 /* | 1 /* |
2 * The copyright in this software is being made available under the 2-clauses | 2 * The copyright in this software is being made available under the 2-clauses |
3 * BSD License, included below. This software may be subject to other third | 3 * BSD License, included below. This software may be subject to other third |
4 * party and contributor rights, including patent rights, and no such rights | 4 * party and contributor rights, including patent rights, and no such rights |
5 * are granted under this license. | 5 * are granted under this license. |
6 * | 6 * |
7 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium | 7 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium |
8 * Copyright (c) 2002-2014, Professor Benoit Macq | 8 * Copyright (c) 2002-2014, Professor Benoit Macq |
9 * Copyright (c) 2001-2003, David Janssens | 9 * Copyright (c) 2001-2003, David Janssens |
10 * Copyright (c) 2002-2003, Yannick Verschueren | 10 * Copyright (c) 2002-2003, Yannick Verschueren |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 static INLINE OPJ_UINT32 opj_uint_max(OPJ_UINT32 a, OPJ_UINT32 b) { | 80 static INLINE OPJ_UINT32 opj_uint_max(OPJ_UINT32 a, OPJ_UINT32 b) { |
81 return (a > b) ? a : b; | 81 return (a > b) ? a : b; |
82 } | 82 } |
83 | 83 |
84 /** | 84 /** |
85 Get the saturated sum of two unsigned integers | 85 Get the saturated sum of two unsigned integers |
86 @return Returns saturated sum of a+b | 86 @return Returns saturated sum of a+b |
87 */ | 87 */ |
88 static INLINE OPJ_UINT32 opj_uint_adds(OPJ_UINT32 a, OPJ_UINT32 b) { | 88 static INLINE OPJ_UINT32 opj_uint_adds(OPJ_UINT32 a, OPJ_UINT32 b) { |
89 OPJ_UINT64 sum = (OPJ_UINT64)a + (OPJ_UINT64)b; | 89 OPJ_UINT64 sum = (OPJ_UINT64)a + (OPJ_UINT64)b; |
90 » return -(OPJ_UINT32)(sum >> 32) | (OPJ_UINT32)sum; | 90 » return (OPJ_UINT32)(-(OPJ_INT32)(sum >> 32)) | (OPJ_UINT32)sum; |
91 } | 91 } |
92 | 92 |
93 /** | 93 /** |
94 Clamp an integer inside an interval | 94 Clamp an integer inside an interval |
95 @return | 95 @return |
96 <ul> | 96 <ul> |
97 <li>Returns a if (min < a < max) | 97 <li>Returns a if (min < a < max) |
98 <li>Returns max if (a > max) | 98 <li>Returns max if (a > max) |
99 <li>Returns min if (a < min) | 99 <li>Returns min if (a < min) |
100 </ul> | 100 </ul> |
(...skipping 27 matching lines...) Expand all Loading... |
128 static INLINE OPJ_UINT32 opj_uint_ceildiv(OPJ_UINT32 a, OPJ_UINT32 b) { | 128 static INLINE OPJ_UINT32 opj_uint_ceildiv(OPJ_UINT32 a, OPJ_UINT32 b) { |
129 assert(b); | 129 assert(b); |
130 return (a + b - 1) / b; | 130 return (a + b - 1) / b; |
131 } | 131 } |
132 | 132 |
133 /** | 133 /** |
134 Divide an integer by a power of 2 and round upwards | 134 Divide an integer by a power of 2 and round upwards |
135 @return Returns a divided by 2^b | 135 @return Returns a divided by 2^b |
136 */ | 136 */ |
137 static INLINE OPJ_INT32 opj_int_ceildivpow2(OPJ_INT32 a, OPJ_INT32 b) { | 137 static INLINE OPJ_INT32 opj_int_ceildivpow2(OPJ_INT32 a, OPJ_INT32 b) { |
138 » return (OPJ_INT32)((a + (OPJ_INT64)(1 << b) - 1) >> b); | 138 » return (OPJ_INT32)((a + ((OPJ_INT64)1 << b) - 1) >> b); |
139 } | 139 } |
| 140 |
| 141 /** |
| 142 Divide a 64bits integer by a power of 2 and round upwards |
| 143 @return Returns a divided by 2^b |
| 144 */ |
| 145 static INLINE OPJ_INT32 opj_int64_ceildivpow2(OPJ_INT64 a, OPJ_INT32 b) { |
| 146 return (OPJ_INT32)((a + ((OPJ_INT64)1 << b) - 1) >> b); |
| 147 } |
| 148 |
| 149 /** |
| 150 Divide an integer by a power of 2 and round upwards |
| 151 @return Returns a divided by 2^b |
| 152 */ |
| 153 static INLINE OPJ_UINT32 opj_uint_ceildivpow2(OPJ_UINT32 a, OPJ_UINT32 b) { |
| 154 return (OPJ_UINT32)((a + ((OPJ_UINT64)1U << b) - 1U) >> b); |
| 155 } |
| 156 |
140 /** | 157 /** |
141 Divide an integer by a power of 2 and round downwards | 158 Divide an integer by a power of 2 and round downwards |
142 @return Returns a divided by 2^b | 159 @return Returns a divided by 2^b |
143 */ | 160 */ |
144 static INLINE OPJ_INT32 opj_int_floordivpow2(OPJ_INT32 a, OPJ_INT32 b) { | 161 static INLINE OPJ_INT32 opj_int_floordivpow2(OPJ_INT32 a, OPJ_INT32 b) { |
145 return a >> b; | 162 return a >> b; |
146 } | 163 } |
147 /** | 164 /** |
148 Get logarithm of an integer and round downwards | 165 Get logarithm of an integer and round downwards |
149 @return Returns log2(a) | 166 @return Returns log2(a) |
(...skipping 18 matching lines...) Expand all Loading... |
168 return l; | 185 return l; |
169 } | 186 } |
170 | 187 |
171 /** | 188 /** |
172 Multiply two fixed-precision rational numbers. | 189 Multiply two fixed-precision rational numbers. |
173 @param a | 190 @param a |
174 @param b | 191 @param b |
175 @return Returns a * b | 192 @return Returns a * b |
176 */ | 193 */ |
177 static INLINE OPJ_INT32 opj_int_fix_mul(OPJ_INT32 a, OPJ_INT32 b) { | 194 static INLINE OPJ_INT32 opj_int_fix_mul(OPJ_INT32 a, OPJ_INT32 b) { |
| 195 #if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && def
ined(_M_IX86) |
| 196 OPJ_INT64 temp = __emul(a, b); |
| 197 #else |
178 OPJ_INT64 temp = (OPJ_INT64) a * (OPJ_INT64) b ; | 198 OPJ_INT64 temp = (OPJ_INT64) a * (OPJ_INT64) b ; |
| 199 #endif |
179 temp += 4096; | 200 temp += 4096; |
180 assert((temp >> 13) <= (OPJ_INT64)0x7FFFFFFF); | 201 assert((temp >> 13) <= (OPJ_INT64)0x7FFFFFFF); |
181 assert((temp >> 13) >= (-(OPJ_INT64)0x7FFFFFFF - (OPJ_INT64)1)); | 202 assert((temp >> 13) >= (-(OPJ_INT64)0x7FFFFFFF - (OPJ_INT64)1)); |
182 return (OPJ_INT32) (temp >> 13); | 203 return (OPJ_INT32) (temp >> 13); |
183 } | 204 } |
184 | 205 |
185 static INLINE OPJ_INT32 opj_int_fix_mul_t1(OPJ_INT32 a, OPJ_INT32 b) { | 206 static INLINE OPJ_INT32 opj_int_fix_mul_t1(OPJ_INT32 a, OPJ_INT32 b) { |
| 207 #if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && def
ined(_M_IX86) |
| 208 OPJ_INT64 temp = __emul(a, b); |
| 209 #else |
186 OPJ_INT64 temp = (OPJ_INT64) a * (OPJ_INT64) b ; | 210 OPJ_INT64 temp = (OPJ_INT64) a * (OPJ_INT64) b ; |
| 211 #endif |
187 temp += 4096; | 212 temp += 4096; |
188 assert((temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) <= (OPJ_INT64)0x7FFFFFF
F); | 213 assert((temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) <= (OPJ_INT64)0x7FFFFFF
F); |
189 assert((temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) >= (-(OPJ_INT64)0x7FFFF
FFF - (OPJ_INT64)1)); | 214 assert((temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) >= (-(OPJ_INT64)0x7FFFF
FFF - (OPJ_INT64)1)); |
190 return (OPJ_INT32) (temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) ; | 215 return (OPJ_INT32) (temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) ; |
191 } | 216 } |
192 | 217 |
193 /* ----------------------------------------------------------------------- */ | 218 /* ----------------------------------------------------------------------- */ |
194 /*@}*/ | 219 /*@}*/ |
195 | 220 |
196 /*@}*/ | 221 /*@}*/ |
197 | 222 |
198 #endif | 223 #endif |
OLD | NEW |