YUV 与RGB问题

ljc_9449 2008-04-23 08:55:58
IYUV转RGB
r = 1.0*Y + 0 + 1.402*(V-128);
g = 1.0*Y - 0.34413*(U-128)-0.71414*(V-128);
b = 1.0*Y + 1.772*(U-128)+0; 这个公式, 比较亮的地方颜色会乱,为何???高手帮忙
...全文
70 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ljc_9449 2008-04-24
  • 打赏
  • 举报
回复
解决了,定义成int型, 就是没想到,哎, 多谢了
oo 2008-04-24
  • 打赏
  • 举报
回复
你的r,g,b都是定义的unsigned char,所以在你注释的那三行里编译器已经做了溢出处理了,
你后面的溢出保护已经没意义了,也许要在你注释的三行代码里用一个 short来保存结果。
(对YUV格式不了解,只是从代码来看)
ljc_9449 2008-04-24
  • 打赏
  • 举报
回复
注释了的那三行代码是在里面的,指教!!
ljc_9449 2008-04-24
  • 打赏
  • 举报
回复
inline void ShowYUV(Uint8* pY, Uint8* pU, Uint8* pV, int nWidth, int nHeight)
{
unsigned char *pR = new unsigned char[nWidth*nHeight];
unsigned char *pG = new unsigned char[nWidth*nHeight];
unsigned char *pB = new unsigned char[nWidth*nHeight];

Uint8 Y, U, V;
unsigned char r, g, b;

int nPos;

for (int i = 0; i < nHeight; i++)
{

for (int j = 0; j < nWidth; j++)
{

Y = pY[i*nWidth + j];

U = pU[((int)(i/2))*((int)(nWidth/2)) + (int)(j/2)];
V = pV[((int)(i/2))*((int)(nWidth/2)) + (int)(j/2)];



nPos = i*nWidth + j;

//r = 1.0*Y + 8 + 1.402*(V-128);
//g = 1.0*Y - 0.34413*(U-128)-0.71414*(V-128);
//b = 1.0*Y + 1.772*(U-128)+0;


if (r > 255) r = 255;

if (g > 255) g = 255;

if (b > 255) b = 255;

if (r < 0) r = 0;

if (g < 0) g = 0;

if (b < 0) b = 0;

pR[nPos]= r ;
pG[nPos]= g ;
pB[nPos]= b ;

}
}

delete[] pY;
delete[] pU;
delete[] pV;

R_G_B *pRGB = new R_G_B(pR, pG, pB, nWidth, nHeight);
::SendMessage(hDispWnd, WM_RGBDISP, 0, (LPARAM)pRGB);

}
fire_woods 2008-04-24
  • 打赏
  • 举报
回复
那么把相关的代码也贴出来.
ljc_9449 2008-04-24
  • 打赏
  • 举报
回复
做了保护的,!!!!
fire_woods 2008-04-24
  • 打赏
  • 举报
回复
没有做溢出保护
if(r<0) r = 0;
if(r>255) r = 255;

g和b也一样,都要做保护.

33,006

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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