📄 lecture02_subprogram.c
字号:
//--------------- lecture02_subprogram.c start--------------
void RGB24_to_YUV444(
unsigned char * RGB_in,
unsigned char * YUV_out,
short width,short height)
{
int i,N;
short tmpY,tmpU,tmpV;
unsigned char * p_RGB, * p_YUV;
N = (int)(width * height);
p_RGB = RGB_in;
p_YUV = YUV_out;
for( i=0; i<N; i++ )
{
tmpY = 0.2990*(*p_RGB) + 0.5870*(*(p_RGB+1)) + 0.1140*(*(p_RGB+2));
tmpU = -0.1684*(*p_RGB) - 0.3316*(*(p_RGB+1)) + 0.5000*(*(p_RGB+2))+128;
tmpV = 0.5000*(*p_RGB) - 0.4187*(*(p_RGB+1)) - 0.0813*(*(p_RGB+2))+128 ;
if (tmpY <0) tmpY = 0;
if (tmpY > 255) tmpY = 255;
if (tmpU <0) tmpU = 0;
if (tmpU > 255) tmpU = 255;
if (tmpV <0) tmpV = 0;
if (tmpV > 255) tmpV = 255;
*p_YUV = (unsigned char) tmpU;
*(p_YUV+1) = (unsigned char)tmpY;
*(p_YUV+2) = (unsigned char)tmpV;
p_RGB +=3;
p_YUV +=3;
}
}
void YUV444_to_YUV422(
unsigned char * YUV444_in,
unsigned char * YUV422_out,
short width,short height)
{ int i,N;
unsigned char * p_in, * p_out;
N = (int)(width * height);
p_in = YUV444_in;
p_out = YUV422_out;
for( i=0; i<(N/2); i++ )
{ *p_out = *p_in;
*(p_out+1) = *(p_in+1);
*(p_out+2) = *(p_in+2);
*(p_out+3) = *(p_in+4);
p_in +=6;
p_out +=4;
}
}
void Rotate_image (
unsigned char * image_in,
unsigned char * image_out,
short width,short height)
{
int i ,j ,N;
unsigned char *p_in, *p_out;
N=(int)(width*height);
p_in = image_in;
p_out = image_out;
for(j=width/2-1; j>=0; j--)
{
for(i=0; i<height; i++)
{
*p_out = *(p_in+j*4+i*width*2);
*(p_out+1) = *(p_in+j*4+i*width*2+3);
*(p_out+2) = *(p_in+j*4+i*width*2+2);
p_out +=3;
i++;
*p_out = *(p_in+j*4+i*width*2+3);
p_out++;
}
for(i=0; i<height; i++)
{
*p_out = *(p_in+j*4+i*width*2);
*(p_out+1) = *(p_in+j*4+i*width*2+1);
*(p_out+2) = *(p_in+j*4+i*width*2+2);
p_out +=3;
i++;
*p_out = *(p_in+j*4+i*width*2+1);
p_out++;
}
}
}
void Get_NTSC_frame_from_ITU656(unsigned char* buffer_in,unsigned char *buffer_out)
{
int i,j;
unsigned char *p_in, *p_out;
p_in = buffer_in;
p_out = buffer_out;
p_out += 1440;
for(j=0;j<263;)
{
if(*p_in == 0xFF && *(p_in+1)==0 && *(p_in+2)==0)
{
p_in += 3;
if((*p_in & 0x20) == 0x20)
{
do
{
p_in += 1716;
j++;
}while((*p_in & 0x20) == 0x20);
if((*p_in & 0x10) == 0x10)
{
p_in += 272;
}
}
else if((*p_in & 0x10) == 0x10)
{
p_in += 272; //268+4
}
p_in ++;
for(i=0;i<1440;i++)
{
*p_out = *p_in;
p_out ++;
p_in ++;
}
p_out += 1440;
j++;
}
else p_in++;
}
p_out = buffer_out;
for(j=0;j<262;)
{
if(*p_in == 0xFF && *(p_in+1)==0 && *(p_in+2)==0)
{
p_in += 3;
if((*p_in & 0x20) == 0x20)
{
do
{
p_in += 1716;
j++;
}while((*p_in & 0x20) == 0x20);
if((*p_in & 0x10) == 0x10)
{
p_in += 272;
}
}
else if((*p_in & 0x10) == 0x10)
{
p_in += 272; //268+4
}
p_in ++;
for(i=0;i<1440;i++)
{
*p_out = *p_in;
p_out ++;
p_in ++;
}
p_out += 1440;
j++;
}
else p_in++;
}
}
//--------------- lecture02_subprogram.c end-----------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -