diff --git a/libImaging/File.c b/libImaging/File.c index ac9ec3be1..b669ab665 100644 --- a/libImaging/File.c +++ b/libImaging/File.c @@ -30,26 +30,26 @@ ImagingOpenPPM(const char* infile) Imaging im; if (!infile) - return ImagingError_ValueError(NULL); + return ImagingError_ValueError(NULL); fp = fopen(infile, "rb"); if (!fp) - return ImagingError_IOError(); + return ImagingError_IOError(); /* PPM magic */ if (fgetc(fp) != 'P') - goto error; + goto error; switch (fgetc(fp)) { case '4': /* FIXME: 1-bit images are not yet supported */ - goto error; + goto error; case '5': - mode = "L"; - break; + mode = "L"; + break; case '6': - mode = "RGB"; - break; + mode = "RGB"; + break; default: - goto error; + goto error; } i = 0; @@ -59,66 +59,66 @@ ImagingOpenPPM(const char* infile) while (i < 3) { - /* Ignore optional comment fields */ - while (c == '\n') { - c = fgetc(fp); - if (c == '#') { - do { - c = fgetc(fp); - if (c == EOF) - goto error; - } while (c != '\n'); - c = fgetc(fp); - } - } + /* Ignore optional comment fields */ + while (c == '\n') { + c = fgetc(fp); + if (c == '#') { + do { + c = fgetc(fp); + if (c == EOF) + goto error; + } while (c != '\n'); + c = fgetc(fp); + } + } - /* Skip forward to next value */ - while (isspace(c)) - c = fgetc(fp); + /* Skip forward to next value */ + while (isspace(c)) + c = fgetc(fp); - /* And parse it */ - v = 0; - while (isdigit(c)) { - v = v * 10 + (c - '0'); - c = fgetc(fp); - } + /* And parse it */ + v = 0; + while (isdigit(c)) { + v = v * 10 + (c - '0'); + c = fgetc(fp); + } - if (c == EOF) - goto error; + if (c == EOF) + goto error; - switch (i++) { - case 0: - x = v; - break; - case 1: - y = v; - break; - case 2: - max = v; - break; - } + switch (i++) { + case 0: + x = v; + break; + case 1: + y = v; + break; + case 2: + max = v; + break; + } } im = ImagingNew(mode, x, y); if (!im) - return NULL; + return NULL; /* if (max != 255) ... FIXME: does anyone ever use this feature? */ if (strcmp(im->mode, "L") == 0) { - /* PPM "L" */ - for (y = 0; y < im->ysize; y++) - if (fread(im->image[y], im->xsize, 1, fp) != 1) - goto error; + /* PPM "L" */ + for (y = 0; y < im->ysize; y++) + if (fread(im->image[y], im->xsize, 1, fp) != 1) + goto error; } else { - /* PPM "RGB" or PyPPM mode */ - for (y = 0; y < im->ysize; y++) - for (x = i = 0; x < im->xsize; x++, i += im->pixelsize) - if (fread(im->image[y]+i, im->bands, 1, fp) != 1) - goto error; + /* PPM "RGB" or PyPPM mode */ + for (y = 0; y < im->ysize; y++) + for (x = i = 0; x < im->xsize; x++, i += im->pixelsize) + if (fread(im->image[y]+i, im->bands, 1, fp) != 1) + goto error; } fclose(fp); @@ -140,16 +140,16 @@ ImagingSaveRaw(Imaging im, FILE* fp) /* @PIL227: FIXME: for mode "1", map != 0 to 255 */ - /* PGM "L" */ - for (y = 0; y < im->ysize; y++) - fwrite(im->image[y], 1, im->xsize, fp); + /* PGM "L" */ + for (y = 0; y < im->ysize; y++) + fwrite(im->image[y], 1, im->xsize, fp); } else { - /* PPM "RGB" or other internal format */ - for (y = 0; y < im->ysize; y++) - for (x = i = 0; x < im->xsize; x++, i += im->pixelsize) - fwrite(im->image[y]+i, 1, im->bands, fp); + /* PPM "RGB" or other internal format */ + for (y = 0; y < im->ysize; y++) + for (x = i = 0; x < im->xsize; x++, i += im->pixelsize) + fwrite(im->image[y]+i, 1, im->bands, fp); } @@ -163,24 +163,24 @@ ImagingSavePPM(Imaging im, const char* outfile) FILE* fp; if (!im) { - (void) ImagingError_ValueError(NULL); - return 0; + (void) ImagingError_ValueError(NULL); + return 0; } fp = fopen(outfile, "wb"); if (!fp) { - (void) ImagingError_IOError(); - return 0; + (void) ImagingError_IOError(); + return 0; } if (strcmp(im->mode, "1") == 0 || strcmp(im->mode, "L") == 0) { - /* Write "PGM" */ - fprintf(fp, "P5\n%d %d\n255\n", im->xsize, im->ysize); + /* Write "PGM" */ + fprintf(fp, "P5\n%d %d\n255\n", im->xsize, im->ysize); } else if (strcmp(im->mode, "RGB") == 0) { /* Write "PPM" */ fprintf(fp, "P6\n%d %d\n255\n", im->xsize, im->ysize); } else { - (void) ImagingError_ModeError(); + (void) ImagingError_ModeError(); return 0; }