Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > C/C++ программирование > Общие вопросы C/C++
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 23.11.2010, 22:39   #1
denes
Заблокирован
 
Регистрация: 09.04.2010
Сообщений: 52
Вопрос Код сжатия ?

Скажите это код сжатия :/* LZWCOM - FILE COMPRESSOR UTILITY */
#include "stdio.h"
#include "debug.h"
#define FALSE 0
#define TRUE !FALSE
#define TABSIZE 4096
#define NO_PRED 0xFFFF
#define EMPTY 0xFFFF
#define NOT_FND 0xFFFF
#define UEOF ((unsigned)EOF)
struct entry {
char used;
unsigned int next; /* hi bit is 'used' flag */
unsigned int predecessor; /* 12 bit code */
unsigned char follower;
} string_tab[TABSIZE];

/* routines common to compress and decompress, contained in CommLZW.c */
unsigned hash();
unsigned unhash();
unsigned getcode();
putcode();
init_tab();
upd_tab();

FILE *op;
main(argc,argv)
int argc; char *argv[];
{
register unsigned int c, code, localcode;
int code_count = TABSIZE - 256;
FILE *infd, *outfd;
if (3 != argc) {
fprintf(stderr,"Usage : lzwcom oldfilename squeezefilename\n");
exit(0);
}
if ( -1 == (infd = fopen( *++argv, "r")) ) {
fprintf(stderr,"Cant open %s\n", *argv);
exit(0);
}
if ( -1 == (outfd = fopen(*++argv,"w")) ) {
fprintf(stderr,"Cant create %s\n",*argv);

exit(0);
}
init_tab(); /* initialize code table */
c = getc(infd);
code = unhash(NO_PRED,c); /* initial code for table */
DEBUGGER (\
if (c >= ' ' || c <= '~' || c == '\n' || c == '\r')\
putchar(c);\
else\
printf("[%2x]",c);\
)
while ( UEOF != (c = getc(infd)) )
{
DEBUGGER (\
if (c >= ' ' || c <= '~' || c == '\n' || c == '\r')\
putchar(c);\
else\
printf("[%2x]",c);\
)
if ( NOT_FND != (localcode = unhash(code,c)) )
{
code = localcode;
continue;
}
/* when the above clause comes false, you have found the last known code */
putcode(outfd,code); /* only update table if table isn't full */
DEBUGGER(printf( "\n%x\n",code)
if ( code_count )
{
upd_tab(code,c);
DEBUGGER(printf("\nadding %x %c = %x\n",code,c,unhash(code,c))
--code_count;
}
/* start loop again with the char that didn't fit into last string */
code = unhash(NO_PRED,c);
}
putcode(outfd,code); /* once EOF reached, always */
/* one code left unsent */
DEBUGGER(fprintf(stderr,"\n%x\n",co de)
flushout(outfd); /* make sure everything's written */
exit(0); /* make sure everything gets closed */
}

он ?
denes вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
На счёт сжатия видео Altera Софт 2 16.10.2010 16:09
Книга по алгоритмам сжатия FeNiX_IU8 Обсуждение статей 3 03.11.2009 22:32
Помогите с алгоритмом сжатия изображения Kulibim Мультимедиа в Delphi 3 20.12.2007 19:33
Алгоритм сжатия+ zlib Воин-Леший Общие вопросы Delphi 1 09.12.2007 15:05