/* Arithmetic Coding Implementation - Expansion version 0.0.0
Copyright Feb. 1993
Gordon V. Cormack Feb. 1993
University of Waterloo
cormack@uwaterloo.ca
All rights reserved.
This code and the algorithms herein are the property of Gordon V. Cormack.
Neither the code nor any algorithm herein may be included in any software,
device, or process which is sold, exchanged for profit, or for which a
licence or royalty fee is charged.
Permission is granted to use this code for educational, research, or
commercial purposes, provided this notice is included, and provided this
code is not used as described in the above paragraph.
*/
#include
main(){
int max = 0x1000000,
min = 0,
mid,
val,
index,
i;
int bit;
char c;
int one[256], zero[256];
for (i=0;i<256;i++){
one[i] = 1;
zero[i] = 1;
}
val = getchar()<<16;
val += getchar()<<8;
val += getchar();
while(1) {
c = 0;
if (val == (max-1)) {
fprintf(stderr,"expand done\n");
break;
}
for (i=0;i<8;i++){
index = (1<*= mid) {
bit = 1;
min = mid;
one[index]++;
}
else {
bit = 0;
max = mid;
zero[index]++;
}
c = c + c + bit;
while ((max-min) < 256) {
max--;
val = (val << 8) & 0xffff00 | (getchar()& 0xff);
min = (min << 8) & 0xffff00;
max = ((max << 8) & 0xffff00) ;
if (min >= max) max = 0x1000000;
}
}
putchar(c);
}
}
*