Clear existing format issue in the codebase
Fix the clang-format warnings on the existing codes. Change-Id: I8e9e781b6f68f41a7fbd0a2116f6b35290d73dc8
This commit is contained in:
Родитель
00b46f7e02
Коммит
f4b2926d01
|
@ -23,34 +23,27 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include "config.h"
|
#include "./config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "entcode.h"
|
#include "aom_dsp/entcode.h"
|
||||||
|
|
||||||
/*CDFs for uniform probability distributions of small sizes (2 through 16,
|
/*CDFs for uniform probability distributions of small sizes (2 through 16,
|
||||||
inclusive).*/
|
inclusive).*/
|
||||||
const uint16_t OD_UNIFORM_CDFS_Q15[135] = {
|
const uint16_t OD_UNIFORM_CDFS_Q15[135] = {
|
||||||
16384, 32768,
|
16384, 32768, 10923, 21845, 32768, 8192, 16384, 24576, 32768, 6554, 13107,
|
||||||
10923, 21845, 32768,
|
19661, 26214, 32768, 5461, 10923, 16384, 21845, 27307, 32768, 4681, 9362,
|
||||||
8192, 16384, 24576, 32768,
|
14043, 18725, 23406, 28087, 32768, 4096, 8192, 12288, 16384, 20480, 24576,
|
||||||
6554, 13107, 19661, 26214, 32768,
|
28672, 32768, 3641, 7282, 10923, 14564, 18204, 21845, 25486, 29127, 32768,
|
||||||
5461, 10923, 16384, 21845, 27307, 32768,
|
3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 2979,
|
||||||
4681, 9362, 14043, 18725, 23406, 28087, 32768,
|
5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 2731,
|
||||||
4096, 8192, 12288, 16384, 20480, 24576, 28672, 32768,
|
5461, 8192, 10923, 13653, 16384, 19115, 21845, 24576, 27307, 30037, 32768,
|
||||||
3641, 7282, 10923, 14564, 18204, 21845, 25486, 29127, 32768,
|
2521, 5041, 7562, 10082, 12603, 15124, 17644, 20165, 22686, 25206, 27727,
|
||||||
3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768,
|
30247, 32768, 2341, 4681, 7022, 9362, 11703, 14043, 16384, 18725, 21065,
|
||||||
2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768,
|
23406, 25746, 28087, 30427, 32768, 2185, 4369, 6554, 8738, 10923, 13107,
|
||||||
2731, 5461, 8192, 10923, 13653, 16384, 19115, 21845, 24576, 27307, 30037,
|
15292, 17476, 19661, 21845, 24030, 26214, 28399, 30583, 32768, 2048, 4096,
|
||||||
32768,
|
6144, 8192, 10240, 12288, 14336, 16384, 18432, 20480, 22528, 24576, 26624,
|
||||||
2521, 5041, 7562, 10082, 12603, 15124, 17644, 20165, 22686, 25206, 27727,
|
28672, 30720, 32768
|
||||||
30247, 32768,
|
|
||||||
2341, 4681, 7022, 9362, 11703, 14043, 16384, 18725, 21065, 23406, 25746,
|
|
||||||
28087, 30427, 32768,
|
|
||||||
2185, 4369, 6554, 8738, 10923, 13107, 15292, 17476, 19661, 21845, 24030,
|
|
||||||
26214, 28399, 30583, 32768,
|
|
||||||
2048, 4096, 6144, 8192, 10240, 12288, 14336, 16384, 18432, 20480, 22528,
|
|
||||||
24576, 26624, 28672, 30720, 32768
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*Given the current total integer number of bits used and the current value of
|
/*Given the current total integer number of bits used and the current value of
|
||||||
|
@ -82,7 +75,7 @@ uint32_t od_ec_tell_frac(uint32_t nbits_total, uint32_t rng) {
|
||||||
l = 0;
|
l = 0;
|
||||||
for (i = OD_BITRES; i-- > 0;) {
|
for (i = OD_BITRES; i-- > 0;) {
|
||||||
int b;
|
int b;
|
||||||
rng = rng*rng >> 15;
|
rng = rng * rng >> 15;
|
||||||
b = (int)(rng >> 16);
|
b = (int)(rng >> 16);
|
||||||
l = l << 1 | b;
|
l = l << 1 | b;
|
||||||
rng >>= b;
|
rng >>= b;
|
||||||
|
|
|
@ -23,10 +23,10 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
|
||||||
|
|
||||||
#if !defined(_entcode_H)
|
#if !defined(_entcode_H)
|
||||||
# define _entcode_H (1)
|
#define _entcode_H (1)
|
||||||
# include <limits.h>
|
#include <limits.h>
|
||||||
# include <stddef.h>
|
#include <stddef.h>
|
||||||
# include "av1/common/odintrin.h"
|
#include "av1/common/odintrin.h"
|
||||||
|
|
||||||
/*Set this flag 1 to enable a "reduced overhead" version of the entropy coder.
|
/*Set this flag 1 to enable a "reduced overhead" version of the entropy coder.
|
||||||
This uses a partition function that more accurately follows the input
|
This uses a partition function that more accurately follows the input
|
||||||
|
@ -81,39 +81,38 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
|
||||||
(vs. 0.022% for the division-based partition function with r much greater
|
(vs. 0.022% for the division-based partition function with r much greater
|
||||||
than ft).
|
than ft).
|
||||||
It improves performance on ntt-short-1 by about 0.3%.*/
|
It improves performance on ntt-short-1 by about 0.3%.*/
|
||||||
# define OD_EC_REDUCED_OVERHEAD (1)
|
#define OD_EC_REDUCED_OVERHEAD (1)
|
||||||
|
|
||||||
/*OPT: od_ec_window must be at least 32 bits, but if you have fast arithmetic
|
/*OPT: od_ec_window must be at least 32 bits, but if you have fast arithmetic
|
||||||
on a larger type, you can speed up the decoder by using it here.*/
|
on a larger type, you can speed up the decoder by using it here.*/
|
||||||
typedef uint32_t od_ec_window;
|
typedef uint32_t od_ec_window;
|
||||||
|
|
||||||
# define OD_EC_WINDOW_SIZE ((int)sizeof(od_ec_window)*CHAR_BIT)
|
#define OD_EC_WINDOW_SIZE ((int)sizeof(od_ec_window) * CHAR_BIT)
|
||||||
|
|
||||||
/*Unsigned subtraction with unsigned saturation.
|
/*Unsigned subtraction with unsigned saturation.
|
||||||
This implementation of the macro is intentionally chosen to increase the
|
This implementation of the macro is intentionally chosen to increase the
|
||||||
number of common subexpressions in the reduced-overhead partition function.
|
number of common subexpressions in the reduced-overhead partition function.
|
||||||
This matters for C code, but it would not for hardware with a saturating
|
This matters for C code, but it would not for hardware with a saturating
|
||||||
subtraction instruction.*/
|
subtraction instruction.*/
|
||||||
#define OD_SUBSATU(a, b) ((a) - OD_MINI(a, b))
|
#define OD_SUBSATU(a, b) ((a)-OD_MINI(a, b))
|
||||||
|
|
||||||
/*The number of bits to use for the range-coded part of unsigned integers.*/
|
/*The number of bits to use for the range-coded part of unsigned integers.*/
|
||||||
# define OD_EC_UINT_BITS (4)
|
#define OD_EC_UINT_BITS (4)
|
||||||
|
|
||||||
/*The resolution of fractional-precision bit usage measurements, i.e.,
|
/*The resolution of fractional-precision bit usage measurements, i.e.,
|
||||||
3 => 1/8th bits.*/
|
3 => 1/8th bits.*/
|
||||||
# define OD_BITRES (3)
|
#define OD_BITRES (3)
|
||||||
|
|
||||||
extern const uint16_t OD_UNIFORM_CDFS_Q15[135];
|
extern const uint16_t OD_UNIFORM_CDFS_Q15[135];
|
||||||
|
|
||||||
/*Returns a Q15 CDF for a uniform probability distribution of the given size.
|
/*Returns a Q15 CDF for a uniform probability distribution of the given size.
|
||||||
n: The size of the distribution.
|
n: The size of the distribution.
|
||||||
This must be at least 2, and no more than 16.*/
|
This must be at least 2, and no more than 16.*/
|
||||||
# define OD_UNIFORM_CDF_Q15(n) \
|
#define OD_UNIFORM_CDF_Q15(n) (OD_UNIFORM_CDFS_Q15 + ((n) * ((n)-1) >> 1) - 1)
|
||||||
(OD_UNIFORM_CDFS_Q15 + ((n)*((n) - 1) >> 1) - 1)
|
|
||||||
|
|
||||||
/*See entcode.c for further documentation.*/
|
/*See entcode.c for further documentation.*/
|
||||||
|
|
||||||
OD_WARN_UNUSED_RESULT uint32_t od_ec_tell_frac(uint32_t nbits_total,
|
OD_WARN_UNUSED_RESULT uint32_t od_ec_tell_frac(uint32_t nbits_total,
|
||||||
uint32_t rng);
|
uint32_t rng);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -23,12 +23,12 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include "config.h"
|
#include "./config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "entdec.h"
|
#include "aom_dsp/entdec.h"
|
||||||
#if OD_ACCOUNTING
|
#if OD_ACCOUNTING
|
||||||
# include "accounting.h"
|
#include "./accounting.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*A range decoder.
|
/*A range decoder.
|
||||||
|
@ -87,7 +87,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
#if OD_ACCOUNTING
|
#if OD_ACCOUNTING
|
||||||
# define od_ec_dec_normalize(dec, dif, rng, ret, str) od_ec_dec_normalize_(dec, dif, rng, ret, str)
|
#define od_ec_dec_normalize(dec, dif, rng, ret, str) \
|
||||||
|
od_ec_dec_normalize_(dec, dif, rng, ret, str)
|
||||||
static void od_process_accounting(od_ec_dec *dec, char *str) {
|
static void od_process_accounting(od_ec_dec *dec, char *str) {
|
||||||
if (dec->acct != NULL) {
|
if (dec->acct != NULL) {
|
||||||
uint32_t tell;
|
uint32_t tell;
|
||||||
|
@ -98,7 +99,8 @@ static void od_process_accounting(od_ec_dec *dec, char *str) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# define od_ec_dec_normalize(dec, dif, rng, ret, str) od_ec_dec_normalize_(dec, dif, rng, ret)
|
#define od_ec_dec_normalize(dec, dif, rng, ret, str) \
|
||||||
|
od_ec_dec_normalize_(dec, dif, rng, ret)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*This is meant to be a large, positive constant that can still be efficiently
|
/*This is meant to be a large, positive constant that can still be efficiently
|
||||||
|
@ -139,8 +141,8 @@ static void od_ec_dec_refill(od_ec_dec *dec) {
|
||||||
ret: The value to return.
|
ret: The value to return.
|
||||||
Return: ret.
|
Return: ret.
|
||||||
This allows the compiler to jump to this function via a tail-call.*/
|
This allows the compiler to jump to this function via a tail-call.*/
|
||||||
static int od_ec_dec_normalize_(od_ec_dec *dec,
|
static int od_ec_dec_normalize_(od_ec_dec *dec, od_ec_window dif, unsigned rng,
|
||||||
od_ec_window dif, unsigned rng, int ret OD_ACC_STR) {
|
int ret OD_ACC_STR) {
|
||||||
int d;
|
int d;
|
||||||
OD_ASSERT(rng <= 65535U);
|
OD_ASSERT(rng <= 65535U);
|
||||||
d = 16 - OD_ILOG_NZ(rng);
|
d = 16 - OD_ILOG_NZ(rng);
|
||||||
|
@ -157,8 +159,8 @@ static int od_ec_dec_normalize_(od_ec_dec *dec,
|
||||||
/*Initializes the decoder.
|
/*Initializes the decoder.
|
||||||
buf: The input buffer to use.
|
buf: The input buffer to use.
|
||||||
Return: 0 on success, or a negative value on error.*/
|
Return: 0 on success, or a negative value on error.*/
|
||||||
void od_ec_dec_init(od_ec_dec *dec,
|
void od_ec_dec_init(od_ec_dec *dec, const unsigned char *buf,
|
||||||
const unsigned char *buf, uint32_t storage) {
|
uint32_t storage) {
|
||||||
dec->buf = buf;
|
dec->buf = buf;
|
||||||
dec->eptr = buf + storage;
|
dec->eptr = buf + storage;
|
||||||
dec->end_window = 0;
|
dec->end_window = 0;
|
||||||
|
@ -205,7 +207,7 @@ int od_ec_decode_bool_(od_ec_dec *dec, unsigned fz, unsigned ft OD_ACC_STR) {
|
||||||
unsigned d;
|
unsigned d;
|
||||||
unsigned e;
|
unsigned e;
|
||||||
d = r - ft;
|
d = r - ft;
|
||||||
e = OD_SUBSATU(2*d, ft);
|
e = OD_SUBSATU(2 * d, ft);
|
||||||
v = fz + OD_MINI(fz, e) + OD_MINI(OD_SUBSATU(fz, e) >> 1, d);
|
v = fz + OD_MINI(fz, e) + OD_MINI(OD_SUBSATU(fz, e) >> 1, d);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -254,7 +256,8 @@ int od_ec_decode_bool_q15_(od_ec_dec *dec, unsigned fz OD_ACC_STR) {
|
||||||
nsyms: The number of symbols in the alphabet.
|
nsyms: The number of symbols in the alphabet.
|
||||||
This should be at most 16.
|
This should be at most 16.
|
||||||
Return: The decoded symbol s.*/
|
Return: The decoded symbol s.*/
|
||||||
int od_ec_decode_cdf_(od_ec_dec *dec, const uint16_t *cdf, int nsyms OD_ACC_STR) {
|
int od_ec_decode_cdf_(od_ec_dec *dec, const uint16_t *cdf,
|
||||||
|
int nsyms OD_ACC_STR) {
|
||||||
od_ec_window dif;
|
od_ec_window dif;
|
||||||
unsigned r;
|
unsigned r;
|
||||||
unsigned c;
|
unsigned c;
|
||||||
|
@ -285,7 +288,7 @@ int od_ec_decode_cdf_(od_ec_dec *dec, const uint16_t *cdf, int nsyms OD_ACC_STR)
|
||||||
c = (unsigned)(dif >> (OD_EC_WINDOW_SIZE - 16));
|
c = (unsigned)(dif >> (OD_EC_WINDOW_SIZE - 16));
|
||||||
q = OD_MAXI((int)(c >> 1), (int)(c - d));
|
q = OD_MAXI((int)(c >> 1), (int)(c - d));
|
||||||
#if OD_EC_REDUCED_OVERHEAD
|
#if OD_EC_REDUCED_OVERHEAD
|
||||||
e = OD_SUBSATU(2*d, ft);
|
e = OD_SUBSATU(2 * d, ft);
|
||||||
/*The correctness of this inverse partition function is not obvious, but it
|
/*The correctness of this inverse partition function is not obvious, but it
|
||||||
was checked exhaustively for all possible values of r, ft, and c.
|
was checked exhaustively for all possible values of r, ft, and c.
|
||||||
TODO: It should be possible to optimize this better than the compiler,
|
TODO: It should be possible to optimize this better than the compiler,
|
||||||
|
@ -293,10 +296,10 @@ int od_ec_decode_cdf_(od_ec_dec *dec, const uint16_t *cdf, int nsyms OD_ACC_STR)
|
||||||
will not use them).
|
will not use them).
|
||||||
It would also be nice to get rid of the 32-bit dividend, as it requires a
|
It would also be nice to get rid of the 32-bit dividend, as it requires a
|
||||||
32x32->64 bit multiply to invert.*/
|
32x32->64 bit multiply to invert.*/
|
||||||
q = OD_MAXI((int)q, (int)((2*(int32_t)c + 1 - (int32_t)e)/3));
|
q = OD_MAXI((int)q, (int)((2 * (int32_t)c + 1 - (int32_t)e) / 3));
|
||||||
#endif
|
#endif
|
||||||
q >>= s;
|
q >>= s;
|
||||||
OD_ASSERT(q < ft >> s);
|
OD_ASSERT(q<ft>> s);
|
||||||
fl = 0;
|
fl = 0;
|
||||||
ret = 0;
|
ret = 0;
|
||||||
for (fh = cdf[ret]; fh <= q; fh = cdf[++ret]) fl = fh;
|
for (fh = cdf[ret]; fh <= q; fh = cdf[++ret]) fl = fh;
|
||||||
|
@ -323,8 +326,8 @@ int od_ec_decode_cdf_(od_ec_dec *dec, const uint16_t *cdf, int nsyms OD_ACC_STR)
|
||||||
nsyms: The number of symbols in the alphabet.
|
nsyms: The number of symbols in the alphabet.
|
||||||
This should be at most 16.
|
This should be at most 16.
|
||||||
Return: The decoded symbol s.*/
|
Return: The decoded symbol s.*/
|
||||||
int od_ec_decode_cdf_unscaled_(od_ec_dec *dec,
|
int od_ec_decode_cdf_unscaled_(od_ec_dec *dec, const uint16_t *cdf,
|
||||||
const uint16_t *cdf, int nsyms OD_ACC_STR) {
|
int nsyms OD_ACC_STR) {
|
||||||
od_ec_window dif;
|
od_ec_window dif;
|
||||||
unsigned r;
|
unsigned r;
|
||||||
unsigned c;
|
unsigned c;
|
||||||
|
@ -359,12 +362,12 @@ int od_ec_decode_cdf_unscaled_(od_ec_dec *dec,
|
||||||
c = (unsigned)(dif >> (OD_EC_WINDOW_SIZE - 16));
|
c = (unsigned)(dif >> (OD_EC_WINDOW_SIZE - 16));
|
||||||
q = OD_MAXI((int)(c >> 1), (int)(c - d));
|
q = OD_MAXI((int)(c >> 1), (int)(c - d));
|
||||||
#if OD_EC_REDUCED_OVERHEAD
|
#if OD_EC_REDUCED_OVERHEAD
|
||||||
e = OD_SUBSATU(2*d, ft);
|
e = OD_SUBSATU(2 * d, ft);
|
||||||
/*TODO: See TODO above.*/
|
/*TODO: See TODO above.*/
|
||||||
q = OD_MAXI((int)q, (int)((2*(int32_t)c + 1 - (int32_t)e)/3));
|
q = OD_MAXI((int)q, (int)((2 * (int32_t)c + 1 - (int32_t)e) / 3));
|
||||||
#endif
|
#endif
|
||||||
q >>= s;
|
q >>= s;
|
||||||
OD_ASSERT(q < ft >> s);
|
OD_ASSERT(q<ft>> s);
|
||||||
fl = 0;
|
fl = 0;
|
||||||
ret = 0;
|
ret = 0;
|
||||||
for (fh = cdf[ret]; fh <= q; fh = cdf[++ret]) fl = fh;
|
for (fh = cdf[ret]; fh <= q; fh = cdf[++ret]) fl = fh;
|
||||||
|
@ -399,8 +402,8 @@ int od_ec_decode_cdf_unscaled_(od_ec_dec *dec,
|
||||||
ftb: The number of bits of precision in the cumulative distribution.
|
ftb: The number of bits of precision in the cumulative distribution.
|
||||||
This must be no more than 15.
|
This must be no more than 15.
|
||||||
Return: The decoded symbol s.*/
|
Return: The decoded symbol s.*/
|
||||||
int od_ec_decode_cdf_unscaled_dyadic_(od_ec_dec *dec,
|
int od_ec_decode_cdf_unscaled_dyadic_(od_ec_dec *dec, const uint16_t *cdf,
|
||||||
const uint16_t *cdf, int nsyms, unsigned ftb OD_ACC_STR) {
|
int nsyms, unsigned ftb OD_ACC_STR) {
|
||||||
od_ec_window dif;
|
od_ec_window dif;
|
||||||
unsigned r;
|
unsigned r;
|
||||||
unsigned c;
|
unsigned c;
|
||||||
|
@ -419,9 +422,8 @@ int od_ec_decode_cdf_unscaled_dyadic_(od_ec_dec *dec,
|
||||||
ret = -1;
|
ret = -1;
|
||||||
do {
|
do {
|
||||||
u = v;
|
u = v;
|
||||||
v = cdf[++ret]*(uint32_t)r >> ftb;
|
v = cdf[++ret] * (uint32_t)r >> ftb;
|
||||||
}
|
} while (v <= c);
|
||||||
while (v <= c);
|
|
||||||
OD_ASSERT(v <= r);
|
OD_ASSERT(v <= r);
|
||||||
r = v - u;
|
r = v - u;
|
||||||
dif -= (od_ec_window)u << (OD_EC_WINDOW_SIZE - 16);
|
dif -= (od_ec_window)u << (OD_EC_WINDOW_SIZE - 16);
|
||||||
|
@ -441,8 +443,8 @@ int od_ec_decode_cdf_unscaled_dyadic_(od_ec_dec *dec,
|
||||||
nsyms: The number of symbols in the alphabet.
|
nsyms: The number of symbols in the alphabet.
|
||||||
This should be at most 16.
|
This should be at most 16.
|
||||||
Return: The decoded symbol s.*/
|
Return: The decoded symbol s.*/
|
||||||
int od_ec_decode_cdf_q15_(od_ec_dec *dec,
|
int od_ec_decode_cdf_q15_(od_ec_dec *dec, const uint16_t *cdf,
|
||||||
const uint16_t *cdf, int nsyms OD_ACC_STR) {
|
int nsyms OD_ACC_STR) {
|
||||||
return od_ec_decode_cdf_unscaled_dyadic(dec, cdf, nsyms, 15, acc_str);
|
return od_ec_decode_cdf_unscaled_dyadic(dec, cdf, nsyms, 15, acc_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -494,10 +496,9 @@ uint32_t od_ec_dec_bits_(od_ec_dec *dec, unsigned ftb OD_ACC_STR) {
|
||||||
available = OD_EC_LOTS_OF_BITS;
|
available = OD_EC_LOTS_OF_BITS;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
window |= (od_ec_window)*--eptr << available;
|
window |= (od_ec_window) * --eptr << available;
|
||||||
available += 8;
|
available += 8;
|
||||||
}
|
} while (available <= OD_EC_WINDOW_SIZE - 8);
|
||||||
while (available <= OD_EC_WINDOW_SIZE - 8);
|
|
||||||
dec->eptr = eptr;
|
dec->eptr = eptr;
|
||||||
}
|
}
|
||||||
ret = (uint32_t)window & (((uint32_t)1 << ftb) - 1);
|
ret = (uint32_t)window & (((uint32_t)1 << ftb) - 1);
|
||||||
|
@ -518,8 +519,8 @@ uint32_t od_ec_dec_bits_(od_ec_dec *dec, unsigned ftb OD_ACC_STR) {
|
||||||
This will always be slightly larger than the exact value (e.g., all
|
This will always be slightly larger than the exact value (e.g., all
|
||||||
rounding error is in the positive direction).*/
|
rounding error is in the positive direction).*/
|
||||||
int od_ec_dec_tell(od_ec_dec *dec) {
|
int od_ec_dec_tell(od_ec_dec *dec) {
|
||||||
return ((dec->end - dec->eptr) + (dec->bptr - dec->buf))*8
|
return ((dec->end - dec->eptr) + (dec->bptr - dec->buf)) * 8 - dec->cnt -
|
||||||
- dec->cnt - dec->nend_bits + dec->tell_offs;
|
dec->nend_bits + dec->tell_offs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Returns the number of bits "used" by the decoded symbols so far.
|
/*Returns the number of bits "used" by the decoded symbols so far.
|
||||||
|
|
|
@ -23,11 +23,11 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
|
||||||
|
|
||||||
#if !defined(_entdec_H)
|
#if !defined(_entdec_H)
|
||||||
# define _entdec_H (1)
|
#define _entdec_H (1)
|
||||||
# include <limits.h>
|
#include <limits.h>
|
||||||
# include "entcode.h"
|
#include "aom_dsp/entcode.h"
|
||||||
#if OD_ACCOUNTING
|
#if OD_ACCOUNTING
|
||||||
# include "accounting.h"
|
#include "./accounting.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -37,25 +37,33 @@ extern "C" {
|
||||||
typedef struct od_ec_dec od_ec_dec;
|
typedef struct od_ec_dec od_ec_dec;
|
||||||
|
|
||||||
#if OD_ACCOUNTING
|
#if OD_ACCOUNTING
|
||||||
# define OD_ACC_STR , char *acc_str
|
#define OD_ACC_STR , char *acc_str
|
||||||
# define od_ec_decode_bool(dec, fz, ft, str) od_ec_decode_bool_(dec, fz, ft, str)
|
#define od_ec_decode_bool(dec, fz, ft, str) od_ec_decode_bool_(dec, fz, ft, str)
|
||||||
# define od_ec_decode_bool_q15(dec, fz, str) od_ec_decode_bool_q15_(dec, fz, str)
|
#define od_ec_decode_bool_q15(dec, fz, str) od_ec_decode_bool_q15_(dec, fz, str)
|
||||||
# define od_ec_decode_cdf(dec, cdf, nsyms, str) od_ec_decode_cdf_(dec, cdf, nsyms, str)
|
#define od_ec_decode_cdf(dec, cdf, nsyms, str) \
|
||||||
# define od_ec_decode_cdf_q15(dec, cdf, nsyms, str) od_ec_decode_cdf_q15_(dec, cdf, nsyms, str)
|
od_ec_decode_cdf_(dec, cdf, nsyms, str)
|
||||||
# define od_ec_decode_cdf_unscaled(dec, cdf, nsyms, str) od_ec_decode_cdf_unscaled_(dec, cdf, nsyms, str)
|
#define od_ec_decode_cdf_q15(dec, cdf, nsyms, str) \
|
||||||
# define od_ec_decode_cdf_unscaled_dyadic(dec, cdf, nsyms, ftb, str) od_ec_decode_cdf_unscaled_dyadic_(dec, cdf, nsyms, ftb, str)
|
od_ec_decode_cdf_q15_(dec, cdf, nsyms, str)
|
||||||
# define od_ec_dec_uint(dec, ft, str) od_ec_dec_uint_(dec, ft, str)
|
#define od_ec_decode_cdf_unscaled(dec, cdf, nsyms, str) \
|
||||||
# define od_ec_dec_bits(dec, ftb, str) od_ec_dec_bits_(dec, ftb, str)
|
od_ec_decode_cdf_unscaled_(dec, cdf, nsyms, str)
|
||||||
|
#define od_ec_decode_cdf_unscaled_dyadic(dec, cdf, nsyms, ftb, str) \
|
||||||
|
od_ec_decode_cdf_unscaled_dyadic_(dec, cdf, nsyms, ftb, str)
|
||||||
|
#define od_ec_dec_uint(dec, ft, str) od_ec_dec_uint_(dec, ft, str)
|
||||||
|
#define od_ec_dec_bits(dec, ftb, str) od_ec_dec_bits_(dec, ftb, str)
|
||||||
#else
|
#else
|
||||||
# define OD_ACC_STR
|
#define OD_ACC_STR
|
||||||
# define od_ec_decode_bool(dec, fz, ft, str) od_ec_decode_bool_(dec, fz, ft)
|
#define od_ec_decode_bool(dec, fz, ft, str) od_ec_decode_bool_(dec, fz, ft)
|
||||||
# define od_ec_decode_bool_q15(dec, fz, str) od_ec_decode_bool_q15_(dec, fz)
|
#define od_ec_decode_bool_q15(dec, fz, str) od_ec_decode_bool_q15_(dec, fz)
|
||||||
# define od_ec_decode_cdf(dec, cdf, nsyms, str) od_ec_decode_cdf_(dec, cdf, nsyms)
|
#define od_ec_decode_cdf(dec, cdf, nsyms, str) \
|
||||||
# define od_ec_decode_cdf_q15(dec, cdf, nsyms, str) od_ec_decode_cdf_q15_(dec, cdf, nsyms)
|
od_ec_decode_cdf_(dec, cdf, nsyms)
|
||||||
# define od_ec_decode_cdf_unscaled(dec, cdf, nsyms, str) od_ec_decode_cdf_unscaled_(dec, cdf, nsyms)
|
#define od_ec_decode_cdf_q15(dec, cdf, nsyms, str) \
|
||||||
# define od_ec_decode_cdf_unscaled_dyadic(dec, cdf, nsyms, ftb, str) od_ec_decode_cdf_unscaled_dyadic_(dec, cdf, nsyms, ftb)
|
od_ec_decode_cdf_q15_(dec, cdf, nsyms)
|
||||||
# define od_ec_dec_uint(dec, ft, str) od_ec_dec_uint_(dec, ft)
|
#define od_ec_decode_cdf_unscaled(dec, cdf, nsyms, str) \
|
||||||
# define od_ec_dec_bits(dec, ftb, str) od_ec_dec_bits_(dec, ftb)
|
od_ec_decode_cdf_unscaled_(dec, cdf, nsyms)
|
||||||
|
#define od_ec_decode_cdf_unscaled_dyadic(dec, cdf, nsyms, ftb, str) \
|
||||||
|
od_ec_decode_cdf_unscaled_dyadic_(dec, cdf, nsyms, ftb)
|
||||||
|
#define od_ec_dec_uint(dec, ft, str) od_ec_dec_uint_(dec, ft)
|
||||||
|
#define od_ec_dec_bits(dec, ftb, str) od_ec_dec_bits_(dec, ftb)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*The entropy decoder context.*/
|
/*The entropy decoder context.*/
|
||||||
|
@ -93,29 +101,37 @@ struct od_ec_dec {
|
||||||
|
|
||||||
/*See entdec.c for further documentation.*/
|
/*See entdec.c for further documentation.*/
|
||||||
|
|
||||||
void od_ec_dec_init(od_ec_dec *dec,
|
void od_ec_dec_init(od_ec_dec *dec, const unsigned char *buf, uint32_t storage)
|
||||||
const unsigned char *buf, uint32_t storage)
|
OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
|
||||||
OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
|
|
||||||
|
|
||||||
OD_WARN_UNUSED_RESULT int od_ec_decode_bool_(od_ec_dec *dec, unsigned fz,
|
OD_WARN_UNUSED_RESULT int od_ec_decode_bool_(od_ec_dec *dec, unsigned fz,
|
||||||
unsigned ft OD_ACC_STR) OD_ARG_NONNULL(1);
|
unsigned ft OD_ACC_STR)
|
||||||
OD_WARN_UNUSED_RESULT int od_ec_decode_bool_q15_(od_ec_dec *dec, unsigned fz OD_ACC_STR)
|
OD_ARG_NONNULL(1);
|
||||||
OD_ARG_NONNULL(1);
|
OD_WARN_UNUSED_RESULT int od_ec_decode_bool_q15_(od_ec_dec *dec,
|
||||||
OD_WARN_UNUSED_RESULT int od_ec_decode_cdf_(od_ec_dec *dec,
|
unsigned fz OD_ACC_STR)
|
||||||
const uint16_t *cdf, int nsyms OD_ACC_STR) OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
|
OD_ARG_NONNULL(1);
|
||||||
|
OD_WARN_UNUSED_RESULT int od_ec_decode_cdf_(od_ec_dec *dec, const uint16_t *cdf,
|
||||||
|
int nsyms OD_ACC_STR)
|
||||||
|
OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
|
||||||
OD_WARN_UNUSED_RESULT int od_ec_decode_cdf_q15_(od_ec_dec *dec,
|
OD_WARN_UNUSED_RESULT int od_ec_decode_cdf_q15_(od_ec_dec *dec,
|
||||||
const uint16_t *cdf, int nsyms OD_ACC_STR) OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
|
const uint16_t *cdf,
|
||||||
|
int nsyms OD_ACC_STR)
|
||||||
|
OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
|
||||||
OD_WARN_UNUSED_RESULT int od_ec_decode_cdf_unscaled_(od_ec_dec *dec,
|
OD_WARN_UNUSED_RESULT int od_ec_decode_cdf_unscaled_(od_ec_dec *dec,
|
||||||
const uint16_t *cdf, int nsyms OD_ACC_STR) OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
|
const uint16_t *cdf,
|
||||||
OD_WARN_UNUSED_RESULT int od_ec_decode_cdf_unscaled_dyadic_(od_ec_dec *dec,
|
int nsyms OD_ACC_STR)
|
||||||
const uint16_t *cdf, int nsyms, unsigned _ftb OD_ACC_STR)
|
OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
|
||||||
OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
|
OD_WARN_UNUSED_RESULT int od_ec_decode_cdf_unscaled_dyadic_(
|
||||||
|
od_ec_dec *dec, const uint16_t *cdf, int nsyms, unsigned _ftb OD_ACC_STR)
|
||||||
|
OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
|
||||||
|
|
||||||
OD_WARN_UNUSED_RESULT uint32_t od_ec_dec_uint_(od_ec_dec *dec,
|
OD_WARN_UNUSED_RESULT uint32_t od_ec_dec_uint_(od_ec_dec *dec,
|
||||||
uint32_t ft OD_ACC_STR) OD_ARG_NONNULL(1);
|
uint32_t ft OD_ACC_STR)
|
||||||
|
OD_ARG_NONNULL(1);
|
||||||
|
|
||||||
OD_WARN_UNUSED_RESULT uint32_t od_ec_dec_bits_(od_ec_dec *dec,
|
OD_WARN_UNUSED_RESULT uint32_t od_ec_dec_bits_(od_ec_dec *dec,
|
||||||
unsigned ftb OD_ACC_STR) OD_ARG_NONNULL(1);
|
unsigned ftb OD_ACC_STR)
|
||||||
|
OD_ARG_NONNULL(1);
|
||||||
|
|
||||||
OD_WARN_UNUSED_RESULT int od_ec_dec_tell(od_ec_dec *dec) OD_ARG_NONNULL(1);
|
OD_WARN_UNUSED_RESULT int od_ec_dec_tell(od_ec_dec *dec) OD_ARG_NONNULL(1);
|
||||||
uint32_t od_ec_dec_tell_frac(od_ec_dec *dec) OD_ARG_NONNULL(1);
|
uint32_t od_ec_dec_tell_frac(od_ec_dec *dec) OD_ARG_NONNULL(1);
|
||||||
|
|
|
@ -23,12 +23,12 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include "config.h"
|
#include "./config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "entenc.h"
|
#include "aom_dsp/entenc.h"
|
||||||
|
|
||||||
/*A range encoder.
|
/*A range encoder.
|
||||||
See entdec.c and the references for implementation details \cite{Mar79,MNW98}.
|
See entdec.c and the references for implementation details \cite{Mar79,MNW98}.
|
||||||
|
@ -60,8 +60,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
|
||||||
necessary), and stores them back in the encoder context.
|
necessary), and stores them back in the encoder context.
|
||||||
low: The new value of low.
|
low: The new value of low.
|
||||||
rng: The new value of the range.*/
|
rng: The new value of the range.*/
|
||||||
static void od_ec_enc_normalize(od_ec_enc *enc,
|
static void od_ec_enc_normalize(od_ec_enc *enc, od_ec_window low,
|
||||||
od_ec_window low, unsigned rng) {
|
unsigned rng) {
|
||||||
int d;
|
int d;
|
||||||
int c;
|
int c;
|
||||||
int s;
|
int s;
|
||||||
|
@ -83,8 +83,8 @@ static void od_ec_enc_normalize(od_ec_enc *enc,
|
||||||
storage = enc->precarry_storage;
|
storage = enc->precarry_storage;
|
||||||
offs = enc->offs;
|
offs = enc->offs;
|
||||||
if (offs + 2 > storage) {
|
if (offs + 2 > storage) {
|
||||||
storage = 2*storage + 2;
|
storage = 2 * storage + 2;
|
||||||
buf = (uint16_t *)realloc(buf, sizeof(*buf)*storage);
|
buf = (uint16_t *)realloc(buf, sizeof(*buf) * storage);
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
enc->error = -1;
|
enc->error = -1;
|
||||||
enc->offs = 0;
|
enc->offs = 0;
|
||||||
|
@ -117,14 +117,13 @@ static void od_ec_enc_normalize(od_ec_enc *enc,
|
||||||
size: The initial size of the buffer, in bytes.*/
|
size: The initial size of the buffer, in bytes.*/
|
||||||
void od_ec_enc_init(od_ec_enc *enc, uint32_t size) {
|
void od_ec_enc_init(od_ec_enc *enc, uint32_t size) {
|
||||||
od_ec_enc_reset(enc);
|
od_ec_enc_reset(enc);
|
||||||
enc->buf = (unsigned char *)malloc(sizeof(*enc->buf)*size);
|
enc->buf = (unsigned char *)malloc(sizeof(*enc->buf) * size);
|
||||||
enc->storage = size;
|
enc->storage = size;
|
||||||
if (size > 0 && enc->buf == NULL) {
|
if (size > 0 && enc->buf == NULL) {
|
||||||
enc->storage = 0;
|
enc->storage = 0;
|
||||||
enc->error = -1;
|
enc->error = -1;
|
||||||
}
|
}
|
||||||
enc->precarry_buf =
|
enc->precarry_buf = (uint16_t *)malloc(sizeof(*enc->precarry_buf) * size);
|
||||||
(uint16_t *)malloc(sizeof(*enc->precarry_buf)*size);
|
|
||||||
enc->precarry_storage = size;
|
enc->precarry_storage = size;
|
||||||
if (size > 0 && enc->precarry_buf == NULL) {
|
if (size > 0 && enc->precarry_buf == NULL) {
|
||||||
enc->precarry_storage = 0;
|
enc->precarry_storage = 0;
|
||||||
|
@ -170,8 +169,8 @@ void od_ec_enc_clear(od_ec_enc *enc) {
|
||||||
value will fall.
|
value will fall.
|
||||||
ft: The sum of the frequencies of all the symbols.
|
ft: The sum of the frequencies of all the symbols.
|
||||||
This must be at least 16384, and no more than 32768.*/
|
This must be at least 16384, and no more than 32768.*/
|
||||||
static void od_ec_encode(od_ec_enc *enc,
|
static void od_ec_encode(od_ec_enc *enc, unsigned fl, unsigned fh,
|
||||||
unsigned fl, unsigned fh, unsigned ft) {
|
unsigned ft) {
|
||||||
od_ec_window l;
|
od_ec_window l;
|
||||||
unsigned r;
|
unsigned r;
|
||||||
int s;
|
int s;
|
||||||
|
@ -194,7 +193,7 @@ static void od_ec_encode(od_ec_enc *enc,
|
||||||
#if OD_EC_REDUCED_OVERHEAD
|
#if OD_EC_REDUCED_OVERHEAD
|
||||||
{
|
{
|
||||||
unsigned e;
|
unsigned e;
|
||||||
e = OD_SUBSATU(2*d, ft);
|
e = OD_SUBSATU(2 * d, ft);
|
||||||
u = fl + OD_MINI(fl, e) + OD_MINI(OD_SUBSATU(fl, e) >> 1, d);
|
u = fl + OD_MINI(fl, e) + OD_MINI(OD_SUBSATU(fl, e) >> 1, d);
|
||||||
v = fh + OD_MINI(fh, e) + OD_MINI(OD_SUBSATU(fh, e) >> 1, d);
|
v = fh + OD_MINI(fh, e) + OD_MINI(OD_SUBSATU(fh, e) >> 1, d);
|
||||||
}
|
}
|
||||||
|
@ -206,7 +205,7 @@ static void od_ec_encode(od_ec_enc *enc,
|
||||||
l += u;
|
l += u;
|
||||||
od_ec_enc_normalize(enc, l, r);
|
od_ec_enc_normalize(enc, l, r);
|
||||||
#if OD_MEASURE_EC_OVERHEAD
|
#if OD_MEASURE_EC_OVERHEAD
|
||||||
enc->entropy -= OD_LOG2((double)(fh - fl)/ft);
|
enc->entropy -= OD_LOG2((double)(fh - fl) / ft);
|
||||||
enc->nb_symbols++;
|
enc->nb_symbols++;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -237,7 +236,7 @@ static void od_ec_encode_q15(od_ec_enc *enc, unsigned fl, unsigned fh) {
|
||||||
l += u;
|
l += u;
|
||||||
od_ec_enc_normalize(enc, l, r);
|
od_ec_enc_normalize(enc, l, r);
|
||||||
#if OD_MEASURE_EC_OVERHEAD
|
#if OD_MEASURE_EC_OVERHEAD
|
||||||
enc->entropy -= OD_LOG2((double)(fh - fl)/32768.);
|
enc->entropy -= OD_LOG2((double)(fh - fl) / 32768.);
|
||||||
enc->nb_symbols++;
|
enc->nb_symbols++;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -251,8 +250,8 @@ static void od_ec_encode_q15(od_ec_enc *enc, unsigned fl, unsigned fh) {
|
||||||
be encoded.
|
be encoded.
|
||||||
ft: The sum of the frequencies of all the symbols.
|
ft: The sum of the frequencies of all the symbols.
|
||||||
This must be at least 2 and no more than 32768.*/
|
This must be at least 2 and no more than 32768.*/
|
||||||
static void od_ec_encode_unscaled(od_ec_enc *enc,
|
static void od_ec_encode_unscaled(od_ec_enc *enc, unsigned fl, unsigned fh,
|
||||||
unsigned fl, unsigned fh, unsigned ft) {
|
unsigned ft) {
|
||||||
int s;
|
int s;
|
||||||
OD_ASSERT(fl < fh);
|
OD_ASSERT(fl < fh);
|
||||||
OD_ASSERT(fh <= ft);
|
OD_ASSERT(fh <= ft);
|
||||||
|
@ -288,7 +287,7 @@ void od_ec_encode_bool(od_ec_enc *enc, int val, unsigned fz, unsigned ft) {
|
||||||
unsigned d;
|
unsigned d;
|
||||||
unsigned e;
|
unsigned e;
|
||||||
d = r - ft;
|
d = r - ft;
|
||||||
e = OD_SUBSATU(2*d, ft);
|
e = OD_SUBSATU(2 * d, ft);
|
||||||
v = fz + OD_MINI(fz, e) + OD_MINI(OD_SUBSATU(fz, e) >> 1, d);
|
v = fz + OD_MINI(fz, e) + OD_MINI(OD_SUBSATU(fz, e) >> 1, d);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -298,7 +297,7 @@ void od_ec_encode_bool(od_ec_enc *enc, int val, unsigned fz, unsigned ft) {
|
||||||
r = val ? r - v : v;
|
r = val ? r - v : v;
|
||||||
od_ec_enc_normalize(enc, l, r);
|
od_ec_enc_normalize(enc, l, r);
|
||||||
#if OD_MEASURE_EC_OVERHEAD
|
#if OD_MEASURE_EC_OVERHEAD
|
||||||
enc->entropy -= OD_LOG2((double)(val ? ft - fz : fz)/ft);
|
enc->entropy -= OD_LOG2((double)(val ? ft - fz : fz) / ft);
|
||||||
enc->nb_symbols++;
|
enc->nb_symbols++;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -325,7 +324,7 @@ void od_ec_encode_bool_q15(od_ec_enc *enc, int val, unsigned fz) {
|
||||||
r = val ? r - v : v;
|
r = val ? r - v : v;
|
||||||
od_ec_enc_normalize(enc, l, r);
|
od_ec_enc_normalize(enc, l, r);
|
||||||
#if OD_MEASURE_EC_OVERHEAD
|
#if OD_MEASURE_EC_OVERHEAD
|
||||||
enc->entropy -= OD_LOG2((double)(val ? 32768 - fz : fz)/32768.);
|
enc->entropy -= OD_LOG2((double)(val ? 32768 - fz : fz) / 32768.);
|
||||||
enc->nb_symbols++;
|
enc->nb_symbols++;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -338,8 +337,7 @@ void od_ec_encode_bool_q15(od_ec_enc *enc, int val, unsigned fz) {
|
||||||
must be at least 16384, and no more than 32768.
|
must be at least 16384, and no more than 32768.
|
||||||
nsyms: The number of symbols in the alphabet.
|
nsyms: The number of symbols in the alphabet.
|
||||||
This should be at most 16.*/
|
This should be at most 16.*/
|
||||||
void od_ec_encode_cdf(od_ec_enc *enc, int s,
|
void od_ec_encode_cdf(od_ec_enc *enc, int s, const uint16_t *cdf, int nsyms) {
|
||||||
const uint16_t *cdf, int nsyms) {
|
|
||||||
OD_ASSERT(s >= 0);
|
OD_ASSERT(s >= 0);
|
||||||
OD_ASSERT(s < nsyms);
|
OD_ASSERT(s < nsyms);
|
||||||
od_ec_encode(enc, s > 0 ? cdf[s - 1] : 0, cdf[s], cdf[nsyms - 1]);
|
od_ec_encode(enc, s > 0 ? cdf[s - 1] : 0, cdf[s], cdf[nsyms - 1]);
|
||||||
|
@ -358,8 +356,8 @@ void od_ec_encode_cdf(od_ec_enc *enc, int s,
|
||||||
must be exactly 32768.
|
must be exactly 32768.
|
||||||
nsyms: The number of symbols in the alphabet.
|
nsyms: The number of symbols in the alphabet.
|
||||||
This should be at most 16.*/
|
This should be at most 16.*/
|
||||||
void od_ec_encode_cdf_q15(od_ec_enc *enc, int s,
|
void od_ec_encode_cdf_q15(od_ec_enc *enc, int s, const uint16_t *cdf,
|
||||||
const uint16_t *cdf, int nsyms) {
|
int nsyms) {
|
||||||
(void)nsyms;
|
(void)nsyms;
|
||||||
OD_ASSERT(s >= 0);
|
OD_ASSERT(s >= 0);
|
||||||
OD_ASSERT(s < nsyms);
|
OD_ASSERT(s < nsyms);
|
||||||
|
@ -375,8 +373,8 @@ void od_ec_encode_cdf_q15(od_ec_enc *enc, int s,
|
||||||
must be at least 2, and no more than 32768.
|
must be at least 2, and no more than 32768.
|
||||||
nsyms: The number of symbols in the alphabet.
|
nsyms: The number of symbols in the alphabet.
|
||||||
This should be at most 16.*/
|
This should be at most 16.*/
|
||||||
void od_ec_encode_cdf_unscaled(od_ec_enc *enc, int s,
|
void od_ec_encode_cdf_unscaled(od_ec_enc *enc, int s, const uint16_t *cdf,
|
||||||
const uint16_t *cdf, int nsyms) {
|
int nsyms) {
|
||||||
OD_ASSERT(s >= 0);
|
OD_ASSERT(s >= 0);
|
||||||
OD_ASSERT(s < nsyms);
|
OD_ASSERT(s < nsyms);
|
||||||
od_ec_encode_unscaled(enc, s > 0 ? cdf[s - 1] : 0, cdf[s], cdf[nsyms - 1]);
|
od_ec_encode_unscaled(enc, s > 0 ? cdf[s - 1] : 0, cdf[s], cdf[nsyms - 1]);
|
||||||
|
@ -394,14 +392,15 @@ void od_ec_encode_cdf_unscaled(od_ec_enc *enc, int s,
|
||||||
ftb: The number of bits of precision in the cumulative distribution.
|
ftb: The number of bits of precision in the cumulative distribution.
|
||||||
This must be no more than 15.*/
|
This must be no more than 15.*/
|
||||||
void od_ec_encode_cdf_unscaled_dyadic(od_ec_enc *enc, int s,
|
void od_ec_encode_cdf_unscaled_dyadic(od_ec_enc *enc, int s,
|
||||||
const uint16_t *cdf, int nsyms, unsigned ftb) {
|
const uint16_t *cdf, int nsyms,
|
||||||
|
unsigned ftb) {
|
||||||
(void)nsyms;
|
(void)nsyms;
|
||||||
OD_ASSERT(s >= 0);
|
OD_ASSERT(s >= 0);
|
||||||
OD_ASSERT(s < nsyms);
|
OD_ASSERT(s < nsyms);
|
||||||
OD_ASSERT(ftb <= 15);
|
OD_ASSERT(ftb <= 15);
|
||||||
OD_ASSERT(cdf[nsyms - 1] == 1U << ftb);
|
OD_ASSERT(cdf[nsyms - 1] == 1U << ftb);
|
||||||
od_ec_encode_q15(enc,
|
od_ec_encode_q15(enc, s > 0 ? cdf[s - 1] << (15 - ftb) : 0,
|
||||||
s > 0 ? cdf[s - 1] << (15 - ftb) : 0, cdf[s] << (15 - ftb));
|
cdf[s] << (15 - ftb));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Encodes a raw unsigned integer in the stream.
|
/*Encodes a raw unsigned integer in the stream.
|
||||||
|
@ -420,8 +419,9 @@ void od_ec_enc_uint(od_ec_enc *enc, uint32_t fl, uint32_t ft) {
|
||||||
ft1 = (int)(ft >> ftb) + 1;
|
ft1 = (int)(ft >> ftb) + 1;
|
||||||
od_ec_encode_cdf_q15(enc, (int)(fl >> ftb), OD_UNIFORM_CDF_Q15(ft1), ft1);
|
od_ec_encode_cdf_q15(enc, (int)(fl >> ftb), OD_UNIFORM_CDF_Q15(ft1), ft1);
|
||||||
od_ec_enc_bits(enc, fl & (((uint32_t)1 << ftb) - 1), ftb);
|
od_ec_enc_bits(enc, fl & (((uint32_t)1 << ftb) - 1), ftb);
|
||||||
|
} else {
|
||||||
|
od_ec_encode_cdf_q15(enc, (int)fl, OD_UNIFORM_CDF_Q15(ft), (int)ft);
|
||||||
}
|
}
|
||||||
else od_ec_encode_cdf_q15(enc, (int)fl, OD_UNIFORM_CDF_Q15(ft), (int)ft);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Encodes a sequence of raw bits in the stream.
|
/*Encodes a sequence of raw bits in the stream.
|
||||||
|
@ -448,15 +448,15 @@ void od_ec_enc_bits(od_ec_enc *enc, uint32_t fl, unsigned ftb) {
|
||||||
if (end_offs + (OD_EC_WINDOW_SIZE >> 3) >= storage) {
|
if (end_offs + (OD_EC_WINDOW_SIZE >> 3) >= storage) {
|
||||||
unsigned char *new_buf;
|
unsigned char *new_buf;
|
||||||
uint32_t new_storage;
|
uint32_t new_storage;
|
||||||
new_storage = 2*storage + (OD_EC_WINDOW_SIZE >> 3);
|
new_storage = 2 * storage + (OD_EC_WINDOW_SIZE >> 3);
|
||||||
new_buf = (unsigned char *)malloc(sizeof(*new_buf)*new_storage);
|
new_buf = (unsigned char *)malloc(sizeof(*new_buf) * new_storage);
|
||||||
if (new_buf == NULL) {
|
if (new_buf == NULL) {
|
||||||
enc->error = -1;
|
enc->error = -1;
|
||||||
enc->end_offs = 0;
|
enc->end_offs = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
OD_COPY(new_buf + new_storage - end_offs,
|
OD_COPY(new_buf + new_storage - end_offs, buf + storage - end_offs,
|
||||||
buf + storage - end_offs, end_offs);
|
end_offs);
|
||||||
storage = new_storage;
|
storage = new_storage;
|
||||||
free(buf);
|
free(buf);
|
||||||
enc->buf = buf = new_buf;
|
enc->buf = buf = new_buf;
|
||||||
|
@ -467,8 +467,7 @@ void od_ec_enc_bits(od_ec_enc *enc, uint32_t fl, unsigned ftb) {
|
||||||
buf[storage - ++end_offs] = (unsigned char)end_window;
|
buf[storage - ++end_offs] = (unsigned char)end_window;
|
||||||
end_window >>= 8;
|
end_window >>= 8;
|
||||||
nend_bits -= 8;
|
nend_bits -= 8;
|
||||||
}
|
} while (nend_bits >= 8);
|
||||||
while (nend_bits >= 8);
|
|
||||||
enc->end_offs = end_offs;
|
enc->end_offs = end_offs;
|
||||||
}
|
}
|
||||||
OD_ASSERT(nend_bits + ftb <= OD_EC_WINDOW_SIZE);
|
OD_ASSERT(nend_bits + ftb <= OD_EC_WINDOW_SIZE);
|
||||||
|
@ -503,19 +502,19 @@ void od_ec_enc_patch_initial_bits(od_ec_enc *enc, unsigned val, int nbits) {
|
||||||
if (enc->offs > 0) {
|
if (enc->offs > 0) {
|
||||||
/*The first byte has been finalized.*/
|
/*The first byte has been finalized.*/
|
||||||
enc->precarry_buf[0] =
|
enc->precarry_buf[0] =
|
||||||
(uint16_t)((enc->precarry_buf[0] & ~mask) | val << shift);
|
(uint16_t)((enc->precarry_buf[0] & ~mask) | val << shift);
|
||||||
}
|
} else if (9 + enc->cnt + (enc->rng == 0x8000) > nbits) {
|
||||||
else if (9 + enc->cnt + (enc->rng == 0x8000) > nbits) {
|
|
||||||
/*The first byte has yet to be output.*/
|
/*The first byte has yet to be output.*/
|
||||||
enc->low = (enc->low & ~((od_ec_window)mask << (16 + enc->cnt))) |
|
enc->low = (enc->low & ~((od_ec_window)mask << (16 + enc->cnt))) |
|
||||||
(od_ec_window)val << (16 + enc->cnt + shift);
|
(od_ec_window)val << (16 + enc->cnt + shift);
|
||||||
|
} else {
|
||||||
|
/*The encoder hasn't even encoded _nbits of data yet.*/
|
||||||
|
enc->error = -1;
|
||||||
}
|
}
|
||||||
/*The encoder hasn't even encoded _nbits of data yet.*/
|
|
||||||
else enc->error = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if OD_MEASURE_EC_OVERHEAD
|
#if OD_MEASURE_EC_OVERHEAD
|
||||||
# include <stdio.h>
|
#include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*Indicates that there are no more symbols to encode.
|
/*Indicates that there are no more symbols to encode.
|
||||||
|
@ -543,9 +542,10 @@ unsigned char *od_ec_enc_done(od_ec_enc *enc, uint32_t *nbytes) {
|
||||||
uint32_t tell;
|
uint32_t tell;
|
||||||
/* Don't count the 1 bit we lose to raw bits as overhead. */
|
/* Don't count the 1 bit we lose to raw bits as overhead. */
|
||||||
tell = od_ec_enc_tell(enc) - 1;
|
tell = od_ec_enc_tell(enc) - 1;
|
||||||
fprintf(stderr, "overhead: %f%%\n", 100*(tell-enc->entropy)/enc->entropy);
|
fprintf(stderr, "overhead: %f%%\n",
|
||||||
|
100 * (tell - enc->entropy) / enc->entropy);
|
||||||
fprintf(stderr, "efficiency: %f bits/symbol\n",
|
fprintf(stderr, "efficiency: %f bits/symbol\n",
|
||||||
(double)tell/enc->nb_symbols);
|
(double)tell / enc->nb_symbols);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/*We output the minimum number of bits that ensures that the symbols encoded
|
/*We output the minimum number of bits that ensures that the symbols encoded
|
||||||
|
@ -568,8 +568,8 @@ unsigned char *od_ec_enc_done(od_ec_enc *enc, uint32_t *nbytes) {
|
||||||
unsigned n;
|
unsigned n;
|
||||||
storage = enc->precarry_storage;
|
storage = enc->precarry_storage;
|
||||||
if (offs + ((s + 7) >> 3) > storage) {
|
if (offs + ((s + 7) >> 3) > storage) {
|
||||||
storage = storage*2 + ((s + 7) >> 3);
|
storage = storage * 2 + ((s + 7) >> 3);
|
||||||
buf = (uint16_t *)realloc(buf, sizeof(*buf)*storage);
|
buf = (uint16_t *)realloc(buf, sizeof(*buf) * storage);
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
enc->error = -1;
|
enc->error = -1;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -585,8 +585,7 @@ unsigned char *od_ec_enc_done(od_ec_enc *enc, uint32_t *nbytes) {
|
||||||
s -= 8;
|
s -= 8;
|
||||||
c -= 8;
|
c -= 8;
|
||||||
n >>= 8;
|
n >>= 8;
|
||||||
}
|
} while (s > 0);
|
||||||
while (s > 0);
|
|
||||||
}
|
}
|
||||||
/*Make sure there's enough room for the entropy-coded bits and the raw
|
/*Make sure there's enough room for the entropy-coded bits and the raw
|
||||||
bits.*/
|
bits.*/
|
||||||
|
@ -599,7 +598,7 @@ unsigned char *od_ec_enc_done(od_ec_enc *enc, uint32_t *nbytes) {
|
||||||
c = OD_MAXI((nend_bits - s + 7) >> 3, 0);
|
c = OD_MAXI((nend_bits - s + 7) >> 3, 0);
|
||||||
if (offs + end_offs + c > storage) {
|
if (offs + end_offs + c > storage) {
|
||||||
storage = offs + end_offs + c;
|
storage = offs + end_offs + c;
|
||||||
out = (unsigned char *)realloc(out, sizeof(*out)*storage);
|
out = (unsigned char *)realloc(out, sizeof(*out) * storage);
|
||||||
if (out == NULL) {
|
if (out == NULL) {
|
||||||
enc->error = -1;
|
enc->error = -1;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -651,7 +650,7 @@ unsigned char *od_ec_enc_done(od_ec_enc *enc, uint32_t *nbytes) {
|
||||||
int od_ec_enc_tell(od_ec_enc *enc) {
|
int od_ec_enc_tell(od_ec_enc *enc) {
|
||||||
/*The 10 here counteracts the offset of -9 baked into cnt, and adds 1 extra
|
/*The 10 here counteracts the offset of -9 baked into cnt, and adds 1 extra
|
||||||
bit, which we reserve for terminating the stream.*/
|
bit, which we reserve for terminating the stream.*/
|
||||||
return (enc->offs + enc->end_offs)*8 + enc->cnt + enc->nend_bits + 10;
|
return (enc->offs + enc->end_offs) * 8 + enc->cnt + enc->nend_bits + 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Returns the number of bits "used" by the encoded symbols so far.
|
/*Returns the number of bits "used" by the encoded symbols so far.
|
||||||
|
|
|
@ -23,9 +23,9 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
|
||||||
|
|
||||||
#if !defined(_entenc_H)
|
#if !defined(_entenc_H)
|
||||||
# define _entenc_H (1)
|
#define _entenc_H (1)
|
||||||
# include <stddef.h>
|
#include <stddef.h>
|
||||||
# include "entcode.h"
|
#include "aom_dsp/entcode.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -76,33 +76,34 @@ void od_ec_enc_reset(od_ec_enc *enc) OD_ARG_NONNULL(1);
|
||||||
void od_ec_enc_clear(od_ec_enc *enc) OD_ARG_NONNULL(1);
|
void od_ec_enc_clear(od_ec_enc *enc) OD_ARG_NONNULL(1);
|
||||||
|
|
||||||
void od_ec_encode_bool(od_ec_enc *enc, int val, unsigned fz, unsigned _ft)
|
void od_ec_encode_bool(od_ec_enc *enc, int val, unsigned fz, unsigned _ft)
|
||||||
OD_ARG_NONNULL(1);
|
OD_ARG_NONNULL(1);
|
||||||
void od_ec_encode_bool_q15(od_ec_enc *enc, int val, unsigned fz_q15)
|
void od_ec_encode_bool_q15(od_ec_enc *enc, int val, unsigned fz_q15)
|
||||||
OD_ARG_NONNULL(1);
|
OD_ARG_NONNULL(1);
|
||||||
void od_ec_encode_cdf(od_ec_enc *enc, int s,
|
void od_ec_encode_cdf(od_ec_enc *enc, int s, const uint16_t *cdf, int nsyms)
|
||||||
const uint16_t *cdf, int nsyms) OD_ARG_NONNULL(1) OD_ARG_NONNULL(3);
|
OD_ARG_NONNULL(1) OD_ARG_NONNULL(3);
|
||||||
void od_ec_encode_cdf_q15(od_ec_enc *enc, int s,
|
void od_ec_encode_cdf_q15(od_ec_enc *enc, int s, const uint16_t *cdf, int nsyms)
|
||||||
const uint16_t *cdf, int nsyms) OD_ARG_NONNULL(1) OD_ARG_NONNULL(3);
|
OD_ARG_NONNULL(1) OD_ARG_NONNULL(3);
|
||||||
void od_ec_encode_cdf_unscaled(od_ec_enc *enc, int s,
|
void od_ec_encode_cdf_unscaled(od_ec_enc *enc, int s, const uint16_t *cdf,
|
||||||
const uint16_t *cdf, int nsyms) OD_ARG_NONNULL(1) OD_ARG_NONNULL(3);
|
int nsyms) OD_ARG_NONNULL(1) OD_ARG_NONNULL(3);
|
||||||
void od_ec_encode_cdf_unscaled_dyadic(od_ec_enc *enc, int s,
|
void od_ec_encode_cdf_unscaled_dyadic(od_ec_enc *enc, int s,
|
||||||
const uint16_t *cdf, int nsyms, unsigned ftb)
|
const uint16_t *cdf, int nsyms,
|
||||||
OD_ARG_NONNULL(1) OD_ARG_NONNULL(3);
|
unsigned ftb) OD_ARG_NONNULL(1)
|
||||||
|
OD_ARG_NONNULL(3);
|
||||||
|
|
||||||
void od_ec_enc_uint(od_ec_enc *enc, uint32_t fl, uint32_t ft)
|
void od_ec_enc_uint(od_ec_enc *enc, uint32_t fl, uint32_t ft) OD_ARG_NONNULL(1);
|
||||||
OD_ARG_NONNULL(1);
|
|
||||||
|
|
||||||
void od_ec_enc_bits(od_ec_enc *enc, uint32_t fl, unsigned ftb)
|
void od_ec_enc_bits(od_ec_enc *enc, uint32_t fl, unsigned ftb)
|
||||||
OD_ARG_NONNULL(1);
|
OD_ARG_NONNULL(1);
|
||||||
|
|
||||||
void od_ec_enc_patch_initial_bits(od_ec_enc *enc, unsigned val, int nbits)
|
void od_ec_enc_patch_initial_bits(od_ec_enc *enc, unsigned val, int nbits)
|
||||||
OD_ARG_NONNULL(1);
|
OD_ARG_NONNULL(1);
|
||||||
OD_WARN_UNUSED_RESULT unsigned char *od_ec_enc_done(od_ec_enc *enc,
|
OD_WARN_UNUSED_RESULT unsigned char *od_ec_enc_done(od_ec_enc *enc,
|
||||||
uint32_t *nbytes) OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
|
uint32_t *nbytes)
|
||||||
|
OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
|
||||||
|
|
||||||
OD_WARN_UNUSED_RESULT int od_ec_enc_tell(od_ec_enc *enc) OD_ARG_NONNULL(1);
|
OD_WARN_UNUSED_RESULT int od_ec_enc_tell(od_ec_enc *enc) OD_ARG_NONNULL(1);
|
||||||
OD_WARN_UNUSED_RESULT uint32_t od_ec_enc_tell_frac(od_ec_enc *enc)
|
OD_WARN_UNUSED_RESULT uint32_t od_ec_enc_tell_frac(od_ec_enc *enc)
|
||||||
OD_ARG_NONNULL(1);
|
OD_ARG_NONNULL(1);
|
||||||
|
|
||||||
void od_ec_enc_checkpoint(od_ec_enc *dst, const od_ec_enc *src);
|
void od_ec_enc_checkpoint(od_ec_enc *dst, const od_ec_enc *src);
|
||||||
void od_ec_enc_rollback(od_ec_enc *dst, const od_ec_enc *src);
|
void od_ec_enc_rollback(od_ec_enc *dst, const od_ec_enc *src);
|
||||||
|
|
|
@ -63,69 +63,68 @@ extern uint32_t OD_DIVU_SMALL_CONSTS[OD_DIVU_DMAX][2];
|
||||||
#define OD_LOG2 AOMLOG2
|
#define OD_LOG2 AOMLOG2
|
||||||
|
|
||||||
/*Enable special features for gcc and compatible compilers.*/
|
/*Enable special features for gcc and compatible compilers.*/
|
||||||
# if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
|
#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
|
||||||
# define OD_GNUC_PREREQ(maj, min, pat) \
|
#define OD_GNUC_PREREQ(maj, min, pat) \
|
||||||
((__GNUC__ << 16) + (__GNUC_MINOR__ << 8) + __GNUC_PATCHLEVEL__ >= ((maj) << 16) + ((min) << 8) + pat)
|
((__GNUC__ << 16) + (__GNUC_MINOR__ << 8) + __GNUC_PATCHLEVEL__ >= \
|
||||||
# else
|
((maj) << 16) + ((min) << 8) + pat) // NOLINT
|
||||||
# define OD_GNUC_PREREQ(maj, min, pat) (0)
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#if OD_GNUC_PREREQ(3, 4, 0)
|
|
||||||
# define OD_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
|
|
||||||
#else
|
#else
|
||||||
# define OD_WARN_UNUSED_RESULT
|
#define OD_GNUC_PREREQ(maj, min, pat) (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if OD_GNUC_PREREQ(3, 4, 0)
|
#if OD_GNUC_PREREQ(3, 4, 0)
|
||||||
# define OD_ARG_NONNULL(x) __attribute__((__nonnull__(x)))
|
#define OD_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
|
||||||
#else
|
#else
|
||||||
# define OD_ARG_NONNULL(x)
|
#define OD_WARN_UNUSED_RESULT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
# if defined(OD_ENABLE_ASSERTIONS)
|
#if OD_GNUC_PREREQ(3, 4, 0)
|
||||||
# if OD_GNUC_PREREQ(2, 5, 0)
|
#define OD_ARG_NONNULL(x) __attribute__((__nonnull__(x)))
|
||||||
|
#else
|
||||||
|
#define OD_ARG_NONNULL(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(OD_ENABLE_ASSERTIONS)
|
||||||
|
#if OD_GNUC_PREREQ(2, 5, 0)
|
||||||
__attribute__((noreturn))
|
__attribute__((noreturn))
|
||||||
# endif
|
#endif
|
||||||
void od_fatal_impl(const char *_str, const char *_file, int _line);
|
void od_fatal_impl(const char *_str, const char *_file, int _line);
|
||||||
|
|
||||||
# define OD_FATAL(_str) (od_fatal_impl(_str, __FILE__, __LINE__))
|
#define OD_FATAL(_str) (od_fatal_impl(_str, __FILE__, __LINE__))
|
||||||
|
|
||||||
# define OD_ASSERT(_cond) \
|
#define OD_ASSERT(_cond) \
|
||||||
do { \
|
do { \
|
||||||
if (!(_cond)) { \
|
if (!(_cond)) { \
|
||||||
OD_FATAL("assertion failed: " # _cond); \
|
OD_FATAL("assertion failed: " #_cond); \
|
||||||
} \
|
} \
|
||||||
} \
|
} while (0)
|
||||||
while (0)
|
|
||||||
|
|
||||||
# define OD_ASSERT2(_cond, _message) \
|
#define OD_ASSERT2(_cond, _message) \
|
||||||
do { \
|
do { \
|
||||||
if (!(_cond)) { \
|
if (!(_cond)) { \
|
||||||
OD_FATAL("assertion failed: " # _cond "\n" _message); \
|
OD_FATAL("assertion failed: " #_cond "\n" _message); \
|
||||||
} \
|
} \
|
||||||
} \
|
} while (0)
|
||||||
while (0)
|
|
||||||
|
|
||||||
# define OD_ALWAYS_TRUE(_cond) OD_ASSERT(_cond)
|
#define OD_ALWAYS_TRUE(_cond) OD_ASSERT(_cond)
|
||||||
|
|
||||||
# else
|
#else
|
||||||
# define OD_ASSERT(_cond)
|
#define OD_ASSERT(_cond)
|
||||||
# define OD_ASSERT2(_cond, _message)
|
#define OD_ASSERT2(_cond, _message)
|
||||||
# define OD_ALWAYS_TRUE(_cond) ((void)(_cond))
|
#define OD_ALWAYS_TRUE(_cond) ((void)(_cond))
|
||||||
# endif
|
#endif
|
||||||
|
|
||||||
/** Copy n elements of memory from src to dst. The 0* term provides
|
/** Copy n elements of memory from src to dst. The 0* term provides
|
||||||
compile-time type checking */
|
compile-time type checking */
|
||||||
#if !defined(OVERRIDE_OD_COPY)
|
#if !defined(OVERRIDE_OD_COPY)
|
||||||
# define OD_COPY(dst, src, n) \
|
#define OD_COPY(dst, src, n) \
|
||||||
(memcpy((dst), (src), sizeof(*(dst))*(n) + 0*((dst) - (src))))
|
(memcpy((dst), (src), sizeof(*(dst)) * (n) + 0 * ((dst) - (src))))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** Copy n elements of memory from src to dst, allowing overlapping regions.
|
/** Copy n elements of memory from src to dst, allowing overlapping regions.
|
||||||
The 0* term provides compile-time type checking */
|
The 0* term provides compile-time type checking */
|
||||||
#if !defined(OVERRIDE_OD_MOVE)
|
#if !defined(OVERRIDE_OD_MOVE)
|
||||||
# define OD_MOVE(dst, src, n) \
|
#define OD_MOVE(dst, src, n) \
|
||||||
(memmove((dst), (src), sizeof(*(dst))*(n) + 0*((dst) - (src)) ))
|
(memmove((dst), (src), sizeof(*(dst)) * (n) + 0 * ((dst) - (src))))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
Загрузка…
Ссылка в новой задаче