📄 yuv2rgb.txt
字号:
#include <stdio.h> #include <stdlib.h> #include <sys time.h=""> struct dummy { int yuv[3]; int stride[3]; }; typedef struct AVPicture { unsigned char *data[4]; int linesize[4]; ///< number of bytes per line } AVPicture; //void convert_yuv420_rgb565( unsigned char *src, unsigned short *dst_ori, int width, int height ); //void convert_yuv420_rgb565(AVPicture *picture, unsigned char *results, int w, int h) ; //void convert_yuv420_rgb565(struct dummy *picture, unsigned char *results, int w, int h); void convert_yuv420_rgb565(struct dummy *picture, unsigned char *results, unsigned char *_py,unsigned char *_pu,unsigned char *_pv); int main( int argc, char *argv[] ) { int fileback; int frameWidth=176; int frameHeight=144; int rgbstride= (640+128)*2; int destwidth=640; int destheight=240; int frameSize; struct timeval tm_start,tm_end; int elapsedTime; unsigned char *bufferYUV; unsigned short *bufferRGB; FILE *filedata; struct dummy picture; // AVPicture picture; if ( argc < 2 ) { fprintf(stderr, "160 120 \n"); return 1; } frameWidth = atoi( argv[1] ); frameHeight = atoi( argv[2] ); frameSize = frameWidth * frameHeight * 3 / 2; bufferYUV = (unsigned char *)malloc( frameSize ); bufferRGB = (unsigned short *)malloc( 768*240 *2 ); filedata = fopen( "input06_YUV420_176_144.raw", "rb" ); /*file name *****/ if ( !filedata ) { fprintf( stderr, "couldn't open the source file \n" ); return 1; } fileback = fread( bufferYUV, 1, frameSize, filedata ); if ( fileback != frameSize ) { printf( "error: the resolution doesn't agree with file size\n" ); return 1; } fclose( filedata ); filedata = fopen( "output.raw", "wb" ); /****rgb file name **************/ if ( !filedata ) { fprintf( stderr, "couldn't open the source file \n" ); return 1; } #if 1 // picture.yuv[0] = bufferYUV; //picture.yuv[1] = bufferYUV + frameWidth * frameHeight; // picture.yuv[2] = bufferYUV + frameWidth * frameHeight * 5 / 4; picture.yuv[0] = destwidth; picture.yuv[1] = destheight; picture.yuv[2] = 0; // picture.stride[0] = frameWidth * frameHeight; // picture.stride[1] = picture.stride[2] = frameWidth * frameHeight / 4; //picture.stride[0] = frameWidth; //picture.stride[1] = picture.stride[2] = frameWidth / 2; picture.stride[0] = frameWidth; picture.stride[1] = frameHeight; picture.stride[2] = rgbstride; #else picture.data[0] = bufferYUV; picture.data[1] = bufferYUV + frameWidth * frameHeight; picture.data[2] = bufferYUV + frameWidth * frameHeight * 5 / 4; picture.data[3] = NULL; picture.linesize[0] = frameWidth; picture.linesize[1] = picture.linesize[2] = frameWidth / 2; picture.linesize[3] = 0; #endif unsigned char *_py ; _py = bufferYUV; unsigned char *_pu; _pu = bufferYUV + frameWidth * frameHeight; unsigned char *_pv; _pv = bufferYUV +frameWidth * frameHeight*5/4; gettimeofday( &tm_start, NULL ); convert_yuv420_rgb565( &picture, (unsigned char *)bufferRGB, _py,_pu,_pv); gettimeofday( &tm_end, NULL ); elapsedTime = (int)( tm_end.tv_sec - tm_start.tv_sec ) * 1000000L + (int)( tm_end.tv_usec - tm_start.tv_usec ); printf( "total time elapsed: %d (us)\n", elapsedTime ); fwrite( bufferRGB, 1, 768*240*2, filedata ); fclose( filedata ); //house keeping free( bufferYUV ); free( bufferRGB ); return 0; } /* main */ </sys></stdlib.h></stdio.h>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -