if ((ic = getc(f)) == EOF) {
fprintf(stderr, "Premature end of file\n");
return -1;
}
c = (char)ic;
if (c == '#') {
do {
if ((ic = getc(f)) == EOF) {
fprintf(stderr, "Premature end of file\n");
return -1;
}
c = (char)ic;
} while (c != '\n' && c != '\r');
}
return c;
}
static int getint(FILE *f)
{
register char c;
register int i;
do {
if ((c = pgetc(f)) == -1)
return -1;
} while (c == ' ' || c == '\t' || c == '\n' || c == '\r');
if (c < '0' || c > '9') {
fprintf(stderr, "Junk in file where an integer should be\n");
return -1;
}
i = 0;
do {
i = i * 10 + c - '0';
if ((c = pgetc(f)) == -1)
return -1;
} while (c >= '0' && c <= '9');
return i;
}
static void readhdr(FILE *f, int *w, int *h)
{
int magic, maxval;
static int lastw = -1, lasth = -1;
if ((magic = getmagic(f)) == -1) exit(1);
if ((*w = getint(f)) == -1) exit(1);
if ((*h = getint(f)) == -1) exit(1);
if ((maxval = getint(f)) == -1) exit(1);
if (magic != 'P' * 256 + '5') {
fprintf(stderr, "yuv2rgb: Not a PGM file\n");
exit(1);
}
if (maxval != 255) {
fprintf(stderr, "yuv2rgb: Maxval != 255\n");
exit(1);
}
if (lastw != -1) {
if (*w != lastw || *h != lasth) {
fprintf(stderr, "yuv2rgb: Inconsistent dimensions\n");
exit(1);
}
}
lastw = *w; lasth = *h;
}
int main(int argc, char **argv)
{
FILE *fy, *fu, *fv;
int w, h, x, y;