ZLIB installation
Libpng is a free, open source library, supports creation, reading and writing, etc. for PNG graphics files. Libpng uses the ZLIB library as a compression engine, Zlib is also a compression engine used by the famous Gzip (GNU Zip).
We first install Zlib, download the latest source program from its official website, assuming that the file name is Zlib-1.1.4.tar.gz. Website: http://www.gzip.org/zlib/.
In D: / Establish the libPng directory, release ZLIB-1.1.4.tar.gz to this directory. Although there is no suitable makefile, we can still compile links Zlib.lib:
D: /Libpng/zlib 1.1.4> BCC32 -C -O2 -6 -W-8004 -W-8057 -W-8012 * .c
Borland C 5.5.1 for Win32 CopyRight (C) 1993, 2000 Borland
Adler32.c:
Compress.c:
CRC32.c:
DEFLATE.C:
EXAMPLE.C:
gzio.c:
Infblock.c:
InfcoDes.c:
Inffast.c:
INFLATE.C:
INFTREES.C:
INFUTIL.C:
Maketree.c:
minigzip.c:
TREES.C:
Uncompr.c:
ZUTIL.C:
D: /libpng/zlib 1.1.4> Tlib Zlib.lib Adler32.obj Compress.obj CRC32.Obj
Deflate.obj Gzio.obj Infblock.obj InfcoDes.obj Inffast.obj
Inflate.obj InfTRees.obj Infutil.obj Maketree.Obj Trees.obj
uncompr.obj ZUTIL.OBJ
Tlib 4.5 CopyRight (C) 1987, 1999 Inprise Corporation
Note that in the command line of TLIB, there is no example.obj and minigzip.obj. Next, the test zlib.lib is compiled successfully, executes:
D: /libpng/zlib 1.1.4> BCC32 minigzip.obj Zlib.lib
Borland C 5.5.1 for Win32 CopyRight (C) 1993, 2000 Borland
Turbo Incremental Link 5.00 Copyright (C) 1997, 2000 Borland
D: /libpng/zlib-1.1.4> BCC32 Example.obj Zlib.lib
Borland C 5.5.1 for Win32 CopyRight (C) 1993, 2000 Borland
Turbo Incremental Link 5.00 Copyright (C) 1997, 2000 Borland
D: /libpng/zlib-1.1.4> EXAMPLE
Uncompress (): Hello, Hello!
gzread (): Hello, Hello!
gzgets () after gzseek: Hello!
Inflate (): Hello, Hello!
Large_inflate (): OK
After Inflatesync (): Hello, Hello!
Inflate with dictionary: hello, hello!
Execute Example.exe, see "Hello, Hello!", Indicating that the generated zlib.lib is good.
Zlib is a general-purpose compression library, providing a set of In-Memory compression and decompression functions, and detects the integrity of the extracted data. Zlib also supports files in Gzip (.gz) format. The two most useful functions are introduced below - Compress and Uncompress.
INT COMPRESS (Bytef * Dest, Ulongf * Destlen, Const Bytef * Source, Ulong Sourcelen);
The Compress function compresses the contents of the SOURCE buffer to the DEST buffer. Sourcelen represents the size of the Source buffer (in bytes). Note that the second parameter destlen in the function is an address call. When the call function is called, DESTLEN indicates the size of the DEST buffer, Destlen> (Sourcelen 12) * 100.1%. When the function exits, Destlen indicates the actual size of the compressed buffer. At this point Destlen / Sourcelen is just a compression ratio.
If COMPRESS is successful, return z_ok; if there is no sufficient memory, return z_mem_error; if the output buffer is not large enough, return z_buf_error.
INT UNCOMPRESS (Bytef * Dest, Ulongf * Destlen, Const Bytef * Source, Ulong Sourcelen);
The Uncompress function decompresses the contents of the Source buffer to the DEST buffer. Sourcelen is the size of the Source buffer (in bytes). Note that the second parameter destlen in the function is an address call. When a function is called, Destlen indicates the size of the DEST buffer, and the DEST buffer is sufficient to accomplish the decompressed data. When performing decompression, it is necessary to know how much it is to be decompressed in advance. This requires the size of the original data (that is, the size of the data after the decompression) is required to be compressed. This is not the function of the Zlib library, you need to do extra job. When the function exits, Destlen is the actual size of the data extracted.
If the uncompress is successful, it returns z_ok; if there is not enough memory, returns z_mem_error; if the output buffer is not large enough, return z_buf_ERROR. Returns z_data_error if the input data is incorrect.
EXAMPLE.C with Zlib belt is a good learning example and worth a view. We write a program to verify the compression function of ZLIB. The written test program is saved as Testzlib.cpp, placed in the ZLIB-1.1.4 directory. Source code:
// Testzlib.cpp Simple Test Zlib's compression
#include
#include
#include
#include "zlib.h"
Using namespace std;
int main ()
{
Int Err;
Byte Compr [200], UNCOMPR [200]; // Big Enough
Ulong Comprlen, uncomprlen;
"123456789090";
Ulong len = strlen (Hello) 1;
Comprlen = sizeof (comp) / sizeof (compr [0]); err = compress (COMPR, & COMPRLEN) Hello, LEN);
IF (Err! = Z_OK) {
CERR << "Compess Error:" << Err << '/ n';
Exit (1);
}
COUT << "Orignal Size:" << len
<< ", Compressed Size:" << Comprlen << '/ n';
STRCPY (CHAR *) UNCOMPR, "Garbage");
Err = Uncompress (uncompr, & uncomprlen, commitr, comprlen);
IF (Err! = Z_OK) {
CERR << "uncompess error:" << Err << '/ n';
Exit (1);
}
COUT << "Orignal Size:" << len
<< ", uncompressed size:" << uncomprlen << '/ n';
IF (strcmp ((char *) uncompr, hello) {
CERR << "Bad Uncompress !!! / N";
Exit (1);
} else {
Cout << "uncompress () succeed: / n" << (char *) UNCOMPR;
}
}
Compilation of this program, output should be
D: /libpng/zlib-1.1.4> BCC32 Testzlib.cpp Zlib.lib
D: /libpng/zlib-1.1.4> Testzlib
Orignal Size: 51, Compressed Size: 22
Orignal Size: 51, Uncompressed Size: 51
Uncompress () succeed:
12345678901234567890123456789012345678901234567890
At this point,
Zlib
The installation task is completed. For future use, I will
Zlib.lib
,
Zlib.h
,
Zconf.h
Copy to
D: / MYLIBS /
.