织梦CMS - 轻松建站从此开始!

罗索

YV12_to_RGB24的源代码

罗索客 发布于 2005-12-28 11:02 点击:次 
弄了一下午,感觉优化的还可以了,欢迎提出更好的优化方案。 //*/ // Converter of YV12 to RGB24 // the size of pYUV is (3 * iWidth * iHeight / 2) // and size of pRGB is (3 * iWidth * iHeight) // if sucess return true, else return false bool YV12_to_RGB24
TAG:

弄了一下午,感觉优化的还可以了,欢迎提出更好的优化方案。

//*/
// Converter of YV12 to RGB24
// the size of pYUV is (3 * iWidth * iHeight / 2)
// and size of pRGB is (3 * iWidth * iHeight)
// if sucess return true, else return false
bool YV12_to_RGB24(unsigned char* pYV12, unsigned char* pRGB24, int iWidth, int iHeight)
{
if(!pYV12 || !pRGB24)
  return false;

const long nYLen = long(iHeight * iWidth);
const int nHfWidth = (iWidth>>1);

if(nYLen<1 || nHfWidth<1)
  return false;

// yv12's data structure
// |WIDTH |
// y......y--------
// y......y  HEIGHT
// y......y
// y......y--------
// v..v
// v..v
// u..u
// u..u
unsigned char* yData = pYV12;
unsigned char* vData = &yData[nYLen];
unsigned char* uData = &vData[nYLen>>2];

if(!uData || !vData)
  return false;

// Convert YV12 to RGB24
//
// formula
//                           [1     1        1       ]
// [r g b] = [y u-128 v-128] [0     0.34375  0       ]
//                           [1.375 0.703125 1.734375]
// another formula
//                           [1         1         1       ]
// [r g b] = [y u-128 v-128] [0         0.698001  0       ]
//                           [1.370705  0.703125  1.732446]
int rgb[3];
int i, j, m, n, x, y;
m = -iWidth;
n = -nHfWidth;
for(y=0; y {
  m += iWidth;
  if(!(y % 2))
   n += nHfWidth;
  for(x=0; x  {
   i = m + x;
   j = n + (x>>1);
   rgb[2] = int(yData[i] + 1.370705 * (vData[j] - 128)); // r
   rgb[1] = int(yData[i] - 0.698001 * (uData[j] - 128)  
         - 0.703125 * (vData[j] - 128)); // g
   rgb[0] = int(yData[i] + 1.732446 * (uData[j] - 128)); // b

   j = nYLen - iWidth - m + x;
   i = (j<<1) + j;
   for(j=0; j<3; j++)
   {
    if(rgb[j]>=0 && rgb[j]<=255)
     pRGB24[i + j] = rgb[j];
    else
     pRGB24[i + j] = (rgb[j] < 0)? 0 : 255;
   }
  }
}
return true;
}
//*/
(iwgh)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/200512/817.html]
本文出处: 作者:iwgh
顶一下
(8)
80%
踩一下
(2)
20%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容