笔者注:CIF文件内存放的是352*288真彩色数据
- #include <stdio.h>
- #include <stdlib.h>
- #define WIDTH 352
- #define HEIGHT 288
- //转换矩阵
- double YuvToRgb[3][3] = {1, 0 , 1.4022 ,
- 1, -0.3456, -0.7145 ,
- 1, 1.771 , 0 };
- //根据RGB三分量写BMP,不必关注
- int WriteBmp(int width, int height, unsigned char *R,unsigned char *G,unsigned char *B, char *BmpFileName);
- //转换函数
- int Convert(char *file, int width, int height, int n)
- {
- //变量声明
- int i = 0;
- int temp = 0;
- int x = 0;
- int y = 0;
- int fReadSize = 0;
- int ImgSize = width*height;
- FILE *fp = NULL;
- unsigned char* yuv = NULL;
- unsigned char* rgb = NULL;
- unsigned char* cTemp[6];
- char BmpFileName[256];
- //申请空间
- int FrameSize = ImgSize + (ImgSize >> 1);
- yuv = (unsigned char *)malloc(FrameSize);
- rgb = (unsigned char *)malloc(ImgSize*3);
- //读取指定文件中的指定帧