ENet  v1.3.17
Reliable UDP networking library
Macros | Enumerations | Functions
compress.c File Reference

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

#include <string.h>
#include "enet/enet.h"

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_)
 

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)
 
void * enet_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

◆ ENET_BUILDING_LIB

#define ENET_BUILDING_LIB   1

◆ ENET_CONTEXT_CREATE

#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; \
}

◆ ENET_CONTEXT_DECODE

#define ENET_CONTEXT_DECODE (   context,
  symbol_,
  code,
  value_,
  under_,
  count_,
  update,
  minimum,
  createRoot,
  visitNode,
  createRight,
  createLeft 
)

◆ ENET_CONTEXT_ENCODE

#define ENET_CONTEXT_ENCODE (   context,
  symbol_,
  value_,
  under_,
  count_,
  update,
  minimum 
)

◆ ENET_CONTEXT_NOT_EXCLUDED

#define ENET_CONTEXT_NOT_EXCLUDED (   value_,
  after,
  before 
)

◆ ENET_CONTEXT_RESCALE

#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; \
}

◆ ENET_CONTEXT_ROOT_DECODE

#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_CONTEXT_DECODE(context, symbol_, code, value_, under_, count_, update, minimum, createRoot, visitNode, createRight, createLeft)
Definition: compress.c:373

◆ ENET_CONTEXT_TRY_DECODE

#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)

◆ ENET_RANGE_CODER_DECODE

#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

◆ ENET_RANGE_CODER_ENCODE

#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

◆ ENET_RANGE_CODER_FLUSH

#define ENET_RANGE_CODER_FLUSH
Value:
{ \
while (encodeLow) \
{ \
ENET_RANGE_CODER_OUTPUT (encodeLow >> 24); \
encodeLow <<= 8; \
} \
}

◆ ENET_RANGE_CODER_FREE_SYMBOLS

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

◆ ENET_RANGE_CODER_OUTPUT

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

◆ ENET_RANGE_CODER_READ

#define ENET_RANGE_CODER_READ (   total)    ((decodeCode - decodeLow) / (decodeRange /= (total)))

◆ ENET_RANGE_CODER_SEED

#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 ++; \
}

◆ ENET_SYMBOL_CREATE

#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; \
}

Enumeration Type Documentation

◆ anonymous enum

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

◆ enet_range_coder_compress()

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

◆ enet_range_coder_create()

void* enet_range_coder_create ( void  )

◆ enet_range_coder_decompress()

size_t enet_range_coder_decompress ( void *  context,
const enet_uint8 inData,
size_t  inLimit,
enet_uint8 outData,
size_t  outLimit 
)

◆ enet_range_coder_destroy()

void enet_range_coder_destroy ( void *  context)