載點
https://docs.google.com/uc?id=0B4PwTcFHZPWbZGUwYTJkMmQtNjkxZi00YTMwLWJhMTEtNDE4N2U5ZThhYjNm&export=download&hl=zh_TW
外觀
關鍵程式碼:
void __fastcall TForm1::RGBToYUY2(Graphics::TBitmap *FrBmp,BYTE *dst)
{
unsigned char *p,*src;
int len,w,h,x,y;
w=FrBmp->Width;
h=FrBmp->Height;
for(y=0;y<h;y++)
{
src=(unsigned char*)FrBmp->ScanLine[y];
for(x=0;x<w;x+=2,src+=6,dst+=4)
{
...
...
}
}
}
//---------------------------------------------------------------------------
HRESULT __fastcall TForm1::YUY2ToBMP(BYTE *yuy2,Graphics::TBitmap *dstbmp)
{
int x,y;
unsigned char *ty,*tu,*tv;
ty=(unsigned char*)malloc(dstbmp->Width*dstbmp->Height);
tu=(unsigned char*)malloc(dstbmp->Width*dstbmp->Height);
tv=(unsigned char*)malloc(dstbmp->Width*dstbmp->Height);
BYTE *pt,*py,*pu,*pv;
pt=yuy2;
py=ty;
pu=tu;
pv=tv;
for(int y=0;y<dstbmp->Height;y++)
{
for(int x=0;x<dstbmp->Width;x+=2)
{
....
....
}
}
py=ty;
pu=tu;
pv=tv;
for(y=0;y<dstbmp->Height;y++)
{
char *linep=(char*)dstbmp->ScanLine[y];
for(x=0;x<dstbmp->Width;x++)
{
unsigned int y=(*py++);
int u=(int)(*pu++)-128;
int v=(int)(*pv++)-128;
float R,G,B;
R = (float)y + 1.6*(float)u;
G = (float)y - 0.9*(float)v - 0.5*(float)u;
B = (float)y + 1.5*(float)v;
if(R<0) R=0;
if(R>255) R=255;
if(G<0) G=0;
if(G>255) G=255;
if(B<0) B=0;
if(B>255) B=255;
*linep++=R;
*linep++=G;
*linep++=B;
}
}
free(ty);
free(tu);
free(tv);
return S_OK;
}
//---------------------------------------------------------------------------
RGB與YUY2轉換,不過轉換後圖檔看起來有些微差異...
沒有留言:
張貼留言