📄 decomp1.c
字号:
/*
comp1.c demo program for order 1 range coder using 256 qsmodels
(c) Michael Schindler
1999
http://www.compressconsult.com/
michael@compressconsult.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. It may be that this
program violates local patents in your country, however it is
belived (NO WARRANTY!) to be patent-free here in Austria.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
decomp1 is an example decompressor able to decompress the files
produced by comp1.c
Note that I do not think that an order 0 model as here is good;
For better compression see for example my freeware szip.
http://www.compressconsult.com/szip/
or ask me as consultant what compression method fits your data best.
*/
#include <stdio.h>
#include <stdlib.h>
#ifndef unix
#include <io.h>
#include <fcntl.h>
#endif
#include <string.h>
#include <ctype.h>
#include "port.h"
#include "qsmodel.h"
#include "rangecod.h"
void usage()
{ fprintf(stderr,"decomp1 [inputfile [outputfile]]\n");
fprintf(stderr,"decomp1 (c)1999 Michael Schindler, michael@compressconsult.com\n");
exit(1);
}
int main( int argc, char *argv[] )
{ int ch, syfreq, ltfreq, lastchar=0;
rangecoder rc;
qsmodel qsm[256];
if ((argc > 3) || ((argc>0) && (argv[1][0]=='-')))
usage();
if ( argc<1 )
fprintf( stderr, "stdin" );
else
{ freopen( argv[1], "rb", stdin );
fprintf( stderr, "%s", argv[1] );
}
if ( argc<2 )
fprintf( stderr, " to stdout\n" );
else
{ freopen( argv[2], "wb", stdout );
fprintf( stderr, " to %s\n", argv[2] );
}
fprintf( stderr, "%s\n", coderversion);
#ifndef unix
setmode( fileno( stdin ), O_BINARY );
setmode( fileno( stdout ), O_BINARY );
#endif
/* init the model the same as in the compressor */
for (ch=0; ch<256; ch++)
initqsmodel(qsm+ch,257,12,2000,NULL,0);
start_decoding(&rc);
while (1)
{
ltfreq = decode_culshift(&rc,12);
ch = qsgetsym(qsm+lastchar, ltfreq);
if (ch==256) /* check for end-of-file */
break;
putc(ch,stdout);
qsgetfreq(qsm+lastchar,ch,&syfreq,<freq);
decode_update( &rc, syfreq, ltfreq, 1<<12);
qsupdate(qsm+lastchar,ch);
lastchar = ch;
}
qsgetfreq(qsm+lastchar,256,&syfreq,<freq);
decode_update( &rc, syfreq, ltfreq, 1<<12);
done_decoding(&rc);
for (ch=0; ch<256; ch++)
deleteqsmodel(qsm+ch);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -