📄 transparentcolorfilter.cpp
字号:
/////////////////////////////////////////////////////////////////////////////////
//
// TransparentColorFilter.cpp: implementation of the CTransparentColorFilter class.
//
////////////////////////////////////////////////////////////////////////////////
// 版权所有(2002)
// Copyright(2002)
// 编写者: 向世明
// Author: Xiang Shiming
#include "stdafx.h"
#include "TransparentColorFilter.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNAMIC(CTransparentColorFilter, CImageComposite)
CTransparentColorFilter::CTransparentColorFilter()
{
m_dwOperation = IMAGE_TRANSPARENT_COLOR_COMPOSE;
m_byRed = m_byGreen = m_byBlue = 0;
}
CTransparentColorFilter::~CTransparentColorFilter()
{
}
#ifdef _DEBUG
void CTransparentColorFilter::Dump(CDumpContext& dc) const
{
CImageComposite::Dump(dc);
}
void CTransparentColorFilter::AssertValid() const
{
CImageComposite::AssertValid();
}
#endif
void CTransparentColorFilter::SetTransparentColor(BYTE byRed, BYTE byGreen, BYTE byBlue)
{
m_byRed = byRed;
m_byGreen = byGreen;
m_byBlue = byBlue;
}
//(nXSrc, nYSrc, nWidth, nHeight) 表示合成输入源的哪部分区域:位置和大小
//nXDst, nYDst 表示从目的地什么位置开始, 大多数情况下, 这两个参数均取0值
//lpbyBitsSrc 表示输入源图像像素字节
//nWidthImgSrc, nHeightImgSrc, 分别表示输入源图像的宽度和高度
//lpbyBitsDst 表示目的地图像的像素字节
//nWidthImgDst, nHeightImgDst 分别表示目的地图像的宽度和高度.
//注意之一:
//nXSrc, nYSrc;nXDst, nYDst都是相对于区域图像而言的.
//区域图像是从其它大的图像中取出的一小块, 它自身也有坐标, 原点在左上角.
//注意之二:
//"源"(Src) 就是当前输入的图像, "目的地"(Dst)典型地可以理解为帧缓存中已经绘制的图像
//在图像点处理和区域处理中, DST表示目标.
//处理结果将放在lpbyBitsDst32中
BOOL CTransparentColorFilter::Filter(int nXSrc, int nYSrc, int nWidth, int nHeight, int nXDst, int nYDst, LPBYTE lpbyBitsSrc32, int nWidthImgSrc, int nHeightImgSrc, LPBYTE lpbyBitsDst32, int nWidthImgDst, int nHeightImgDst)
{
//第一步, 参数合法性检测
ASSERT(lpbyBitsSrc32);
ASSERT(lpbyBitsDst32);
if((nXSrc > (nWidthImgSrc - 1)) || (nYSrc > (nHeightImgSrc - 1))) return FALSE;
if((nXDst > (nWidthImgDst - 1)) || (nYDst > (nHeightImgDst - 1))) return FALSE;
//有效区域的宽度和高度
int w = min(nWidth, (nWidthImgSrc - nXSrc));
int h = min(nHeight, (nHeightImgSrc - nYSrc));
w = min(w, (nWidthImgDst - nXDst));
h = min(h, (nHeightImgDst - nYDst));
//行字节数:扫描
DWORD dwWidthBytesSrc = (DWORD)nWidthImgSrc * 4;
DWORD dwWidthBytesDst = (DWORD)nWidthImgDst * 4;
//开始数据基索引
DWORD dwBaseIndexSrc = nYSrc * dwWidthBytesSrc + 4 * nXSrc;
DWORD dwBaseIndexDst = nYDst * dwWidthBytesDst + 4 * nXDst;
//第二步, 过滤处理
for(int i = 0;i < h;i++)
{
BYTE* pbySrc = lpbyBitsSrc32 + dwBaseIndexSrc;
BYTE* pbyDst = lpbyBitsDst32 + dwBaseIndexDst;
for(int j = 0;j < w;j++)
{
//源
BYTE byBlue = *pbySrc++;
BYTE byGreen = *pbySrc++;
BYTE byRed = *pbySrc++;
pbySrc++;
//目的地
BYTE* pbyBlue = pbyDst++;
BYTE* pbyGreen = pbyDst++;
BYTE* pbyRed = pbyDst++;
pbyDst++;
//如果该颜色不透明, 则应该覆盖目的地已经存在的像素
if((byRed != m_byRed) || (byGreen != m_byGreen) || (byBlue != m_byBlue))
{
*pbyBlue = byBlue;
*pbyGreen = byGreen;
*pbyRed = byRed;
}
}
dwBaseIndexSrc += dwWidthBytesSrc;
dwBaseIndexDst += dwWidthBytesDst;
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -