2 Copyright (C) Arturo San Emeterio Campos 1999. All rights reserved.
3 Permission is granted to make verbatim copies of this file for private
4 use only. There is ABSOLUTELY NO WARRANTY. Use it at your OWN RISK.
7 Email: arturo@arturocampos.com
8 Web: http://www.arturocampos.com
10 Part of the ppmc encoder and decoder.
12 This module contains the definitions of different functions and all the
13 data structures defined by ppmc. Also contains defines.
18 #define ppmc_order4_hash_size 65536
19 #define ppmc_order4_hash_key(k,j,i,l) ( (k)+(j<<8)+(i<<1)+(l<<9) )& ppmc_order4_hash_size-1
20 #define ppmc_order3_hash_size 65536
21 #define ppmc_order3_hash_key(k,j,i) ((k)+(j<<7)+(i<<11)) & ppmc_order3_hash_size-1
22 #define ppmc_order2_hash_key(k,j) ((k)+(j<<8))
23 #define _bytes_pool_elements 125000 //this is used the first time
24 //that we allocate memory, that's
25 //the number of entries
26 #define _bytes_pool_elements_inc 125000 //if we need to alloc again, this
27 //is the number of entries to get
28 #define _context_pool_elements 50000
29 #define _context_pool_elements_inc 50000
31 #define _mempool_max_index 1000 //the number of entries in the array with
37 // This structure contains a single element of a linked lists which contains
38 // the probability distribution of a given order. This structure takes 6 bytes.
39 struct _byte_and_freq{
40 unsigned char byte; //the byte itself
41 unsigned char freq; //and the frequency of it
42 struct _byte_and_freq *next; //pointer to next element in linked list or 0
46 // This structure is used for both order-3 and order-4. It takes 20 bytes,
47 // and it can still hold another byte more. (only 19 being used)
48 // Order 2-1-0-(-1) use different structures for a faster accessing.
50 struct context *next; //next context in the hash entry
51 unsigned long order4321; //order-4-3-2-1 (or order-3-2-1 for order-3)
52 struct _byte_and_freq *prob; //pointer to linked lists containing probability distribution
53 unsigned int max_cump; //maximum cumulative probability (can't exceed (2^16)-1 )
54 unsigned int defined_bytes; //the number of bytes in this context
57 // That's the same but for order-2 where there's no hash collisions.
59 struct _byte_and_freq *prob; //pointer to linked lists containing probability distribution
60 unsigned int max_cump; //maximum cumulative probability (can't exceed (2^16)-1 )
61 unsigned int defined_bytes; //the number of bytes in this context
65 // Declaration of functions
68 // Functions for initializing
69 void ppmc_alloc_memory(void);
70 void ppmc_initialize_contexts(void);
71 void ppmc_encoder_initialize(void);
72 void ppmc_decoder_initialize(void);
73 void ppmc_free_memory(void);
74 void ppmc_flush_mem_enc(void);
75 void ppmc_flush_mem_dec(void);
77 // Functions for order-(-1)
78 void ppmc_get_prob_ordern1(void);
79 unsigned long ppmc_get_symbol_ordern1(void);
80 void ppmc_get_totf_ordern1(void);
81 void ppmc_renormalize_order1(void);
83 // Functions for order-0
84 void ppmc_get_totf_order0(void);
85 char ppmc_code_byte_order0(void);
86 void ppmc_update_order0(void);
87 void ppmc_renormalize_order0(void);
88 void ppmc_decode_order0(void);
89 void ppmc_get_escape_prob_order0(void);
90 void ppmc_get_prob_order0(void);
92 // Functions for order-1
93 void ppmc_get_totf_order1(void);
94 char ppmc_code_byte_order1(void);
95 void ppmc_update_order1(void);
96 void ppmc_renormalize_order1(void);
97 void ppmc_decode_order1(void);
98 void ppmc_get_escape_prob_order1(void);
99 void ppmc_get_prob_order1(void);
102 // Functions for order-2
103 void ppmc_get_totf_order2(void);
104 char ppmc_code_byte_order2(void);
105 void ppmc_update_order2(void);
106 void ppmc_renormalize_order2(void);
107 void ppmc_decode_order2(void);
108 void ppmc_update_dec_order2(void);
109 void ppmc_get_escape_prob_order2(void);
110 void ppmc_get_prob_order2(void);
113 // Functions for order-3
114 char ppmc_get_totf_order3(void);
115 char ppmc_code_byte_order3(void);
116 void ppmc_update_order3(void);
117 void ppmc_renormalize_order3(void);
118 void ppmc_decode_order3(void);
119 void ppmc_update_dec_order3(void);
120 void ppmc_get_escape_prob_order3(void);
121 void ppmc_get_prob_order3(void);
124 // Functions for order-4
125 char ppmc_get_totf_order4(void);
126 char ppmc_code_byte_order4(void);
127 void ppmc_update_order4(void);
128 void ppmc_renormalize_order4(void);
129 void ppmc_decode_order4(void);
130 void ppmc_update_dec_order4(void);
131 void ppmc_get_escape_prob_order4(void);
132 void ppmc_get_prob_order4(void);