Compiling and using zlib and libpng libraries in Windows

Source: Internet
Author: User
Tags uncompress

Libpng
It is a free and open source code library that supports operations such as creating, reading, and writing PNG graphics files.

Zlib
Is a common open source compression library.

Libpng can go to www.libpng.org.
Download the source code. Libpng uses the zlib library as the compression engine, and zlib is also a well-known gzip (GNU zip) compression engine. Zlib is a common compression library that provides a set of In-memory compression and decompression functions, and can detect the integrity of extracted data (integrity ). Zlib also supports reading and writing gzip (.gz) files. These files are free and public.

After pbglib is downloaded and zlib is downloaded, how can it be added to the code?

Take vc6. as an example. The same is true for other cbuild compilers. For example, we downloaded an lpng1210.zipand zlib-1.2.3.tar.tar from the Internet.

First decompress them. Find projects/visualc6/LibPNG. DSW in the lpng directory. And find zlib-1.2.3/projects/visualc6/zlib. DSW in zlib. Use VC to open the libpng project file and add the zlib project file. Set the output paths of zlib. lib and PBG. Lib set in setting, and include paths (this simple method is understandable ). After running, two static databases are generated. After Lib is completed, we can add lib to the project we want to do. Set in link and add PNG. h and zlib. h. In this way, you can officially use libpng!


Zlib Installation and Use

Zlib installation: Download and view the makefile. msc file.

Run CMD in the Command window of vs.net,

Run nmake-F Win32/makefile. MSC in Win32 \.

How to Use zlib

Header file and library name

Contains header files zlib. H, zconf. H, and zdll. Lib (or zlib. Lib)

Zlib compresses the buffer in the program:

// Compress SRC to DeST. srclen is the original length and destlen is the compressed length.

// Result: = z_ OK is successful, z_mem_error does not have enough memory, and the z_buf_error target buffer is not large enough.

// Level: Compression level
Int compress (byte * DEST, ulong * destlen, const byte * SRC, ulong srclen );

Int compress (byte * DEST, ulong * destlen, const byte * SRC, ulong srclen, int level );

// Extract SRC to DeST. srclen indicates the original length and destlen indicates the decompressed length.

// Result: = z_ OK success, z_mem_error does not have enough memory,

// Z_buf_error the target buffer is not large enough, = z_data_error data error
Int uncompress (byte * DEST, ulong * destlen, const byte * SRC, ulong srclen );

 

// Calculate the length of the buffer to be compressed; rough calculation

Ulong compressbound (ulong srclen );

Deflateinit (), deflate (), deflateend () Internal Compression

Decompress inflateinit (), inflate (), and inflateend () internally.

Functions starting with GZ are used to operate *. GZ files and functions similar to stdio,

In fact, only compress and uncompress functions are enough.

 

Examples of compression and decompression

// Uncompressed raw data
Unsigned char pchsrc [] = "XXX ....";
Unsigned long nsclen = sizeof (pchsrc );

// The buffer to store the compressed data
Unsigned char achcomp [1024];
Unsigned long ncomplen = 1024;

// Decompressed data storage buffer
Unsigned char achuncomp [1024];
Unsigned long nuncomplen= 1024;

// Compress the original data into the compression buffer.

Compress (achcomp, & ncomplen, pchsrc, nsclen );

// Decompress the compressed data into the decompression buffer.

Uncompress (achuncomp, & nuncomplen, achcomp, ncomplen );

// Display original data information
Printf ("Raw data (% d): \ n % s \ n", nsclen, pchsrc );

// Display compressed data
Printf ("compressed data (% d): \ n % s \ n", ncomplen, achcomp );

// Display the decompressed data
Printf ("extract data (% d): \ n % s \ n", nuncomplen, achuncomp );

Reprinted: Click to open the link

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.