做技术开发的把平时的经验写下来是一种财富
2015-01-05 14:21
225 查看
从上一家公司辞职后,有些东西找不到了。时间长了,之前解决过的问题,现在又要重新找资料来解决,这是一种损失。
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);
}
}
相关文章推荐
- 8月19日BBUG:电信技术开发经验分享与前景展望
- 实习结束了,临走还捞了一票...和Jason聊了许多关于以后在校园技术实践以及学习的方法,宝贵经验,记录下来。
- 平时积累的有关MSDN 里ActiveX开发技术的一些链接
- 从程序员到技术总监,分享10年开发经验
- 从程序员到技术总监,分享10年开发经验
- WinHack的开发技术经验(1)-使用 Unicode 作为内部字符串处理
- 从程序员到技术总监,分享10年开发经验
- iphone开发中文章显示的一种排版技术
- 页面驱动开发(Page Driven) —— 一种大多数人还不认同的技术
- 从程序员到技术总监,分享10年开发经验
- 一种优化的技术开发方法
- 软件开发技术学习的经验
- 8月19日BBUG:电信技术开发经验分享与前景展望
- 有一种开发的高级技术叫测试
- 平时积累的有关MSDN 里ActiveX开发技术的一些链接
- 7年软件开发技术学习的经验与模式总结Part1
- 真正的创新必然是基于对市场的了解,对客户反馈的观察,开发出来的产品一定要适应市场,提出的模式一定要能解决现实的问题。而在这其中,技术只是一种实现手段。
- 帮朋友发个“招10年以上开发经验的技术人员”
- 从程序员到技术总监,分享10年开发经验
- 从程序员到技术总监,分享10年开发经验