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