The following code works perfectly to create 8 bit YUV files. I want to update it to be able to create 10 bit YUV files. But the char function does not allow integers more than 255.
I've tried changing it to short or int but I get incompatible pointer type errors. I've spent hours researching alternative approaches but have not been able to figure out how to adjust this code. Any help appreciated.
/*
MPEG 2 decoder bitstream xfer
*/
#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 < 360; 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 < 360; j++) {
for(i = 0; i < 960; i++) {
if(i < 320 || i > 639) {
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);
}
}
}
fclose(fpout);
return 0;