概述
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<cmath>
int Convert(char *input, char *output)
{
int h,v;
unsigned char * buff_in;
unsigned char * buff_out;
unsigned char * buf;
unsigned char r, g, b;
FILE* in = fopen( input, "rw+" );
if ( in == NULL ) {
printf("open file %s failedn", input);
return -1;
}
FILE* out = fopen( output, "w+" );
if ( in == NULL ) {
printf("open file %s failedn", output);
return -1;
}
buff_in = (unsigned char *)malloc(1824*944*3);
buff_out = (unsigned char *)malloc(1824*944*3);
buf = (unsigned char *)malloc(1824*944*3);
fread(buff_in, 1824*944*3 ,1 ,in);
for(v=0;v<944;v++){
for(h=0;h<1824;h++){
b= buff_in[v*1824*3+3*h];
g= buff_in[v*1824*3+3*h+1];
r= buff_in[v*1824*3+3*h+2];
buf[v*1824*3+3*h+0] = 0.299*r + 0.587*g + 0.114*b;
buf[v*1824*3+3*h+1] = -0.169*r - 0.331*g + 0.5 *b + 128;
buf[v*1824*3+3*h+2] = 0.5 *r - 0.419*g - 0.081*b + 128;
}
}
#if 1
for(v=0;v<472;v++){
for(h=0;h<912;h++){
buff_out[1824*944+v*1824+2*h] = buf[v*2*1824*3+3*2*h +1];
buff_out[1824*944+v*1824+2*h+1]=buf[v*2*1824*3+3*2*h +2];
}
}
#endif
for(v=0;v<944;v++){
for(h=0;h<1824;h++){
buff_out[v*1824+h] = buf[v*1824*3+3*h];
}
}
fwrite(buff_out, 1824*944*1.5, 1, out);
fclose(in);
fclose(out);
free(buff_in);
free(buff_out);
return 0;
}
int main(int argc, char **argv)
{
if(argc < 2)
printf("please input read filen");
char *input_name = argv[1];
printf("input file name:%s n", input_name);
char *output_name = argv[2];
printf("output file name:%s n", output_name);
int ret = Convert(input_name, output_name);
if(ret < 0)
printf("convert failed!n");
return 0;
}
最后
以上就是甜美百合为你收集整理的rgb to nv12的全部内容,希望文章能够帮你解决rgb to nv12所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复