whitespace: mixed 8ch tabs + spaces -> spaces

This commit is contained in:
wiredfool 2016-10-03 02:54:23 -07:00
parent 0f2d6e0cc5
commit c0d2d2a912

View File

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