系统位32位win7系统,c实现旋转代码;
for(int i=0;i < bmpHeight;i++)
{
DWORD* pData=((DWORD*)pBmpBuf + (bmpHeight-1-i)*bmpWidth);
for(int j=0;j<bmpWidth;j++)
{
*( (DWORD*)rotateBuf + j*bmpHeight + i) = *pData++;
}
}
耗时为120毫秒,老师要求是在100毫秒内完成
4 个解决方案
#1
DWORD* pSrcLine = pBmpBuf;
int nSrcOffsetNextPt = 1;
int nSrcOffsetNextLine = bmpWidth;
//根据旋转方向计算以下变量
DWORD* pDstLine = rotateBuf + bmpHeight;
int nDstoffsetNextPt = bmpHeight;
int nDstOffsetNextLine = -1;
for (int line = 0; line < bmpHeight; line++)
{
DWORD* pSrc = pSrcLine;
DWORD* pDst = pDstLine;
for (int pt = 0; pt < bmpWidth; pt++)
{
*pDst = *pSrc;
pDst += nDstOffsetNextPt;
pSrc += nSrcOffsetNextPt;//pSrc++
}
pSrcLine += nSrcOffsetNextLine;
pDstLine += nDstOffsetNextLine;
}
最多用一次乘法
int nSrcOffsetNextPt = 1;
int nSrcOffsetNextLine = bmpWidth;
//根据旋转方向计算以下变量
DWORD* pDstLine = rotateBuf + bmpHeight;
int nDstoffsetNextPt = bmpHeight;
int nDstOffsetNextLine = -1;
for (int line = 0; line < bmpHeight; line++)
{
DWORD* pSrc = pSrcLine;
DWORD* pDst = pDstLine;
for (int pt = 0; pt < bmpWidth; pt++)
{
*pDst = *pSrc;
pDst += nDstOffsetNextPt;
pSrc += nSrcOffsetNextPt;//pSrc++
}
pSrcLine += nSrcOffsetNextLine;
pDstLine += nDstOffsetNextLine;
}
最多用一次乘法
#2
感谢大侠的回复,这样写好像不对。
#3
示意啦!你当然要自己来实现
#4
老师!汗,.....用 IntelIPP,
#1
DWORD* pSrcLine = pBmpBuf;
int nSrcOffsetNextPt = 1;
int nSrcOffsetNextLine = bmpWidth;
//根据旋转方向计算以下变量
DWORD* pDstLine = rotateBuf + bmpHeight;
int nDstoffsetNextPt = bmpHeight;
int nDstOffsetNextLine = -1;
for (int line = 0; line < bmpHeight; line++)
{
DWORD* pSrc = pSrcLine;
DWORD* pDst = pDstLine;
for (int pt = 0; pt < bmpWidth; pt++)
{
*pDst = *pSrc;
pDst += nDstOffsetNextPt;
pSrc += nSrcOffsetNextPt;//pSrc++
}
pSrcLine += nSrcOffsetNextLine;
pDstLine += nDstOffsetNextLine;
}
最多用一次乘法
int nSrcOffsetNextPt = 1;
int nSrcOffsetNextLine = bmpWidth;
//根据旋转方向计算以下变量
DWORD* pDstLine = rotateBuf + bmpHeight;
int nDstoffsetNextPt = bmpHeight;
int nDstOffsetNextLine = -1;
for (int line = 0; line < bmpHeight; line++)
{
DWORD* pSrc = pSrcLine;
DWORD* pDst = pDstLine;
for (int pt = 0; pt < bmpWidth; pt++)
{
*pDst = *pSrc;
pDst += nDstOffsetNextPt;
pSrc += nSrcOffsetNextPt;//pSrc++
}
pSrcLine += nSrcOffsetNextLine;
pDstLine += nDstOffsetNextLine;
}
最多用一次乘法
#2
感谢大侠的回复,这样写好像不对。
#3
示意啦!你当然要自己来实现
#4
老师!汗,.....用 IntelIPP,