I am trying to re-purpose this C code for my purposes. It creates a YUVY file with a colored box in the center and black background. The Y'CbCr colors are entered on the command line for the rectangle in the center. It works great with the only exception being I would like to change the size of the colored box. I've spent hours trying to figure out for how to change it with lots of trial and error and searching online for answers with no luck. Not being a programmer, I don't understand how the logic elements of this code works.
My goal: The overall resolution is 1920 x 1080 and I want the box to be 1/3 of both the vertical and horizontal grid in the center. So the x coordinates would be between 360 and 720 with the y coordinates between 640 and 1280. I've tried creating if, then logic that specifies these intersections but I get all black or red files or a red box in the corner, etc. No matter what I try I can't get the desired result. Any help would be appreciated.
#include <stdio.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
int main(int argc, char **argv)
{
FILE *fpout;
unsigned int i, j;
unsigned char y, cb, cr, temp;
if (argc != 5) {
fprintf(stderr, "usage: pat<outfile> <Y> <Cb> <Cr>\n");
exit(-1);
}
/*--- open binary file (for parsing) ---*/
fpout = fopen(argv[1], "wb");
if (fpout == 0) {
fprintf(stderr, "Cannot open output file <%s>\n", argv[1]);
exit(-1);
}
for(j = 0; j < 264; j++) {
for(i = 0; i < 960; i++) {
y = 16;
cr = 128;
cb = 128;
fwrite(&cb, 1, 1, fpout);
fwrite(&y, 1, 1, fpout);
fwrite(&cr, 1, 1, fpout);
fwrite(&y, 1, 1, fpout);
}
}
for(j = 0; j < 552; j++) {
for(i = 0; i < 960; i++) {
if(i < 240 || i > 719) {
y = 16;
cr = 128;
cb = 128;
fwrite(&cb, 1, 1, fpout);
fwrite(&y, 1, 1, fpout);
fwrite(&cr, 1, 1, fpout);
fwrite(&y, 1, 1, fpout);
}
else {
temp = atoi(argv[2]);
y = temp;
temp = atoi(argv[3]);
cb = temp;
temp = atoi(argv[4]);
cr = temp;
fwrite(&cb, 1, 1, fpout);
fwrite(&y, 1, 1, fpout);
fwrite(&cr, 1, 1, fpout);
fwrite(&y, 1, 1, fpout);
}
}
}
for(j = 0; j < 264; j++) {
for(i = 0; i < 960; i++) {
y = 16;
cr = 128;
cb = 128;
fwrite(&cb, 1, 1, fpout);
fwrite(&y, 1, 1, fpout);
fwrite(&cr, 1, 1, fpout);
fwrite(&y, 1, 1, fpout);
}
}
fclose(fpout);
return 0;
Aucun commentaire:
Enregistrer un commentaire