⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 422to420.c

📁 YUV格式转换,用于TI的评估板DM6446上
💻 C
字号:








inImageSize = 720*480*2; // input frame is NTSC SD resolution, 422 format
outImageSize = 704*480; // output size for Y plane
fin = fopen (inputFileName, "rb" ); // open file containing input video frames
fout = fopen ( envp->videoOutFile, "wb" ); // open file to write output frames to
// allocate a physically contiguous memory as input buffer and get its physical address
inBuf = Memory_contigAlloc( imageSize, Memory_DEFAULTALIGNMENT);
inBufPhyAddr = Memory_getPhysicalAddress(inBuf);
for ( i = 0; i < 3; i++ ){
resize[i].in_buf.index = -1; // -1 means the buffer is user supplied
resize[i].in_buf.offset = inBufPhyAddr;
}
// Initialize resizer device, get 3 file descriptors corresponding to Y, U, V operation
for ( i = 0; i < 3; i++ ) {
resizerFd[i] = initResizerDevice();
}
// ask resizer to allocate contiguous memory as output buffer for Y, U, V plane
req_outbufs[0].size = outImageSize;
req_outbufs[1].size = outImageSize>>2; // size of U and V plane is 1/4x of Y plane
req_outbufs[2].size = outImageSize>>2;
for ( i = 0; i < 3; i++ ) {
req_outbufs[i].buf_type = RSZ_BUF_OUT;
req_outbufs[i].count = 1;
ioctl( resizerFd[i], RSZ_REQBUF, &req_outbufs[i] );
bufd[i].buf_type = RSZ_BUF_OUT;
bufd[i].index = 0;
ioctl( resizerFd[i], RSZ_QUERYBUF, &bufd[i] );
}
// map output buffers to user space, buffer address for component i is outBuffer[i]
outBuffer[0] = (char*)mmap( 0, outImageSize, PROT_READ | PROT_WRITE,
MAP_SHARED,resizerFd[0], bufd[0].offset );
outBuffer[1] = (char*)mmap( 0, outImageSize>>2, PROT_READ | PROT_WRITE,
MAP_SHARED,resizerFd[1], bufd[0].offset );
outBuffer[2] = (char*)mmap( 0, outImageSize>>2, PROT_READ | PROT_WRITE,
MAP_SHARED,resizerFd[2], bufd[0].offset );
resize[0].out_buf.size = outImageSize;
resize[1].out_buf.size = resize[2].out_buf.size = outImageSize>>2;
for ( i = 0; i < 3; i++ ){
resize[i].out_buf.index = 0; // index != -1 means it is allocated by resizer
}


// clear filter coefficients for safety
for ( i = 0; i < 3; i++ ) {
for ( j = 0; j < 32; j++ ) {
params[i].hfilter_coeffs[j] = 0;
params[i].vfilter_coeffs[j] = 0;
}
}
// set params which are common for Y, U, V
for ( i = 0; i < 3; i++ ) {
// tell resizer to treat input frame as 420 planar format so that operation is 8bit based
params[i].inptyp = RSZ_INTYPE_PLANAR_8BIT;
params[i].pix_fmt = RSZ_PIX_FMT_PLANAR;
params[i].yenh_params.type = RSZ_YENH_DISABLE; // disable Y enhancement module
params[i].cbilin = 0;
params[i].vert_starting_pixel =0;
params[i].horz_starting_pixel =0;
params[i].hstph = 0;
params[i].vstph = 0;
params[i].yenh_params.gain = 0x7f;
params[i].yenh_params.slop = 0x7f;
params[i].yenh_params.core = 0;
}
// set params specific for Y component
params[0].in_vsize = 244;
params[0].in_hsize = 1414;
params[0].out_hsize = 704;
params[0].out_vsize = 480;
params[0].out_pitch = 704;
params[0].in_pitch = 2880;
params[0].hfilt_coeffs[1] = 256; // extract Y from input frame
params[0].vfilt_coeffs[1] = 256; // keep Y values in even rows unchanged
params[0].vfilt_coeffs[16] = -32; // re-interpolate Y values in odd rows using this filter
params[0].vfilt_coeffs[17] = 160;
params[0].vfilt_coeffs[18] = 160;
params[0].vfilt_coeffs[19] = -32;
// set params specific for U, V
for ( i = 1; i < 3; i++ ) {
params[i].in_pitch = 1440;
params[i].out_hsize = 352;
params[i].out_vsize = 240;
params[i].out_pitch = 352;
params[i].in_vsize = 484;
params[i].in_hsize = 1412;
}
params[1].hfilt_coeffs[0] = 256; // extract U from input frame
params[2].hfilt_coeffs[2] = 256; // extract V from input frame
params[1].vfilt_coeffs[0] = 256; // keep U values in even rows unchanged
params[2].vfilt_coeffs[0] = 256; // keep V values in even rows unchanged
// configure the 3 resizer instances using the params
for ( i = 0; i < 3; i++ ) {
ioctl ( resizerFd[i], RSZ_S_PARAM, &params[i] );
}
// set resizer speed to fastest. Since it is a device based parameter instead of a file
// descriptor based parameter, calling it once is enough
rszSpeed = 0;
ioctl( resizerFd[0], RSZ_S_EXP, &rszSpeed );
while ( !feof (fin ) ) {
// keep reading a whole input frame. Quit if not.
if ( inImageSize != fread( inBuf, 1, inImageSize, fin );
break;
// calling resizer 3 times to do de-interlacing and 422 to 420 conversion
for ( i = 0; i < 3; i++ ) {
ioctl( resizerFd[i],RSZ_RESIZE,&resize[i]);

}
// write Y, U, V plane output to file
fwrite( resizedBuffer[0], 1, outImageSize, fout );
fwrite( resizedBuffer[1], 1, outImageSize>>2, fout );
fwrite( resizedBuffer[2], 1, outImageSize>>2, fout );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -