//
//放大或者缩小RGB24,采用双线性插值算法
//nSrcWidth:原始宽度、nSrcHeight:原始高度
//fRateW:目的宽度/nSrcWidth
//fRateH:目的高度/nSrcHeight
//
void ZoomBitMap(unsigned char *pSrcImg, unsigned char *pDstImg, int nSrcWidth, int nSrcHeight, double fRateW,double fRateH)
{
int i = 0;
int j = 0;
double fX, fY;
int iStepSrcImg = nSrcWidth;
int iStepDstImg = nSrcWidth * fRateW;
int iX, iY;
unsigned char bUpLeft, bUpRight, bDownLeft, bDownRight;
unsigned char gUpLeft, gUpRight, gDownLeft, gDownRight;
unsigned char rUpLeft, rUpRight, rDownLeft, rDownRight;
unsigned char b, g, r;
/* int w=nHeight * fRateH;
int h=nWidth * fRateW;*/
for(i = 0; i < nSrcHeight * fRateH ; i++)
{
for(j = 0; j < nSrcWidth * fRateW ; j++)
{
fX = ((double)j) /fRateW;
fY = ((double)i) /fRateH;
iX = (int)fX;
iY = (int)fY;
bUpLeft = pSrcImg[iY * iStepSrcImg * 3 + iX * 3 + 0];
bUpRight = pSrcImg[iY * iStepSrcImg * 3 + (iX + 1) * 3 + 0];
bDownLeft = pSrcImg[(iY + 1) * iStepSrcImg * 3 + iX * 3 + 0];
bDownRight = pSrcImg[(iY + 1) * iStepSrcImg * 3 + (iX + 1) * 3 + 0];
gUpLeft = pSrcImg[iY * iStepSrcImg * 3 + iX * 3 + 1];
gUpRight = pSrcImg[iY * iStepSrcImg * 3 + (iX + 1) * 3 + 1];
gDownLeft = pSrcImg[(iY + 1) * iStepSrcImg * 3 + iX * 3 + 1];
gDownRight = pSrcImg[(iY + 1) * iStepSrcImg * 3 + (iX + 1) * 3 + 1];
rUpLeft = pSrcImg[iY * iStepSrcImg * 3 + iX * 3 + 2];
rUpRight = pSrcImg[iY * iStepSrcImg * 3 + (iX + 1) * 3 + 2];
rDownLeft = pSrcImg[(iY + 1) * iStepSrcImg * 3 + iX * 3 + 2];
rDownRight = pSrcImg[(iY + 1) * iStepSrcImg * 3 + (iX + 1) * 3 + 2];
b = bUpLeft * (iX + 1 - fX) * (iY + 1 - fY) + bUpRight * (fX - iX) * (iY + 1 - fY)
+ bDownLeft * (iX + 1 - fX) * (fY - iY) + bDownRight * (fX - iX) * (fY - iY);
g = gUpLeft * (iX + 1 - fX) * (iY + 1 - fY) + gUpRight * (fX - iX) * (iY + 1 - fY)
+ gDownLeft * (iX + 1 - fX) * (fY - iY) + gDownRight * (fX - iX) * (fY - iY);
r = rUpLeft * (iX + 1 - fX) * (iY + 1 - fY) + rUpRight * (fX - iX) * (iY + 1 - fY)
+ rDownLeft * (iX + 1 - fX) * (fY - iY) + rDownRight * (fX - iX) * (fY - iY);
if(iY >= 0 && iY <= nSrcHeight * 2 && iX >= 0 && iX <= nSrcWidth * 2)
{
pDstImg[i * iStepDstImg * 3 + j * 3 + 0] = b; //B
pDstImg[i * iStepDstImg * 3 + j * 3 + 1] = g; //G
pDstImg[i * iStepDstImg * 3 + j * 3 + 2] = r; //R
}
}
}
}
采用双线性插值算法 放大或者缩小RGB24
最新推荐文章于 2024-07-03 21:37:22 发布