亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? lzwcompression.cpp

?? mfc下的LZW算法
?? CPP
字號:
// LZWCompression.cpp: implementation of the CLZWCompression class.
//
//////////////////////////////////////////////////////////////////////

/*
	Created by: Luria Israel

  This project implements the use of a dynamic LZW compression.
  This code is free for use, and can be inserted into any MFC project.
*/

#include "stdafx.h"
#include "LZWCompression.h"
#include "Mainfrm.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CLZWCompression::CLZWCompression()
{
	Init();
	p_Log = NULL;

	//	The Maximum code for a bit
	m_MaxCode[0]		= 0;
	m_MaxCode[1]		= 0x1;
	m_MaxCode[2]		= 0x3;
	m_MaxCode[3]		= 0x7;
	m_MaxCode[4]		= 0xF;
	m_MaxCode[5]		= 0x1F;
	m_MaxCode[6]		= 0x3F;
	m_MaxCode[7]		= 0x7F;
	m_MaxCode[8]		= 0xFF;
	m_MaxCode[9]		= 0x1FF;
	m_MaxCode[10]		= 0x3FF;
	m_MaxCode[11]		= 0x7FF;
	m_MaxCode[12]		= 0xFFF;
	m_MaxCode[13]		= 0x1FFF;
	m_MaxCode[14]		= 0x3FFF;
	m_MaxCode[15]		= 0x7FFF;
	m_MaxCode[16]		= 0xFFFF;
	m_MaxCode[17]		= 0x1FFF;
	m_MaxCode[18]		= 0x3FFFF;
	m_MaxCode[19]		= 0x7FFFF;
	m_MaxCode[20]		= 0xFFFFF;
	m_MaxCode[21]		= 0x1FFFFF;
	m_MaxCode[22]		= 0x3FFFFF;
	m_MaxCode[23]		= 0x7FFFFF;
	m_MaxCode[24]		= 0xFFFFFF;
	m_MaxCode[25]		= 0x1FFFFFF;
	m_MaxCode[26]		= 0x3FFFFFF;
	m_MaxCode[27]		= 0x7FFFFFF;
	m_MaxCode[28]		= 0xFFFFFFF;
	m_MaxCode[29]		= 0x1FFFFFFF;
	m_MaxCode[30]		= 0x3FFFFFFF;
	m_MaxCode[31]		= 0x7FFFFFFF;

}

void CLZWCompression::Init()
{
	m_dictionary = NULL;
	m_SavedData = 0;
	m_TotalBits = 0;
	m_MaxBits = 9;
}

CLZWCompression::~CLZWCompression()
{
	ClearDictionary();
}

//	This function was added to send log information to the view
void CLZWCompression::Log(CString data)
{
	//	Put something inside the log if exist
	if (p_Log != NULL)
		p_Log->Add(data);
}

//	Create a new dictionary
void CLZWCompression::CreateDictionary()
{
	Log("Creating dictionary!");
	m_dictionary = new CDictionary;
}

//	Remove the existing dictionary
void CLZWCompression::ClearDictionary()
{
	if (m_dictionary != NULL)
	{
		Log("Clear dictionary!");

		delete[] m_dictionary;
		m_dictionary = NULL;
	}
}

BOOL CLZWCompression::Compress(CFile &source, CFile &destination)
{
	long prefix = 0;
	long result = 0;
	BYTE readByte = 0;
	unsigned long filetotal = 0;
	CString logString;
	DWORD resAdd = 256;

	//	Initialize the neccessry data
	Init();

	//	Get the total file size
	filetotal = source.GetLength();

	//	Create the dictionary (if not created already)
	if (m_dictionary == NULL)
	{
		CreateDictionary();
	}

	//	Read the first byte from the file
	source.Read(&prefix, 1);

	//	Go over the rest of the file and read it
	while (source.GetPosition() < filetotal)
	{
		//	Read the second byte
		source.Read(&readByte, 1);

		//	Check if the prefix and readByte combination exist in the dictionary
		result = m_dictionary->GetEntry(prefix, readByte);

		//	If not exist
		if (result == -1)
		{
			//	Add the new combination
			resAdd = m_dictionary->AddEntry(prefix, readByte);
			//	Calculate the new bit size needed to encode the file
			CalculateBitSize(resAdd);

			//	To show a log in the view
			logString.Format("Adding combination of %d and %d to dictionary to entry %d.",
				prefix, readByte, resAdd);
			Log(logString);

			//	Send the prefix for compression in to the destination file
			CompressData(destination, prefix);

			//	Set the prefix as the readByte
			prefix = readByte;

			//	Initiate the result
			result = -1;
		}
		else
		{
			//	Set the prefix as the result
			prefix = result;
			readByte = 0;
		}
	}

	//	Compress the remaining information in the refix into the destination file
	CompressData(destination, prefix);
	//	Close the destination file
	CloseCompressedFile(destination);

	//	Remove the existing dictionary
	ClearDictionary();
	return TRUE;
}

void CLZWCompression::CompressData(CFile &dest, long toSave)
{
	DWORD writeData = 0;

	//	Move the data you want to write few bits to the left
	//	and combine it with the already existing data in the buffer
	m_SavedData |= (DWORD) toSave << (32 - m_MaxBits - m_TotalBits);

	//	Add the new added number of bits to the total bits counter
	m_TotalBits += m_MaxBits;

	//	Check if it's possible to enter the data to the file
	//	(over and equal a byte of data)
	while (m_TotalBits >= 8)
	{
		//	Get the byte we want to write
		writeData = m_SavedData;
		writeData >>= 24;
		dest.Write(&writeData, 1);

		//	remove the byte from the buffer
		m_SavedData <<= 8;
		//	Remove the byte from the counter
		m_TotalBits -= 8;
	}
}

BOOL CLZWCompression::Decompress(CFile &source, CFile &destination)
{
	DWORD prefix = 0, data = 0;
	CString logString;
	CByteArray decodeString;
	BYTE writeData = 0, character = 0;
	int counter = 0;

	Init();

	//	Create the dicionary (if not already created)
	if (m_dictionary == NULL)
	{
		CreateDictionary();
	}

	//	Get the first prefix information
	prefix = DecompressData(source);
	//	Save the prefix as the last used character (since we're writing it in the
	//	destination file)
	character = (BYTE)prefix;
	//	Write the prefix in the destination file (the first byte inside
	//	a LZW copressed file is always the first byte of the original file)
	destination.Write(&prefix, 1);

	//	While the recieve data is not the maximum bit data possible
	while ((data = DecompressData(source)) != m_MaxCode[m_MaxBits])
	{
		//	Check if the code exist in the dictionary
		//	if not
		if (!m_dictionary->IsCodeExist(data))
		{
			//	Get the last used character into the decod buffer
			decodeString.Add((BYTE)character);
			//	Decode the existing prefix into a known string of data
			m_dictionary->GetBytesFromCode(&decodeString, prefix);
		}
		else
		{
			//	Decode the data into the decode buffer
			m_dictionary->GetBytesFromCode(&decodeString, data);
			//	Get the last letter inside the data, as the last used letter
			character = decodeString.GetAt(decodeString.GetSize() - 1);
		}

		//	Go over the decode buffer, from the end to the start,
		//	and write the information into the destination file
		counter = decodeString.GetSize();
		while (counter > 0)
		{
			writeData = (BYTE)decodeString.GetAt(--counter);
			destination.Write(&writeData, 1);

			//	To show a log in the view

			//	This commented addition was added as suggested by WREY from www.codeproject.com
			logString.Format("Adding character code %d with know visualisation of: %s"
				, writeData, convertASCIIToText(writeData));
//			logString.Format("Adding byte %d to file.", writeData);
			Log(logString);
		}

		//	Clear the decode buffer
		decodeString.RemoveAll();

		//	Add the new combination into the dictionary
		m_dictionary->AddEntry(prefix, (BYTE)character);
		//	Calculate the new buffer size to read now
		CalculateBitSize(m_dictionary->GetMaxCode()+1);

		//	Set the new prefix to use
		prefix = data;
	}
	return TRUE;
}

DWORD CLZWCompression::DecompressData(CFile &source)
{
	DWORD returnValue;
	BYTE readByte = 0;

	//	If the source file still contains information
	if (source.GetPosition() < source.GetLength())
	{
		//	check if the number of bits in the read buffer is >= 24
		while (m_TotalBits <= 24)
		{
			//	Read one byte
			source.Read(&readByte, 1);

			//	Add the byte to the read buffer
			m_SavedData |= (DWORD) readByte << (24 - m_TotalBits);
			//	Add byte to the bit counter
			m_TotalBits += 8;
		}
	}
	else
	{
		//	If there is no more data, and there are no more bits to read
		//	while the file is over, then return the maximum bit number
		//	to end the decompression process
		if (m_SavedData == 0 && m_TotalBits == 0)
			return m_MaxCode[m_MaxBits];
	}

	//	calculate the return information
	returnValue = m_SavedData >> (32 - m_MaxBits);
	//	Remove the returned information from the buffer
	m_SavedData <<= m_MaxBits;
	//	Remove the return information bit size from the bit counter
	m_TotalBits -= m_MaxBits;

	//	Return the data
	return returnValue;
}

void CLZWCompression::CloseCompressedFile(CFile &source)
{
	//	Insert to the file the maximum number of bit (for signaling the end of the
	//	compression\decompression)
	CompressData(source, m_MaxCode[m_MaxBits]);
	//	Flash the rest of the file with 0
	CompressData(source, 0);
}

void CLZWCompression::CalculateBitSize(DWORD value)
{
	//	Check the value of the parameter against the Maximum number possible
	//	and then returns the counter

	//	This can also be acheived by right shifting the value until we get 0
	//	and counting the number of times we doing it.

	BYTE counter;

	for (counter = 0; counter < 32; counter++)
	{
		if (value <= m_MaxCode[counter])
			break;
	}
	m_MaxBits = counter;

	//	Since the minimal number of bits we are using is 9 (256 is the begining of the dictionary), 
	//	then the minimal number of bits is check to return a 9 in case a lower value will be
	//	reached in the application
	if (m_MaxBits < 9)
		m_MaxBits = 9;
}

//	Added for using the log from the application
BOOL CLZWCompression::CompressWithLog(CFile &source, CFile &destination, CStringArray *pLog)
{
	p_Log = pLog;
	return Compress(source, destination);
}

BOOL CLZWCompression::DecompressWithLog(CFile &source, CFile &destination, CStringArray *pLog)
{
	p_Log = pLog;
	return Decompress(source, destination);
}

CString CLZWCompression::convertASCIIToText(BYTE ascii)
{
	//	Those are the values I know of.
	//	If you know others then just add then to this function.
	CString rValue;

	switch (ascii)
	{
	case 8:		//	Backspace
		rValue = "Backspace";
		break;
	case 9:		//	TAB
		rValue = "TAB";
		break;
	case 10:	//	Line Feed
		rValue = "Line Feed";
		break;
	case 12:	//	Form Feed
		rValue = "Form Feed";
		break;
	case 13:	//	Enter
		rValue = "Enter";
		break;
	case 32:	//	Space
		rValue = "Space";
		break;
	case 127:	//	Delete
		rValue = "Delete";
		break;
	default:
		rValue = "There is no visual character associated with this code";
		break;
	}

	if ((ascii >= 33) && (ascii <= 126))
		rValue.Format("%c", ascii);

	return rValue;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美少妇性性性| 91福利区一区二区三区| 丝袜亚洲另类欧美综合| 亚洲国产日日夜夜| 亚洲欧美另类久久久精品2019| 中文字幕在线不卡一区二区三区| 国产精品久久久久久久久免费桃花 | 国产日本欧洲亚洲| 中文字幕精品在线不卡| 中文欧美字幕免费| 亚洲欧美色综合| 亚州成人在线电影| 麻豆91小视频| 国产91精品一区二区麻豆亚洲| 成人永久aaa| 在线免费观看日本一区| 在线不卡一区二区| 久久精品一区二区三区不卡| 国产精品入口麻豆九色| 一区二区三区在线观看网站| 青青青伊人色综合久久| 国产91精品一区二区麻豆网站 | 性做久久久久久免费观看| 奇米影视在线99精品| 国产在线精品免费av| www.亚洲人| 欧美精品在线观看播放| 国产丝袜在线精品| 亚洲一区二区偷拍精品| 久久国产成人午夜av影院| 成人午夜av影视| 欧美人与z0zoxxxx视频| 久久九九久精品国产免费直播| 自拍av一区二区三区| 日本视频一区二区三区| www.综合网.com| 欧美高清www午色夜在线视频| 久久久久国产成人精品亚洲午夜| 亚洲免费在线看| 久久99久久99小草精品免视看| eeuss鲁一区二区三区| 4438成人网| 亚洲欧洲三级电影| 黄色成人免费在线| 色视频成人在线观看免| 久久精品日产第一区二区三区高清版 | 丝袜美腿高跟呻吟高潮一区| 国产不卡免费视频| 911国产精品| 亚洲柠檬福利资源导航| 国产成人免费av在线| 欧美一区二区三区在线观看视频| 国产精品理论在线观看| 国产一区二区视频在线播放| 欧美精品99久久久**| 亚洲欧美日韩国产综合在线| 国产精选一区二区三区| 日韩精品一区二| 日本不卡视频在线观看| 欧亚洲嫩模精品一区三区| 国产婷婷一区二区| 韩日精品视频一区| 欧美一激情一区二区三区| 亚洲国产一区二区三区| 色av一区二区| 亚洲狠狠丁香婷婷综合久久久| 成人a区在线观看| 日本一区二区三区国色天香| 国产精品一区二区黑丝| 精品国产亚洲在线| 六月婷婷色综合| 日韩欧美一区二区视频| 美国十次综合导航| 日韩一级欧美一级| 久久99国产精品成人| 亚洲色图一区二区| 93久久精品日日躁夜夜躁欧美| 中文字幕欧美激情| aaa欧美色吧激情视频| 亚洲精品中文在线| 在线视频欧美精品| 日韩国产在线一| 日韩一区二区三区电影| 精品一区二区在线免费观看| 精品乱人伦一区二区三区| 加勒比av一区二区| 中文av字幕一区| 色婷婷激情综合| 日韩精品欧美精品| www日韩大片| 成人毛片老司机大片| 亚洲欧美日韩在线| 7777精品伊人久久久大香线蕉 | 精品国产91九色蝌蚪| 国产成人免费视频一区| 自拍av一区二区三区| 欧美视频日韩视频| 久久97超碰国产精品超碰| 国产精品黄色在线观看| 欧美日精品一区视频| 国产综合色视频| 亚洲视频香蕉人妖| 欧美一区二区三区思思人| 国产精品中文字幕一区二区三区| 欧美国产一区视频在线观看| 日本高清不卡一区| 精品一二三四区| 亚洲精选一二三| 欧美va天堂va视频va在线| 成人性生交大片免费看中文网站| 一区二区在线观看视频| 2021国产精品久久精品| 在线视频中文字幕一区二区| 紧缚捆绑精品一区二区| 亚洲主播在线播放| 久久久久久久久久久99999| 91国偷自产一区二区使用方法| 美腿丝袜亚洲一区| 亚洲黄色在线视频| 国产无一区二区| 欧美一级午夜免费电影| 色综合久久88色综合天天6 | 91看片淫黄大片一级| 蜜桃视频在线观看一区| 中文字幕中文字幕一区| 亚洲精品在线观| 欧美日韩国产免费一区二区| 成人免费福利片| 狠狠色丁香婷综合久久| 亚洲第一搞黄网站| 亚洲欧洲国产专区| 久久久久久久久久久久久女国产乱| 在线视频国产一区| 成人免费高清在线| 国产精品18久久久久| 日韩成人免费电影| 午夜电影网一区| 一区二区久久久| 国产精品成人免费| 国产精品素人一区二区| 国产三级精品视频| 久久久久久亚洲综合| 精品91自产拍在线观看一区| 欧美一区2区视频在线观看| 欧美日韩美女一区二区| 在线观看91精品国产入口| 97精品电影院| 91麻豆产精品久久久久久| 99久久精品免费精品国产| 成人av电影免费在线播放| 国产成人精品一区二区三区网站观看| 久久99精品视频| 国精品**一区二区三区在线蜜桃| 日日摸夜夜添夜夜添亚洲女人| 亚洲午夜影视影院在线观看| 亚洲一线二线三线久久久| 一区二区三区四区中文字幕| 亚洲精品国产无天堂网2021| 一区二区三区四区不卡在线| 亚洲午夜久久久久中文字幕久| 亚洲精品亚洲人成人网 | 久久夜色精品一区| 久久久精品国产免费观看同学| 国产亚洲欧美激情| 国产精品久久久久久久久晋中| 中文字幕欧美区| 亚洲欧洲日韩av| 午夜欧美大尺度福利影院在线看 | 极品少妇xxxx精品少妇偷拍| 国产精品一二三在| av电影一区二区| 精品1区2区3区| 精品久久国产97色综合| 国产亚洲精品福利| 亚洲精品中文字幕在线观看| 日韩国产一二三区| 国产高清无密码一区二区三区| 91在线观看高清| 欧美日本免费一区二区三区| 久久青草国产手机看片福利盒子| 国产欧美日韩综合| 亚洲一区二区三区在线播放| 精品一区二区影视| 成人亚洲一区二区一| 欧美日韩中文精品| 久久久精品综合| 亚洲欧美另类图片小说| 麻豆国产欧美一区二区三区| 99久久国产综合精品女不卡| 日韩一区和二区| 国产精品拍天天在线| 日韩成人一级片| 一本久道久久综合中文字幕| 日韩欧美国产一区二区三区 | 欧美日韩国产高清一区二区三区 | 成人一区在线看| 91精品视频网| 亚洲色图.com| 国产麻豆精品在线| 在线电影院国产精品|