1 | /**************************************************************************
|
---|
2 | *
|
---|
3 | * arithcode.h -- Arithmetic coding
|
---|
4 | * Copyright (C) 1994 Alistair Moffat
|
---|
5 | *
|
---|
6 | * This program is free software; you can redistribute it and/or modify
|
---|
7 | * it under the terms of the GNU General Public License as published by
|
---|
8 | * the Free Software Foundation; either version 2 of the License, or
|
---|
9 | * (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This program is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | * GNU General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU General Public License
|
---|
17 | * along with this program; if not, write to the Free Software
|
---|
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
19 | *
|
---|
20 | * $Id: arithcode.h 3745 2003-02-20 21:20:24Z mdewsnip $
|
---|
21 | *
|
---|
22 | **************************************************************************/
|
---|
23 |
|
---|
24 | #ifndef _arithcode_h
|
---|
25 | #define _arithcode_h
|
---|
26 |
|
---|
27 | extern FILE *arith_in, *arith_out;
|
---|
28 |
|
---|
29 | #define codevaluebits 16
|
---|
30 | #if (codevaluebits<16)
|
---|
31 | typedef unsigned short codevalue;
|
---|
32 | #else
|
---|
33 | typedef unsigned long codevalue;
|
---|
34 | #endif
|
---|
35 |
|
---|
36 | #define topvalue ((codevalue)((1<<codevaluebits)-1))
|
---|
37 | #define maxfrequency ((topvalue+1)/4 + 1)
|
---|
38 |
|
---|
39 | #define firstqtr (topvalue/4+1)
|
---|
40 | #define half (2*firstqtr)
|
---|
41 | #define thirdqtr (3*firstqtr)
|
---|
42 |
|
---|
43 | #define escape_event U->totalcnt-U->notfound, U->totalcnt, U->totalcnt
|
---|
44 |
|
---|
45 | void arithmetic_encode ();
|
---|
46 | codevalue arithmetic_decode_target ();
|
---|
47 |
|
---|
48 | #define arithmetic_decode_target(totl) \
|
---|
49 | ( ((S_value-S_low+1)*(totl)-1) / (S_high-S_low+1) )
|
---|
50 |
|
---|
51 | void arithmetic_decode ();
|
---|
52 |
|
---|
53 |
|
---|
54 | extern codevalue S_low, S_high, S_value;
|
---|
55 | extern long S_bitstofollow;
|
---|
56 | extern int S_buffer, S_bitstogo;
|
---|
57 |
|
---|
58 | extern long cmpbytes, rawbytes;
|
---|
59 |
|
---|
60 | extern long CountOfBitsOut;
|
---|
61 |
|
---|
62 | void EncodeGammaDist (int Off);
|
---|
63 | int DecodeGammaDist ();
|
---|
64 |
|
---|
65 | void EncodeGammaSigned (int snum, int *pos, int *neg);
|
---|
66 | int DecodeGammaSigned (int *pos, int *neg);
|
---|
67 |
|
---|
68 |
|
---|
69 | void InitArithEncoding (void);
|
---|
70 | void InitArithDecoding (void);
|
---|
71 |
|
---|
72 | void CloseDownArithEncoding (void);
|
---|
73 | void CloseDownArithDecoding (void);
|
---|
74 |
|
---|
75 | void EncodeChecksum ();
|
---|
76 | void DecodeChecksum (char str[]);
|
---|
77 |
|
---|
78 | #endif
|
---|