bmp中提取rgb888格式的数据 ,转换成yv12格式,
再从yv12格式转换成rgb888格式的数据
然后以bmp格式写入文件的测试工程。
///-------------rgb.cpp-----------内容是rgb与yv12格式转换函数
#include "convert.h"
// Conversion from RGB to YUV420
int RGB2YUV_YR[256], RGB2YUV_YG[256], RGB2YUV_YB[256];
int RGB2YUV_UR[256], RGB2YUV_UG[256], RGB2YUV_UBVR[256];
int RGB2YUV_VG[256], RGB2YUV_VB[256];
// Conversion from YUV420 to RGB24
static long int crv_tab[256];
static long int cbu_tab[256];
static long int cgu_tab[256];
static long int cgv_tab[256];
static long int tab_76309[256];
static unsigned char clp[1024]; //for clip in CCIR601
// Table used for RGB to YUV420 conversion
void InitLookupTable()
{
int i;
for (i = 0; i < 256; i++) RGB2YUV_YR[i] = (float)65.481 * (i<<8);
for (i = 0; i < 256; i++) RGB2YUV_YG[i] = (float)128.553 * (i<<8);
for (i = 0; i < 256; i++) RGB2YUV_YB[i] = (float)24.966 * (i<<8);
for (i = 0; i < 256; i++) RGB2YUV_UR[i] = (float)37.797 * (i<<8);
for (i = 0; i < 256; i++) RGB2YUV_UG[i] = (float)74.203 * (i<<8);
for (i = 0; i < 256; i++) RGB2YUV_VG[i] = (float)93.786 * (i<<8);
for (i = 0; i < 256; i++) RGB2YUV_VB[i] = (float)18.214 * (i<<8);
for (i = 0; i < 256; i++) RGB2YUV_UBVR[i] = (float)112 * (i<<8);
}
// Convert from RGB24 to YUV420
//int ConvertRGB2YUV(int w,int h,unsigned char *bmp,unsigned int *yuv)
int ConvertRGB2YUV(int w,int h,unsigned char *bmp,unsigned char*yuv)
{
//unsigned int *u,*v,*y,*uu,*vv;
//unsigned int *pu1,*pu2,*pu3,*pu4;
//unsigned int *pv1,*pv2,*pv3,*pv4;
//unsigned char *r,*g,*b;
//int i,j;
//uu=new unsigned int[w*h];
//vv=new unsigned int[w*h];
unsigned char *u,*v,*y,*uu,*vv;
unsigned char *pu1,*pu2,*pu3,*pu4;
unsigned char *pv1,*pv2,*pv3,*pv4;
unsigned char *r,*g,*b;
int i,j;
uu=new unsigned char[w*h];
vv=new unsigned char[w*h];
if(uu==NULL || vv==NULL)
return 0;
y=yuv;
u=uu;
v=vv;
// Get r,g,b