图像缩放的问题

starsoul2000 2007-09-11 10:18:52
我通过rtsp远程获取摄像头的数据然后用下边的函数进行图像的准备,
TBool CMp4Dec::PrepareBmp(TUint8 * rgb_buf, TUint32& pitch, TUint32& width, TUint32& height)
{

TInt i, j ;
TInt k = 0 ;
TInt jump_step = (pitch - width) * 3 ;
iHeapLocker->Begin(iLockPt) ;
TUint8 * pdata = (TUint8 *) iMemBmp->DataAddress() ;
// use rrrrrr00gggggg00bbbbbb00
for(i = 0 ; i < height ; i++)
{
for(j = 0 ; j < width ; j++)
{
*pdata = rgb_buf[k+2] & 0xFC;
pdata ++;
*pdata = rgb_buf[k+1]& 0xFC ;
pdata ++;
*pdata = rgb_buf[k]& 0xFC ;
pdata ++;
k += 3 ;
}
k += jump_step ;
}
iHeapLocker->End() ;
return ETrue ;
}
最后在屏幕上画出图像iEngine->DrawPic2(iNewMemBmp);,一切正常。因为我想缩放图像,所以写了下边的函数,
inline TUint8 GetR( const TUint16 aColor)
{
return aColor;
}

inline TUint8 GetG(const TUint16 aColor)
{
return aColor;
}

inline TUint8 GetB(const TUint16 aColor)
{
return aColor ;
}

CFbsBitmap* CMp4Dec::BmpZoomL( CFbsBitmap* aBitmap, TInt aWinth, TInt aHeight)
{
if( aWinth>0 && aHeight>0 )
{
const TInt widtha = aBitmap->SizeInPixels().iWidth;
const TInt heighta = aBitmap->SizeInPixels().iHeight;
TReal WPencent=(TReal)aWinth/widtha;
TReal HPencent=(TReal)aHeight/heighta;
return BmpZoomL( aBitmap, WPencent, HPencent);
}
else
{
return NULL;
}

}
CFbsBitmap* CMp4Dec::BmpZoomL( CFbsBitmap* aBitmap, TReal aPencent ){
if(aPencent>0)
{
return BmpZoomL( aBitmap, aPencent, aPencent );

}
else
{
return NULL;
}
}
CFbsBitmap* CMp4Dec::BmpZoomL( CFbsBitmap* aBitmap, TReal aWPencent, TReal aHPencent)
{
if( aWPencent>0 && aHPencent>0 )
{

const TInt widtha = aBitmap->SizeInPixels().iWidth;
const TInt heighta = aBitmap->SizeInPixels().iHeight;
const TInt width = widtha * aWPencent +0.5;
const TInt height = heighta * aHPencent +0.5;
CFbsBitmap* newbitmap = new(ELeave) CFbsBitmap();
User::LeaveIfError(newbitmap->Create(TSize(width,height), EColor4K/*displayMode*/));

TBitmapUtil bmpUtil1(aBitmap);
TBitmapUtil bmpUtil2(newbitmap);
bmpUtil1.Begin(TPoint(0,0));
bmpUtil2.Begin(TPoint(0,0), bmpUtil1);

TUint16* const addr1 = (TUint16*)aBitmap->DataAddress();
TUint16* const addr2 = (TUint16*)newbitmap->DataAddress();

TUint16* p1 = addr1;
TUint16* p2 = addr2;
const TInt line1 = CFbsBitmap::ScanLineLength(widtha, EColor4K) / 2;
const TInt line2 = CFbsBitmap::ScanLineLength(width, EColor4K) / 2;

TReal xa=0,ya=0;
TInt x=0,y=0;
const TInt jump = line2 - width;

TUint16* p2end = addr2 + width;

p2end = addr2 + line2*height;
while( p2 < p2end)
{
TUint16* p2endline = p2 + width;
while( p2!=p2endline )
{

xa=x/aWPencent;
ya=y/aHPencent;
TInt xai = xa;
TInt yai = ya;

if( xai == widtha -1 )
{
if( yai == heighta-1 )
{
*p2 = *(addr1+line1*yai+xai);
}
else
{

p1=addr1+line1*yai+widtha-1;

TUint8 red=GetR(*p1)+(GetR(*(p1+line1))-GetR(*p1))*(ya-yai)+0.5;
TUint8 green=GetG(*p1)+(GetG(*(p1+line1))-GetG(*p1))*(ya-yai)+0.5;
TUint8 blue=GetB(*p1)+(GetB(*(p1+line1))-GetB(*p1))*(ya-yai)+0.5;
*p2 = (red) | (green) | (blue);
}

}
else
{
if( yai == heighta-1 )
{
p1=addr1+line1*(heighta-1)+xai;

TUint8 red=GetR(*(p1))+(GetR(*(p1+1))-GetR(*(p1)))*(xa-xai)+0.5;
TUint8 green=GetG(*(p1))+(GetG(*(p1+1))-GetG(*(p1)))*(xa-xai)+0.5;
TUint8 blue=GetB(*(p1))+(GetB(*(p1+1))-GetB(*(p1)))*(xa-xai)+0.5;
*p2 = (red ) | (green) | (blue);
}
else
{

p1=addr1+line1*yai+xai;

TUint8 red1=GetR(*(p1))+(GetR(*(p1+1))-GetR(*(p1)))*(xa-xai)+0.5;
TUint8 green1=GetG(*(p1))+(GetG(*(p1+1))-GetG(*(p1)))*(xa-xai)+0.5;
TUint8 blue1=GetB(*(p1))+(GetB(*(p1+1))-GetB(*(p1)))*(xa-xai)+0.5;

p1=addr1+line1*(yai+1)+xai;

TUint8 red2=GetR(*(p1))+(GetR(*(p1+1))-GetR(*(p1)))*(xa-xai)+0.5;
TUint8 green2=GetG(*(p1))+(GetG(*(p1+1))-GetG(*(p1)))*(xa-xai)+0.5;
TUint8 blue2=GetB(*(p1))+(GetB(*(p1+1))-GetB(*(p1)))*(xa-xai)+0.5;

TUint8 red=red1+(red2-red1)*(ya-yai)+0.5;
TUint8 green=green1+(green2-green1)*(ya-yai)+0.5;
TUint8 blue=blue1+(blue2-blue1)*(ya-yai)+0.5;

*p2 = (red) | (green) | (blue);
}

}
x++;
p2++;

}
x=0;
y++;
p2+=jump;

}

bmpUtil2.End();
bmpUtil1.End();

return newbitmap;
}
else
{
return NULL;
}
}
在显示图像前缩放iNewMemBmp = BmpZoomL(iMemBmp, 208,178);
然后画出 iEngine->DrawPic2(iNewMemBmp);但是屏幕是绿色的一片;因为对图像的解码不懂,不知道那做错了,应该怎么改。
...全文
82 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

3,119

社区成员

发帖
与我相关
我的任务
社区描述
塞班系统(Symbian系统)是塞班公司为手机而设计的操作系统,它的前身是英国宝意昂公司的 EP ( Electronic Piece of cheese)操作系统。
社区管理员
  • Symbian社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧