16,548
社区成员




BOOL CXXX::Scale(LPBYTE lpbyBitsSrc32, int x, int y, int nWidth, int nHeight, int nScanWidth, int nScanHeight, LPBYTE lpbyBitsDst32, int nWidthImgDst, int nHeightImgDst)
{
//有效区域的宽度和高度
int w = min(nWidth, nScanWidth - x);
int h = min(nHeight, nScanHeight - y);
//宽度缩放比
float fScalex = (float)w / (float)nWidthImgDst;
float fScaley = (float)h / (float)nHeightImgDst;
//行字节数
DWORD dwWidthBytes = (DWORD)nScanWidth * 2;
//开始数据基索引
DWORD dwBaseIndex = y * dwWidthBytes + 2 * x;
//指向目标数据
BYTE* pbyDst = lpbyBitsDst32;
//完成变换
for(int i = 0; i < nHeightImgDst;i++)
{
//反向变换后获得的浮点y值
float fYInverse = i * fScaley;
//取整
int yy = (int)fYInverse;
//坐标差值
float fv = fYInverse - yy;
//对应于原图像的y坐标
yy += y;
BYTE* pbySrc = lpbyBitsSrc32 + yy * dwWidthBytes;
for(int j = 0;j < nWidthImgDst;j++)
{
//反向变换后获得的浮点x值
float fXInverse = j * fScalex;
//取整
int xx = (int)fXInverse;
//坐标差值
float fu = fXInverse - xx;
//对应于原图像的y坐标
xx += x;
//获取数据
BYTE* pbyCurrent = pbySrc + 2 * xx;
PIXELCOLORRGB rgb = Interpolate(pbyCurrent, xx, yy, fu, fv, nScanWidth, nScanHeight);
*pbyDst++ = rgb.blue;
*pbyDst++ = rgb.green;
*pbyDst++ = rgb.red;
//alpha数据由外部填充.
pbyDst++;
}
}
return TRUE;
}
PIXELCOLORRGB CXXX::Interpolate(LPBYTE lpbySrcXY, int x, int y, float fu, float fv, int nScanWidth, int nScanHeight)
{
PIXELCOLORRGB rgb;
//行字节数, 可以将dwWidthBytes作为参数传递过来
DWORD dwWidthBytes = (DWORD)nScanWidth * 2;
BYTE* pbySrc = lpbySrcXY;
rgb.blue = *pbySrc++;
rgb.green = *pbySrc++;
rgb.red = *pbySrc++;
return rgb;
}