clamav/libclamav/7z/Ppmd.h
Török Edvin 569bdeebe8 Merge branch 'fmapify'
* fmapify: (54 commits)
  workaround for unrar not supporting fmap.
  stfu on large lzma allocs
  handle 7z encryption detection albeit post extraction and blockencrypted
  add 7z SFX support - bb#3063
  fix makefile for external LLVM 2.9
  fix wrong interaction between prescan_cb caching and postscan_cb
  bytecode_watchdog: fix use of unaddressable data
  UPgrade lzma SDK to version 9.20 Also fmapify
  export cl_fmap_close
  cli_map_scandesc convenience API
  Introduce cli_map_scandesc to scan a portion of the existing file
  fix utf16_to_utf8, and add testcase
  cli_utf16_to_utf8
  fmapify jpeg_exploit
  fmaify cli_scan_riff
  fmapify mydoom
  export filetype cb
  factor out common code
  fix mem API of new fmap
  unit tests for new fmap scan API
  ...

Conflicts:
	libclamav/Makefile.in
	libclamav/c++/Makefile.am
	libclamav/c++/Makefile.in
	libclamav/filetypes_int.h
	libclamav/scanners.c
	libclamav/str.c
	unit_tests/check_clamav.c
2012-01-04 15:52:33 +02:00

81 lines
1.9 KiB
C

/* Ppmd.h -- PPMD codec common code
2010-03-12 : Igor Pavlov : Public domain
This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
#ifndef __PPMD_H
#define __PPMD_H
#include "Types.h"
#include "CpuArch.h"
EXTERN_C_BEGIN
#ifdef MY_CPU_32BIT
#define PPMD_32BIT
#endif
#define PPMD_INT_BITS 7
#define PPMD_PERIOD_BITS 7
#define PPMD_BIN_SCALE (1 << (PPMD_INT_BITS + PPMD_PERIOD_BITS))
#define PPMD_GET_MEAN_SPEC(summ, shift, round) (((summ) + (1 << ((shift) - (round)))) >> (shift))
#define PPMD_GET_MEAN(summ) PPMD_GET_MEAN_SPEC((summ), PPMD_PERIOD_BITS, 2)
#define PPMD_UPDATE_PROB_0(prob) ((prob) + (1 << PPMD_INT_BITS) - PPMD_GET_MEAN(prob))
#define PPMD_UPDATE_PROB_1(prob) ((prob) - PPMD_GET_MEAN(prob))
#define PPMD_N1 4
#define PPMD_N2 4
#define PPMD_N3 4
#define PPMD_N4 ((128 + 3 - 1 * PPMD_N1 - 2 * PPMD_N2 - 3 * PPMD_N3) / 4)
#define PPMD_NUM_INDEXES (PPMD_N1 + PPMD_N2 + PPMD_N3 + PPMD_N4)
/* SEE-contexts for PPM-contexts with masked symbols */
typedef struct
{
UInt16 Summ; /* Freq */
Byte Shift; /* Speed of Freq change; low Shift is for fast change */
Byte Count; /* Count to next change of Shift */
} CPpmd_See;
#define Ppmd_See_Update(p) if ((p)->Shift < PPMD_PERIOD_BITS && --(p)->Count == 0) \
{ (p)->Summ <<= 1; (p)->Count = (Byte)(3 << (p)->Shift++); }
typedef struct
{
Byte Symbol;
Byte Freq;
UInt16 SuccessorLow;
UInt16 SuccessorHigh;
} CPpmd_State;
typedef
#ifdef PPMD_32BIT
CPpmd_State *
#else
UInt32
#endif
CPpmd_State_Ref;
typedef
#ifdef PPMD_32BIT
void *
#else
UInt32
#endif
CPpmd_Void_Ref;
typedef
#ifdef PPMD_32BIT
Byte *
#else
UInt32
#endif
CPpmd_Byte_Ref;
#define PPMD_SetAllBitsIn256Bytes(p) \
{ unsigned i; for (i = 0; i < 256 / sizeof(p[0]); i += 8) { \
p[i+7] = p[i+6] = p[i+5] = p[i+4] = p[i+3] = p[i+2] = p[i+1] = p[i+0] = ~(size_t)0; }}
EXTERN_C_END
#endif