[AssistantTool]_4_生成原始Color数据文件
Posted 暮色1994
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[AssistantTool]_4_生成原始Color数据文件相关的知识,希望对你有一定的参考价值。
[AssistantTool]_4_生成原始Color数据文件
创建时间:20200525 23:35:58
界面介绍
变量
enum{
FMT_NV12,
FMT_UYVY,
FMT_YUYV,
};
int frameSize;
int width;
int height;
QString fileName;
int frameCount;
int fmt;
char *frameBuff;
int fb;
主要函数
void CreateColorForm::frame_render(int frameCount)
{
int colorIndex = 0;
int frame = 0;
int ret;
char *disY = NULL;
char *disUV = NULL;
int tw = 0;
while(frame < frameCount)
{
qDebug() << "frame_render frame:" << frame;
switch( fmt )
{
case FMT_NV12:
disY = frameBuff;
disUV = frameBuff+width*height;
for(int i = 0; i < height; i++)
{
for(int j = 0; j < width; j++)
{
disY[i*width+j] = (j+colorIndex)%255;
}
}
for(int i = 0; i < height; i++)
{
for(int j = 0; j < width/4; j++)
{
disUV[(i*width/4+j)*2+0] = 90;
disUV[(i*width/4+j)*2+1] = 90;
}
}
colorIndex++;
break;
case FMT_YUYV:
tw = width/2;
for(int i = 0; i < height; i++)
{
for(int j = 0; j < width; j++)
{
frameBuff[(i*width+j)*2] = (j+colorIndex)%255;
}
}
for(int i = 0; i < height; i++)
{
for(int j = 0; j < tw; j++)
{
frameBuff[(i*tw+j)*4+1] = 90;
frameBuff[(i*tw+j)*4+3] = 90;
}
}
colorIndex++;
break;
case FMT_UYVY:
tw = width/2;
for(int i = 0; i < height; i++)
{
for(int j = 0; j < width; j++)
{
frameBuff[(i*width+j)*2+1] = (j+colorIndex)%255;
}
}
for(int i = 0; i < height; i++)
{
for(int j = 0; j < tw; j++)
{
frameBuff[(i*tw+j)*4+0] = 90;
frameBuff[(i*tw+j)*4+2] = 90;
}
}
colorIndex++;
break;
}
//frameBuff
ret = write(fb, frameBuff, frameSize);
qDebug() << "frame_render write ret = " << ret;
frame++;
}
}
/**
* @brief CreateColorForm::createColor
* 创建颜色文件, 分配内存,并调用渲染数据
* @return 0:Ok -1:Err
*/
int CreateColorForm::createColor()
{
frameBuff = (char*)malloc(frameSize);
if( frameBuff == NULL )
{
printf("frameBuff == NULL , malloc Err\\n");
}
qDebug() << "fileName:" << fileName;
fb = ::open(fileName.toStdString().c_str(), O_CREAT|O_RDWR, 0777);
if( fb < 0 )
{
qDebug() << "fileName:" << fileName << "open err";
}
else
{
qDebug() << "fileName:" << fileName << "open ok";
}
frame_render(frameCount);
::close(fb);
qDebug() << "fileName:" << fileName << "close ok";
free(frameBuff);
qDebug() << "createColor run end ok\\n";
return 0;
}
以上是关于[AssistantTool]_4_生成原始Color数据文件的主要内容,如果未能解决你的问题,请参考以下文章
[AssistantTool]_6_添加生成YUV文件的功能