From 2a72461b3a234c1746175b10ef7f4bce54a0270f Mon Sep 17 00:00:00 2001 From: avolkov Date: Sat, 19 Feb 2005 02:05:03 +0000 Subject: [PATCH] random changes and bugfixes git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1547 8092fc87-c524-0410-9efc-e669fe64eaf9 --- tools/dos-ani/lz.c | 94 ++++++++++++++++++++++++++++++++++++++++++ tools/dos-ani/lzhuf.c | 9 +++- tools/dos-ani/lzhuf.h | 4 +- tools/dos-ani/undani.c | 5 +-- 4 files changed, 107 insertions(+), 5 deletions(-) create mode 100755 tools/dos-ani/lz.c diff --git a/tools/dos-ani/lz.c b/tools/dos-ani/lz.c new file mode 100755 index 000000000..22c530747 --- /dev/null +++ b/tools/dos-ani/lz.c @@ -0,0 +1,94 @@ +/************************************************************************* + LZ packer/unpacker + + Code is mostly from lzhuf.c found at + http://www.cs.umu.se/~isak/Snippets + +***********Original Comment*********************************************** + lzhuf.c + written by Haruyasu Yoshizaki 1988/11/20 + some minor changes 1989/04/06 + comments translated by Haruhiko Okumura 1989/04/07 + getbit and getbyte modified 1990/03/23 by Paul Edwards + so that they would work on machines where integers are + not necessarily 16 bits (although ANSI guarantees a + minimum of 16). This program has compiled and run with + no errors under Turbo C 2.0, Power C, and SAS/C 4.5 + (running on an IBM mainframe under MVS/XA 2.2). Could + people please use YYYY/MM/DD date format so that everyone + in the world can know what format the date is in? + external storage of filesize changed 1990/04/18 by Paul Edwards to + Intel's "little endian" rather than a machine-dependant style so + that files produced on one machine with lzhuf can be decoded on + any other. "little endian" style was chosen since lzhuf + originated on PC's, and therefore they should dictate the + standard. + initialization of something predicting spaces changed 1990/04/22 by + Paul Edwards so that when the compressed file is taken somewhere + else, it will decode properly, without changing ascii spaces to + ebcdic spaces. This was done by changing the ' ' (space literal) + to 0x20 (which is the far most likely character to occur, if you + don't know what environment it will be running on. +*************************************************************************/ + +//#include +//#include +#include +#include +#include +//#include +#include +#include +//#include +#include +#if defined(WIN32) && defined(_MSC_VER) +# define inline __inline +#elif defined(__GNUC__) +# define inline __inline__ +#endif +#include "lzhuf.h" + + +int main(int argc, char *argv[]) +{ + char* s; + lzhuf_session_t sess; + FILE* infile; + FILE* outfile; + int ret; + + if (argc != 4) + { + fprintf(stderr, + "'lz e file1 file2' encodes file1 into file2.\n" + "'lz d file2 file1' decodes file2 into file1.\n"); + return EXIT_FAILURE; + } + + if ((s = argv[1], s[1] || strchr("DEde", s[0]) == NULL) + || (s = argv[2], (infile = fopen(s, "rb")) == NULL) + || (s = argv[3], (outfile = fopen(s, "wb")) == NULL)) + { + fprintf(stderr, "??? %s\n", s); + return EXIT_FAILURE; + } + + lzhuf_startSession(&sess, LZHUF_STDIO); + sess.infile = infile; + sess.outfile = outfile; + + if (toupper(*argv[1]) == 'E') + ret = lzhuf_encode(&sess); + else + ret = lzhuf_decode(&sess); + + lzhuf_endSession(&sess); + + if (ret != 0) + return EXIT_FAILURE; + + fclose(infile); + fclose(outfile); + + return EXIT_SUCCESS; +} diff --git a/tools/dos-ani/lzhuf.c b/tools/dos-ani/lzhuf.c index 7f09c2e0d..c6c657268 100755 --- a/tools/dos-ani/lzhuf.c +++ b/tools/dos-ani/lzhuf.c @@ -670,9 +670,16 @@ int lzhuf_decode(lzhuf_session_t* sess) /* recover */ return 0; } -void lzhuf_startSession(lzhuf_session_t* sess) +void lzhuf_startSession(lzhuf_session_t* sess, int bStdIO) { memset(sess, 0, sizeof(*sess)); + if (bStdIO) + { + sess->read = fread; + sess->write = fwrite; + sess->seek = fseek; + sess->tell = ftell; + } } void lzhuf_endSession(lzhuf_session_t* sess) diff --git a/tools/dos-ani/lzhuf.h b/tools/dos-ani/lzhuf.h index e07a4aa1b..2afe6cf81 100755 --- a/tools/dos-ani/lzhuf.h +++ b/tools/dos-ani/lzhuf.h @@ -63,7 +63,9 @@ typedef struct } lzhuf_session_t; -void lzhuf_startSession(lzhuf_session_t *); +#define LZHUF_STDIO 1 + +void lzhuf_startSession(lzhuf_session_t *, int bStdIO); void lzhuf_endSession(lzhuf_session_t *); int lzhuf_encode(lzhuf_session_t *); /* compression */ int lzhuf_decode(lzhuf_session_t *); /* recover */ diff --git a/tools/dos-ani/undani.c b/tools/dos-ani/undani.c index c7644a50e..e27c50c13 100755 --- a/tools/dos-ani/undani.c +++ b/tools/dos-ani/undani.c @@ -569,14 +569,13 @@ void generateAni(const index_header_t *h, const char *prefix, int plut, FILE *ou { frame_info_t* info = h->frames + i; frame_desc_t* desc = info->desc; - int actplut; + int actplut = plut; if ((h->flags & GFX_HAS_IMAGES) && (h->flags & GFX_HAS_MASKS)) { char tempbuf[sizeof("frame -2147483648")]; sprintf(tempbuf, "frame %d", i); transparentPixel = findTransparentColour(tempbuf, info); - actplut = plut; } else if (h->flags & GFX_HAS_MASKS) { @@ -1096,7 +1095,7 @@ int decompressData(uint8_t* src, uint32_t srclen, uint8_t* dst, uint32_t dstlen) decomp_handle_t writeh = {dst, dstlen, 0}; int ret; - lzhuf_startSession(&sess); + lzhuf_startSession(&sess, 0); sess.infile = &readh; sess.outfile = &writeh; sess.read = decRead;