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

📄 conversionview.cpp

📁 图象像素的表示
💻 CPP
📖 第 1 页 / 共 3 页
字号:
			Value=Value>255?255:Value;

			lower=clrR/Value*Value;
			upper=(clrR+Value)/Value*Value;

			if(clrR-lower>upper-clrR)
			{
				clrR=upper;
			}
			else
			{
				clrR=lower;
			}

			lower=clrG/Value*Value;
			upper=(clrG+Value)/Value*Value;

			if(clrG-lower>upper-clrG)
			{
				clrG=upper;
			}
			else
			{
				clrG=lower;
			}

			lower=clrB/Value*Value;
			upper=(clrB+Value)/Value*Value;

			if(clrB-lower>upper-clrB)
			{
				clrB=upper;
			}
			else
			{
				clrB=lower;
			}

			clrContrast=RGB(clrR,clrG,clrB);

			m_pDC->SetPixel (ix,iy,clrContrast);

			dIndex=iy*biWidth+ix;
			pFrameBuff[dIndex].clrRGBA =clrContrast;
		}
	}
}

/////////////////////////////////////////////////
//辉度处理函数:在指定区域内,按给定参数值,依据
//相应的算法实现图像的处理。
//
void CConversionView::Luminosity(RECT rSel,int Value)
{
	int ix,iy;
	DWORD dIndex,sIndex;
	UINT wUpper,hUpper;
	
	int clrR,clrG,clrB;
	COLORREF clrLuminosity,clrTemp;

	m_pDC->SetROP2 (R2_COPYPEN);
	wUpper=biWidth<rSel.right+1  ?biWidth:rSel.right+1  ;
	hUpper=biHeight<rSel.bottom+1  ?biHeight:rSel.bottom +1 ;
	
	//对当前象素的辉度叠加一个偏移量
	//
	for(iy=rSel.top ;iy<hUpper;iy++)
	{
		sIndex=iy*biWidth;
		for(ix=rSel.left ;ix<wUpper;ix++)
		{
			clrTemp=pBuff[sIndex+ix].clrRGBA ;
			clrR=clrTemp&0x000000ff;
			clrTemp=clrTemp>>8;
			clrG=clrTemp&0x000000ff;
			clrTemp=clrTemp>>8;
			clrB=clrTemp&0x000000ff;
			
			clrR+=Value;
			clrG+=Value;
			clrG+=Value;

			clrR=clrR<0?0:clrR;
			clrR=clrR>255?255:clrR;

			clrG=clrG<0?0:clrG;
			clrG=clrG>255?255:clrG;

			clrB=clrB<0?0:clrB;
			clrB=clrB>255?255:clrB;

			
			clrLuminosity=RGB(clrR,clrG,clrB);
			m_pDC->SetPixel (ix,iy,clrLuminosity);
			dIndex=iy*biWidth+ix;
			pFrameBuff[dIndex].clrRGBA =clrLuminosity;
		}
	}
}

/////////////////////////////////////////////////
//找边处理函数:在指定区域内,按给定参数值,依据
//相应的算法实现图像的处理。
//
void CConversionView::Contour(RECT rSel, int Value)
{
	int ix,iy;
	DWORD sIndex;
	UINT wUpper,hUpper;
	
	int xc,yc;
	bool bContour;
	int xL,xR,yU,yD;
	int clrR,clrG,clrB;
	int clrR0,clrG0,clrB0;
	COLORREF clrContour,clrTemp;

	m_pDC->SetROP2 (R2_COPYPEN);
	wUpper=biWidth<rSel.right+1  ?biWidth:rSel.right+1  ;
	hUpper=biHeight<rSel.bottom+1  ?biHeight:rSel.bottom +1 ;
	
	//先根据相邻象素的灰度情况,确定当前象素是否为轮廓象素,
	//若是则保留颜色,否则反显象素颜色。
	//
	for(iy=rSel.top ;iy<hUpper;iy++)
	{
		for(ix=rSel.left ;ix<wUpper;ix++)
		{
			xL=ix-rSel.left;
			xL=xL>1?1:xL;
            
			xR=wUpper-ix;
			xR=xR>1?1:xR;

			yU=iy-rSel.top;
			yU=yU>1?1:yU;
            
			yD=hUpper-iy;
			yD=yD>1?1:yD;
			

			bContour=FALSE;
			sIndex=iy*biWidth+ix;
			clrTemp=pBuff[sIndex].clrRGBA ;
			clrR0=clrTemp&0x000000ff;
			clrTemp=clrTemp>>8;
			clrG0=clrTemp&0x000000ff;
			clrTemp=clrTemp>>8;
			clrB0=clrTemp&0x000000ff;

			for(yc=iy-yU;yc<=iy+yD;yc++)
			{
				sIndex=yc*biWidth;
				for(xc=ix-xL;xc<=ix+xR;xc++)
				{
					clrTemp=pBuff[sIndex+xc].clrRGBA ;
					clrR=clrTemp&0x000000ff;
					clrTemp=clrTemp>>8;
					clrG=clrTemp&0x000000ff;
					clrTemp=clrTemp>>8;
					clrB=clrTemp&0x000000ff;

					if(!(abs(clrR0-clrR)<=Value&&abs(clrG0-clrG)<=Value&&abs(clrB0-clrB)<=Value))
					{
						bContour=TRUE;
						break;
					}
				}
				if(bContour)
					break;
			}

			if(bContour)
				clrContour=RGB(clrR0,clrG0,clrB0);
			else
				clrContour=RGB(255-clrR0,255-clrG0,255-clrB0);
			
			m_pDC->SetPixel (ix,iy,clrContour);
			sIndex=iy*biWidth+ix;
			pFrameBuff[sIndex].clrRGBA =clrContour;
		}
	}
}

////////////////////////////////////////////////////////////////////////
//位图复制函数:将位图从源缓冲区逐象素复制到目标缓冲区。
//
void CConversionView::CopyBitmap(MYBITMAP *Source,MYBITMAP *Destination)
{
	UINT i,j;
	DWORD Index;

	for(j=0;j<biHeight;j++)
		for(i=0;i<biWidth;i++)
		{
			Index=j*biWidth+i;
			Destination[Index].clrRGBA =Source[Index].clrRGBA ;
		}
}

///////////////////////////////////////////////////////
//柔化按钮消息函数:将前次处理结果复制“后台”缓冲区,
//从而不能再对前次操作进行反复,然后对选定区域进行柔化
//效果处理,并设置相应状态。
//
void CConversionView::OnbtnBlur() 
{
	CopyBitmap(pFrameBuff,pBuff);
	
	Blur(selRect,8);
	
	opStatus=sBlur;
	UnRedo=sUndo;
}

///////////////////////////////////////////////////////
//柔化按钮更新消息函数:当打开了有效位图文件之后,系统
//自动使按钮处于有效状态,否则处于无效状态。
//
void CConversionView::OnUpdatebtnBlur(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable (pBuff!=NULL);
	
}

///////////////////////////////////////////////////////
//找变按钮消息函数:将前次处理结果复制“后台”缓冲区,
//从而不能再对前次操作进行反复,然后对选定区域进行找边
//效果处理,并设置相应状态。
//
void CConversionView::OnbtnContour() 
{
	CopyBitmap(pFrameBuff,pBuff);

	Contour(selRect,80);

	opStatus=sContour;
	UnRedo=sUndo;
	
}

///////////////////////////////////////////////////////
//找边按钮更新消息函数:当打开了有效位图文件之后,系统
//自动使按钮处于有效状态,否则处于无效状态。
//
void CConversionView::OnUpdatebtnContour(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable (pBuff!=NULL);	
}

///////////////////////////////////////////////////////
//对比度按钮消息函数:将前次处理结果复制“后台”缓冲区,
//从而不能再对前次操作进行反复,然后对选定区域进行对比度
//效果处理,并设置相应状态。
//
void CConversionView::OnbtnContrast() 
{
	CopyBitmap(pFrameBuff,pBuff);

	Contrast(selRect,50);

	opStatus=sContrast;
	UnRedo=sUndo;
}

///////////////////////////////////////////////////////
//对比度按钮更新消息函数:当打开了有效位图文件之后,系统
//自动使按钮处于有效状态,否则处于无效状态。
//
void CConversionView::OnUpdatebtnContrast(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable (pBuff!=NULL);
}

///////////////////////////////////////////////////////
//单色化按钮消息函数:将前次处理结果复制“后台”缓冲区,
//从而不能再对前次操作进行反复,然后对选定区域进行单色化
//效果处理,并设置相应状态。
//
void CConversionView::OnbtnGray() 
{
	CopyBitmap(pFrameBuff,pBuff);

	Gray(selRect,8);

	opStatus=sGray;
	UnRedo=sUndo;

}

///////////////////////////////////////////////////////
//单色化按钮更新消息函数:当打开了有效位图文件之后,系统
//自动使按钮处于有效状态,否则处于无效状态。
//
void CConversionView::OnUpdatebtnGray(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable (pBuff!=NULL);
	
}

///////////////////////////////////////////////////////
//辉度按钮消息函数:将前次处理结果复制“后台”缓冲区,
//从而不能再对前次操作进行反复,然后对选定区域进行辉度
//效果处理,并设置相应状态。
//
void CConversionView::OnbtnLuminosity() 
{
	CopyBitmap(pFrameBuff,pBuff);

    Luminosity(selRect,20);

	opStatus=sLuminosity;
	UnRedo=sUndo;
}

///////////////////////////////////////////////////////
//辉度按钮更新消息函数:当打开了有效位图文件之后,系统
//自动使按钮处于有效状态,否则处于无效状态。
//
void CConversionView::OnUpdatebtnLuminosity(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable (pBuff!=NULL);
	
}

////////////////////////////////////////
//取消按钮消息函数:将“后台”缓冲区的内容复制到“前台”
//缓冲区,并重新进行显示。
//
void CConversionView::OnbtnUndo() 
{
	CopyBitmap(pBuff,pFrameBuff);
	DrawBitmap(pFrameBuff,0,0,m_pDC);
	UnRedo=sRedo;
}

/////////////////////////////////////////////////////
//取消按钮更新消息函数:系统根据操作改变状态的值自动
//更新按钮状态。
//
void CConversionView::OnUpdatebtnUndo(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable (UnRedo==sUndo);	
}

///////////////////////////////////////////////////////
//纹波按钮消息函数:将前次处理结果复制“后台”缓冲区,
//从而不能再对前次操作进行反复,然后对选定区域进行纹波
//效果处理,并设置相应状态。
//
void CConversionView::OnbtnWave() 
{
	CopyBitmap(pFrameBuff,pBuff);

	Wave(selRect,5);
	
	opStatus=sWave;
	UnRedo=sUndo;
	
}

///////////////////////////////////////////////////////
//纹波按钮更新消息函数:当打开了有效位图文件之后,系统
//自动使按钮处于有效状态,否则处于无效状态。
//
void CConversionView::OnUpdatebtnWave(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable (pBuff!=NULL);
	
}

///////////////////////////////////////////////////////
//二值化按钮消息函数:将前次处理结果复制“后台”缓冲区,
//从而不能再对前次操作进行反复,然后对选定区域进行二值化
//效果处理,并设置相应状态。
//
void CConversionView::OnbtnWhtBlk() 
{
	CopyBitmap(pFrameBuff,pBuff);

	WhtBlk(selRect,128);

	opStatus=sWhtBlk;
	UnRedo=sUndo;
}

///////////////////////////////////////////////////////
//二值化按钮更新消息函数:当打开了有效位图文件之后,系统
//自动使按钮处于有效状态,否则处于无效状态。
//
void CConversionView::OnUpdatebtnWhtBlk(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable (pBuff!=NULL);
	
}

///////////////////////////////////////////////////////
//反复按钮消息函数:根据前次图像处理类型,调用相应处理函
//数进行图像处理,并更新显示。
//
void CConversionView::OnbtnRedo() 
{
	switch(opStatus)
	{
	case sLuminosity:Luminosity(selRect,20);
		break;
	case sContrast:Contrast(selRect,50);
		break;
	case sWhtBlk:WhtBlk(selRect,128);
		break;
	case sGray:Gray(selRect,8);
		break;
	case sMosaic:Mosaic(selRect,8);
		break;
	case sBlur:Blur(selRect,8);
		break;
	case sWave:Wave(selRect,5);
		break;
	case sContour:Contour(selRect,80);
		break;
	default:break;
	}
	UnRedo=sUndo;
}

/////////////////////////////////////////////////////
//反复按钮更新消息函数:系统根据操作改变状态的值自动
//更新按钮状态。
//
void CConversionView::OnUpdatebtnRedo(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable (UnRedo==sRedo);
	
}

⌨️ 快捷键说明

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