Click here to Skip to main content
15,886,067 members
Articles / Desktop Programming / MFC

LZW Compression

Rate me:
Please Sign up or sign in to vote.
3.51/5 (22 votes)
23 Apr 20046 min read 227.3K   11.9K   38  
This will show the simple and useful way to implement a compression algorithm in MFC
// LZWCompression.h: interface for the CLZWCompression class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_LZWCOMPRESSION_H__6C8D7CDC_4AF5_426D_A4AF_49682963D8C3__INCLUDED_)
#define AFX_LZWCOMPRESSION_H__6C8D7CDC_4AF5_426D_A4AF_49682963D8C3__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "Dictionary.h"

class CLZWCompression  
{
public:
	//	These two functions were added to use the log file with the application
	BOOL DecompressWithLog(CFile &source, CFile &destination, CStringArray *pLog);
	BOOL CompressWithLog(CFile &source, CFile &destination, CStringArray *pLog = NULL);
	void Log(CString data);
private:
	CStringArray * p_Log;

public:
	void ClearDictionary();
	BOOL Decompress(CFile &source, CFile &destination);
	BOOL Compress(CFile &source, CFile &destination);
	void CreateDictionary();
	CLZWCompression();
	virtual ~CLZWCompression();
private:
	CString convertASCIIToText(BYTE ascii);
	void Init();
	void CalculateBitSize(DWORD value);
	void CloseCompressedFile(CFile &source);
	DWORD DecompressData(CFile &source);
	BYTE m_MaxBits;
	DWORD m_MaxCode[32];
	int m_TotalBits;
	void CompressData(CFile &dest, long toSave);
	DWORD m_SavedData;
	CDictionary *m_dictionary;
};

#endif // !defined(AFX_LZWCOMPRESSION_H__6C8D7CDC_4AF5_426D_A4AF_49682963D8C3__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions