⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xxcode.cpp

📁 视频监控vc源代码.对于做视频系统的朋友们很有帮助
💻 CPP
字号:
#include "xxcode.h"
#include <memory.h>

CXXCode::CXXCode(void):

  m_cCodeSet("+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
{
}

CXXCode::~CXXCode(void)
{
}
bool CXXCode::EnCode(const  char  cSource[],char cDest[],int &iLength)
{
	if(iLength<0||cSource==0)
		return false;
	else
	{
		char *p=(char *)this->_EnCode((unsigned char *)cSource,iLength);
		memcpy(cDest,p,iLength+1);
		return true;
	}
}
bool CXXCode::DeCode(const  char  cSource[],char cDest[],int &iLength)
{
	if(iLength<6||cDest==0||iLength%4!=0)
		return false;
	else
	{
		char *p=(char *)this->_DeCode((unsigned char *)cSource,iLength);
		memcpy(cDest,p,iLength);
		return true;
	}
}
unsigned char * CXXCode::_EnCode(const unsigned char cSource[],int &iLength)
{
	int *p=(int *)this->m_cSrcBuff;
	*p=iLength;
	int icode=0;
	memcpy(this->m_cSrcBuff+4,cSource,iLength);
	if((iLength+4)%3)				
		icode=(iLength+4)/3+1;		
	else
		icode=(iLength+4)/3;
	int i=0,j=0,k=0;
	while(k<icode)
	{
		this->_3To4(this->m_cSrcBuff+i,this->m_cDestBuff+j);
		i+=3;j+=4;++k;
	}
	iLength=j;
	this->m_cDestBuff[iLength]=0;
	return this->m_cDestBuff;
}
unsigned char *CXXCode::_DeCode(const unsigned char cDest[],int &iLength)
{
	memcpy(this->m_cDestBuff,cDest,iLength);
	int i=0,j=0;
	int icode=iLength;
	while(j<icode)
	{
		this->_4To3(this->m_cDestBuff+j,this->m_cSrcBuff+i);
		i+=3;j+=4;
	}
	iLength=*(int *)this->m_cSrcBuff;
	return this->m_cSrcBuff+4;
}
unsigned char CXXCode::_GetCodeSet(unsigned char ch) 
{
	if(ch==43) ch=0;
	else if(ch==45) ch=1;
	else if(ch>=48&&ch<=57) ch-=46;
	else if(ch>=65&&ch<=90) ch-=53;
	else if(ch>=97&&ch<=122) ch-=59;
	return ch;
}

void CXXCode::_3To4(unsigned char  cSrc[], unsigned char  cDest[])
{
	cDest[0]=cSrc[0]>>2;
	cDest[1]=(cSrc[0]<<4)&48|(cSrc[1]>>4)&15;
	cDest[2]=(cSrc[1]<<2)&60|(cSrc[2]>>6)&3;
	cDest[3]=cSrc[2]&63;
	for(int i=0;i<4;i++) 
		cDest[i]=this->m_cCodeSet[cDest[i]];
}
void CXXCode::_4To3(unsigned char  cSrc[], unsigned char  cDest[])
{
	int k=2 ,i;
	unsigned char t;
	t=0;
	*cSrc=this->_GetCodeSet(*cSrc);
	for(i=0;i<3;i++)
	{
		*(cSrc+i+1)=this->_GetCodeSet(*(cSrc+i+1));
		*(cDest+i)=*(cSrc+i)<<k;
		k+=2;
		t=*(cSrc+i+1)>>(8-k);
		*(cDest+i)|=t;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -