enet  v1.3.12
reliable UDP networking library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
compress.c File Reference

An adaptive order-2 PPM range coder. More...

#include <string.h>
#include "enet/enet.h"
Include dependency graph for compress.c:

Macros

#define ENET_BUILDING_LIB   1
 
#define ENET_CONTEXT_CREATE(context, escapes_, minimum)
 
#define ENET_CONTEXT_DECODE(context, symbol_, code, value_, under_, count_, update, minimum, createRoot, visitNode, createRight, createLeft)
 
#define ENET_CONTEXT_ENCODE(context, symbol_, value_, under_, count_, update, minimum)
 
#define ENET_CONTEXT_NOT_EXCLUDED(value_, after, before)
 
#define ENET_CONTEXT_RESCALE(context, minimum)
 
#define ENET_CONTEXT_ROOT_DECODE(context, symbol_, code, value_, under_, count_, update, minimum, exclude)
 
#define ENET_CONTEXT_TRY_DECODE(context, symbol_, code, value_, under_, count_, update, minimum, exclude)   ENET_CONTEXT_DECODE (context, symbol_, code, value_, under_, count_, update, minimum, return 0, exclude (node -> value, after, before), return 0, return 0)
 
#define ENET_RANGE_CODER_DECODE(under, count, total)
 
#define ENET_RANGE_CODER_ENCODE(under, count, total)
 
#define ENET_RANGE_CODER_FLUSH
 
#define ENET_RANGE_CODER_FREE_SYMBOLS
 
#define ENET_RANGE_CODER_OUTPUT(value)
 
#define ENET_RANGE_CODER_READ(total)   ((decodeCode - decodeLow) / (decodeRange /= (total)))
 
#define ENET_RANGE_CODER_SEED
 
#define ENET_SYMBOL_CREATE(symbol, value_, count_)
 

Typedefs

typedef struct _ENetRangeCoder ENetRangeCoder
 
typedef struct _ENetSymbol ENetSymbol
 

Enumerations

enum  {
  ENET_RANGE_CODER_TOP = 1<<24,
  ENET_RANGE_CODER_BOTTOM = 1<<16,
  ENET_CONTEXT_SYMBOL_DELTA = 3,
  ENET_CONTEXT_SYMBOL_MINIMUM = 1,
  ENET_CONTEXT_ESCAPE_MINIMUM = 1,
  ENET_SUBCONTEXT_ORDER = 2,
  ENET_SUBCONTEXT_SYMBOL_DELTA = 2,
  ENET_SUBCONTEXT_ESCAPE_DELTA = 5
}
 

Functions

int enet_host_compress_with_range_coder (ENetHost *host)
 Sets the packet compressor the host should use to the default range coder. More...
 
size_t enet_range_coder_compress (void *context, const ENetBuffer *inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 *outData, size_t outLimit)
 
voidenet_range_coder_create (void)
 
size_t enet_range_coder_decompress (void *context, const enet_uint8 *inData, size_t inLimit, enet_uint8 *outData, size_t outLimit)
 
void enet_range_coder_destroy (void *context)
 

Detailed Description

An adaptive order-2 PPM range coder.

Macro Definition Documentation

#define ENET_BUILDING_LIB   1
#define ENET_CONTEXT_CREATE (   context,
  escapes_,
  minimum 
)
Value:
{ \
ENET_SYMBOL_CREATE (context, 0, 0); \
(context) -> escapes = escapes_; \
(context) -> total = escapes_ + 256*minimum; \
(context) -> symbols = 0; \
}
#define ENET_SYMBOL_CREATE(symbol, value_, count_)
Definition: compress.c:68

Referenced by enet_range_coder_compress(), and enet_range_coder_decompress().

#define ENET_CONTEXT_DECODE (   context,
  symbol_,
  code,
  value_,
  under_,
  count_,
  update,
  minimum,
  createRoot,
  visitNode,
  createRight,
  createLeft 
)
#define ENET_CONTEXT_ENCODE (   context,
  symbol_,
  value_,
  under_,
  count_,
  update,
  minimum 
)
#define ENET_CONTEXT_NOT_EXCLUDED (   value_,
  after,
  before 
)
#define ENET_CONTEXT_RESCALE (   context,
  minimum 
)
Value:
{ \
(context) -> total = (context) -> symbols ? enet_symbol_rescale ((context) + (context) -> symbols) : 0; \
(context) -> escapes -= (context) -> escapes >> 1; \
(context) -> total += (context) -> escapes + 256*minimum; \
}

Referenced by enet_range_coder_compress(), and enet_range_coder_decompress().

#define ENET_CONTEXT_ROOT_DECODE (   context,
  symbol_,
  code,
  value_,
  under_,
  count_,
  update,
  minimum,
  exclude 
)
Value:
ENET_CONTEXT_DECODE (context, symbol_, code, value_, under_, count_, update, minimum, \
{ \
value_ = code / minimum; \
under_ = code - code%minimum; \
ENET_SYMBOL_CREATE (symbol_, value_, update); \
(context) -> symbols = symbol_ - (context); \
}, \
exclude (node -> value, after, before), \
{ \
value_ = node->value + 1 + (code - after)/minimum; \
under_ = code - (code - after)%minimum; \
ENET_SYMBOL_CREATE (symbol_, value_, update); \
node -> right = symbol_ - node; \
}, \
{ \
value_ = node->value - 1 - (after - before - code - 1)/minimum; \
under_ = code - (after - before - code - 1)%minimum; \
ENET_SYMBOL_CREATE (symbol_, value_, update); \
node -> left = symbol_ - node; \
}) \
#define ENET_SYMBOL_CREATE(symbol, value_, count_)
Definition: compress.c:68
#define ENET_CONTEXT_DECODE(context, symbol_, code, value_, under_, count_, update, minimum, createRoot, visitNode, createRight, createLeft)
Definition: compress.c:373

Referenced by enet_range_coder_decompress().

#define ENET_CONTEXT_TRY_DECODE (   context,
  symbol_,
  code,
  value_,
  under_,
  count_,
  update,
  minimum,
  exclude 
)    ENET_CONTEXT_DECODE (context, symbol_, code, value_, under_, count_, update, minimum, return 0, exclude (node -> value, after, before), return 0, return 0)
#define ENET_RANGE_CODER_DECODE (   under,
  count,
  total 
)
Value:
{ \
decodeLow += (under) * decodeRange; \
decodeRange *= (count); \
for (;;) \
{ \
if((decodeLow ^ (decodeLow + decodeRange)) >= ENET_RANGE_CODER_TOP) \
{ \
if(decodeRange >= ENET_RANGE_CODER_BOTTOM) break; \
decodeRange = -decodeLow & (ENET_RANGE_CODER_BOTTOM - 1); \
} \
decodeCode <<= 8; \
if (inData < inEnd) \
decodeCode |= * inData ++; \
decodeRange <<= 8; \
decodeLow <<= 8; \
} \
}
Definition: compress.c:28
Definition: compress.c:27

Referenced by enet_range_coder_decompress().

#define ENET_RANGE_CODER_ENCODE (   under,
  count,
  total 
)
Value:
{ \
encodeRange /= (total); \
encodeLow += (under) * encodeRange; \
encodeRange *= (count); \
for (;;) \
{ \
if((encodeLow ^ (encodeLow + encodeRange)) >= ENET_RANGE_CODER_TOP) \
{ \
if(encodeRange >= ENET_RANGE_CODER_BOTTOM) break; \
encodeRange = -encodeLow & (ENET_RANGE_CODER_BOTTOM - 1); \
} \
ENET_RANGE_CODER_OUTPUT (encodeLow >> 24); \
encodeRange <<= 8; \
encodeLow <<= 8; \
} \
}
Definition: compress.c:28
Definition: compress.c:27
#define ENET_RANGE_CODER_OUTPUT(value)
Definition: compress.c:114

Referenced by enet_range_coder_compress().

#define ENET_RANGE_CODER_FLUSH
Value:
{ \
while (encodeLow) \
{ \
ENET_RANGE_CODER_OUTPUT (encodeLow >> 24); \
encodeLow <<= 8; \
} \
}
#define ENET_RANGE_CODER_OUTPUT(value)
Definition: compress.c:114

Referenced by enet_range_coder_compress().

#define ENET_RANGE_CODER_FREE_SYMBOLS
Value:
{ \
if (nextSymbol >= sizeof (rangeCoder -> symbols) / sizeof (ENetSymbol) - ENET_SUBCONTEXT_ORDER ) \
{ \
nextSymbol = 0; \
predicted = 0; \
order = 0; \
} \
}
struct _ENetSymbol ENetSymbol
#define ENET_CONTEXT_CREATE(context, escapes_, minimum)
Definition: compress.c:82
Definition: compress.c:31
Definition: compress.c:34
Definition: compress.c:32

Referenced by enet_range_coder_compress(), and enet_range_coder_decompress().

#define ENET_RANGE_CODER_OUTPUT (   value)
Value:
{ \
if (outData >= outEnd) \
return 0; \
* outData ++ = value; \
}

Referenced by enet_range_coder_decompress().

#define ENET_RANGE_CODER_READ (   total)    ((decodeCode - decodeLow) / (decodeRange /= (total)))
#define ENET_RANGE_CODER_SEED
Value:
{ \
if (inData < inEnd) decodeCode |= * inData ++ << 24; \
if (inData < inEnd) decodeCode |= * inData ++ << 16; \
if (inData < inEnd) decodeCode |= * inData ++ << 8; \
if (inData < inEnd) decodeCode |= * inData ++; \
}

Referenced by enet_range_coder_decompress().

#define ENET_SYMBOL_CREATE (   symbol,
  value_,
  count_ 
)
Value:
{ \
symbol = & rangeCoder -> symbols [nextSymbol ++]; \
symbol -> value = value_; \
symbol -> count = count_; \
symbol -> under = count_; \
symbol -> left = 0; \
symbol -> right = 0; \
symbol -> symbols = 0; \
symbol -> escapes = 0; \
symbol -> total = 0; \
symbol -> parent = 0; \
}

Typedef Documentation

typedef struct _ENetRangeCoder ENetRangeCoder
typedef struct _ENetSymbol ENetSymbol

Enumeration Type Documentation

anonymous enum
Enumerator
ENET_RANGE_CODER_TOP 
ENET_RANGE_CODER_BOTTOM 
ENET_CONTEXT_SYMBOL_DELTA 
ENET_CONTEXT_SYMBOL_MINIMUM 
ENET_CONTEXT_ESCAPE_MINIMUM 
ENET_SUBCONTEXT_ORDER 
ENET_SUBCONTEXT_SYMBOL_DELTA 
ENET_SUBCONTEXT_ESCAPE_DELTA 

Function Documentation

size_t enet_range_coder_compress ( void context,
const ENetBuffer inBuffers,
size_t  inBufferCount,
size_t  inLimit,
enet_uint8 outData,
size_t  outLimit 
)
void* enet_range_coder_create ( void  )

References enet_malloc().

Referenced by enet_host_compress_with_range_coder().

Here is the call graph for this function:

Here is the caller graph for this function:

void enet_range_coder_destroy ( void context)

References enet_free().

Referenced by enet_host_compress_with_range_coder().

Here is the call graph for this function:

Here is the caller graph for this function: