53 int8_t *y_data,*py_data;
54 int8_t *u_data,*pu_data;
55 int8_t *v_data,*pv_data;
76 for(i = 1; i < (unsigned)argc; i++) {
77 if (
strncmp(argv[i],
"-h=",3) == 0 ) {
78 height=
atoi(argv[i]+3);
80 else if (
strncmp(argv[i],
"-w=",3) == 0 ) {
81 width=
atoi(argv[i]+3);
83 else if(
strcmp(argv[i],
"-split") == 0 ) {
86 else if(
strcmp(argv[i],
"-skipy") == 0 ) {
89 else if(
strcmp(argv[i],
"-rgb") == 0 ) {
100 fprintf(stderr,
"%s: unknown option %s\n",argv[0],argv[i]);
106 fprintf(stderr,
"%s: missing input file\n",argv[0]);
110 fprintf(stderr,
"%s: missing output file\n",argv[0]);
113 if(!height || !width) {
114 fprintf(stderr,
"%s: invalid dimensions\n",argv[0]);
118 if(
stat(iname,&st) != 0) {
119 fprintf(stderr,
"%s: bad input file %s\n",argv[0],iname);
123 if((width*12)%8 != 0) {
124 fprintf(stderr,
"WARNING: width %u not an integral number of bytes at 12 bpp\n",width);
128 npixels=height*
width;
129 isize = (npixels*12)/8;
130 if(isize > st.st_size) {
131 fprintf(stderr,
"%s: ERROR: dimensions too large for input file (%u*%u*12)/8=%u > %lu\n",
132 argv[0],width,height,isize,(
unsigned long)st.st_size);
134 }
else if ( isize < st.st_size) {
135 fprintf(stderr,
"%s: WARNING: dimensions smaller than input file (%u*%u*12)/8=%u < %lu\n",
136 argv[0],width,height,isize,(
unsigned long)st.st_size);
139 if(!rgb && !split_yuv) {
140 fprintf(stderr,
"nothing to do!\n");
148 fp=
fopen(iname,
"rb");
151 rcount=
fread(in_data,1,isize,fp);
156 fprintf(stderr,
"input: %s %ux%u UYVYYY %u bytes\n",iname, width, height, isize);
159 fprintf(stderr,
"output: %s.Y %ux%u %s.U,V %ux%u\n", oname, width, height,oname,width/4,height);
161 py_data = y_data=
malloc(npixels);
163 pu_data = u_data=
malloc(npixels/4);
165 pv_data = v_data=
malloc(npixels/4);
167 for (i=0;i<isize; i+=6) {
168 *py_data++ = in_data[i+1];
169 *py_data++ = in_data[i+3];
170 *py_data++ = in_data[i+4];
171 *py_data++ = in_data[i+5];
172 *pu_data++ = in_data[i];
173 *pv_data++ = in_data[i+2];
176 sprintf(splitname,
"%s.Y",oname);
177 fp=
fopen(splitname,
"wb");
179 fwrite(y_data, 1, npixels, fp);
183 sprintf(splitname,
"%s.U",oname);
184 fp=
fopen(splitname,
"wb");
186 fwrite(u_data, 1, npixels/4, fp);
190 sprintf(splitname,
"%s.V",oname);
191 fp=
fopen(splitname,
"wb");
193 fwrite(v_data, 1, npixels/4, fp);
207 osize = (owidth*
height)*3;
211 prgb_data = out_data;
212 p_yuv = (uint8_t*)in_data;
214 sprintf(rgbname,
"%s-%d.RGB",oname,owidth);
216 fprintf(stderr,
"output: %s %ux%u RGB8 %u bytes\n", rgbname, owidth, height, osize);
218 for (i=0;i<npixels; i+=4, p_yuv+=6) {
219 yuv_to_rgb(&prgb_data,p_yuv[1],p_yuv[0],p_yuv[2]);
220 yuv_to_rgb(&prgb_data,p_yuv[3],p_yuv[0],p_yuv[2]);
223 yuv_to_rgb(&prgb_data,p_yuv[4],p_yuv[0],p_yuv[2]);
224 yuv_to_rgb(&prgb_data,p_yuv[5],p_yuv[0],p_yuv[2]);
227 fp=
fopen(rgbname,
"wb");
229 fwrite(out_data, 1, osize, fp);
234 fprintf(stderr,
"done\n");