大头
Table_bottom

标签云
Table_bottom

分类
Table_bottom

日历
二月
28293031123
45678910
11121314151617
18192021222324
252627282912
Table_bottom

评论
Table_bottom

留言
Table_bottom

微博
Table_bottom

热门文章
Table_bottom

随机文章
Table_bottom

豆瓣上谁关注这里
Table_bottom

链接
Table_bottom

搜索栏
Table_bottom

RSS
RSS Link
Table_bottom

功能
Table_bottom

页面
Table_bottom

计数器
462866
Table_bottom

访客统计
Table_bottom

存档
Table_bottom

rgb to yuv

 

  1. void RGB2YUV(BYTE *in, BYTE *out, DWORD len)
  2. {
  3.         int r,g,b;
  4.         int y, cb,cr;
  5.         int i;
  6.         int data;
  7.  
  8.         for(i=0; i<len; i=i+4)
  9.         {
  10.                 r = *(in+2);
  11.                 g = *(in+1);
  12.                 b = *(in);
  13.  
  14.                 y= (0.257*r + 0.504*g + 0.098*b + 16);
  15.                 cb = -0.148*r - 0.291*g + 0.439*b + 128;
  16.                 cr = 0.439*r - 0.368*g - 0.071*b + 128;
  17.                 if(y <16)
  18.                 {
  19.                         y = 16;
  20.                 }
  21.                 else if(y>235)
  22.                 {
  23.                         y = 235;
  24.                 }
  25.  
  26.                 if(cb <16)
  27.                 {
  28.                         cb = 16;
  29.                 }
  30.                 else if(cb>240)
  31.                 {
  32.                         cb = 240;
  33.                 }
  34.  
  35.                 if(cr <16)
  36.                 {
  37.                         cr = 16;
  38.                 }
  39.                 else if(cr>240)
  40.                 {
  41.                         cr = 240;
  42.                 }
  43.                 *(DWORD *)out = 0x7f000000 + ((DWORD)cr<<16) + ((DWORD)cb<<8) + (DWORD)y;
  44.  
  45.                 in += 4;
  46.                 out += 4;
  47.         }
  48. }