[MPlayer-dev-eng] New remove-logo filter
Reimar Döffinger
Reimar.Doeffinger at stud.uni-karlsruhe.de
Wed Feb 23 19:00:35 CET 2005
Hi,
On Wed, Feb 23, 2005 at 06:14:59PM +0100, Reimar Döffinger wrote:
> No it is not (that's why I said raw pgm, not ASCII pgm). Only the header is TEXT.
If that still scares you, I attached a working parser for pgm file.
Instead of the last three fgetc you should of course use fread to read
the whole image data in a block.
Greetings,
Reimar Döffinger
-------------- next part --------------
#include <stdio.h>
#include <ctype.h>
void skip(FILE *f) {
int c, comment = 0;
do {
c = fgetc(f);
if (c == '#')
comment = 1;
if (c == '\n')
comment = 0;
} while (c != EOF && (isspace(c) || comment));
ungetc(c, f);
}
int main() {
int width, height, maxval, val;
FILE *f = fopen("test.pgm", "r");
if (!f)
return -1;
skip(f);
if (fgetc(f) != 'P' || fgetc(f) != '5')
return -1;
skip(f);
if (fscanf(f, "%i", &width) != 1)
return -1;
skip(f);
if (fscanf(f, "%i", &height) != 1)
return -1;
skip(f);
if (fscanf(f, "%i", &maxval) != 1)
return -1;
val = fgetc(f);
if (!isspace(val))
return -1;
printf("w: %i, h: %i, m: %i\n", width, height, maxval);
printf("val1: %i\n", fgetc(f));
printf("val2: %i\n", fgetc(f));
printf("val3: %i\n", fgetc(f));
fclose(f);
return 0;
}
More information about the MPlayer-dev-eng
mailing list