做技术开发的把平时的经验写下来是一种财富

   

  从上一家公司辞职后,有些东西找不到了。时间长了,之前解决过的问题,现在又要重新找资料来解决,这是一种损失。

 

   1、把图像数据保存到 yuv文件中,然后用yuv播放器检测保存的图像数据是否正确。

   
 tstring strFile = _T("F://test1.yuv");


 FILE* pFile = _tfopen(strFile.c_str(),_T("wb"));
 
  fwrite(pBuffer,sizeof(char),lLength,pFile);
 

  fclose(pFile);
 

其实,不管是long*, 还是 char * ,只要把指针地址长度(此长度是以char*的长度)然后以char*的字符保存,就是图像所有char* 的图像数据。

 

YUV播放器 yuvplayer.exe。

 

2、YUV数据的转换

  颜色空间 RGB、YUV、Gray图像数据的转换。

//RGB转Gray

RGB2Gray(const GTByte *psrc, GTByte *pdst, int w, int h)
{
 for (int i=0; i<h; i++)
 {
  int p_d = i * w;
  int p_s = i * w * 3;
  for (int j=0; j<w; j++)
  {
   int value = (30 * psrc[p_s] + 59 * psrc[p_s + 1] + 11 * psrc[p_s + 2]) / 100;
   pdst[p_d] = value;
   p_d += 1;
   p_s += 3;
  }
 }
}

YUV422和YUV420是有区别的。YUV422:Y0U0Y1V1 Y2U2Y3V3 Y4U4Y5V5 ...  YUV420:Y0U0Y1 Y2V2Y3 Y4U4Y5..等,转为Gray只需把其中的Y值按顺序取出即可。

//YUV422转Gray

YUV2Gray(const GTByte *psrc, GTByte *pdst, int w, int h)
{
 for (int i=0; i<h; i++)
 {
  for (int j=0; j<w; j++)
  {
   int p_d = i * w + j;
   int p_s = p_d * 2 + 1;
   pdst[p_d] = psrc[p_s];
  }
 }
}

//YUV 420转Gray

YUV0Gray(const GTByte *psrc, GTByte *pdst, int w, int h)
{
 for (int i=0; i<h/2; i++)
 {
  for (int j=0; j<w/2; j++)
  {
   int p_d = i * w + j;
   int p_s = p_d * 3;
   int p_s2 = p_d * 3 + 2;
   pdst[p_d*2] = psrc[p_s];
   pdst[p_d*2+1] = psrc[p_s2];
  }
 }
}

3、图像缩放

ResampleImage(const GTByte *psrc, int srcW, int srcH, GTByte *pdst, int dstW, int dstH)
{
 for (int i=0; i<dstH; i++)
 {
  for (int j=0; j<dstW; j++)
  {
   int p_s = (i * srcW + j) * ratio;
   int p_d = (i * dstW + j);

   pdst[p_d]   = psrc[p_s];
   pdst[p_d+1] = psrc[p_s+1];
   pdst[p_d+2] = psrc[p_s+2];
  }
 }
}

 4、图像中的部分图像Copy

CropImage(const GTByte *psrc, GTByte *pdst, int w, int h, GTRect rect)
{
 int dst_w = rect.right - rect.left + 1;
 int dst_h = rect.bottom - rect.top + 1;

 for (int i=rect.top; i<=rect.bottom; i++)
 {
  int p_s = i * w + rect.left;
  int p_d = (i - rect.top) * dst_w;
  memcpy(pdst + p_d, psrc + p_s, dst_w);
 }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值