From 1a43da7a8bda884a597f3a1623364f4719d21c14 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Mon, 3 Oct 2016 03:09:54 -0700 Subject: [PATCH] Removed 'Debugging' open_ppm call that didn't check file provided parameters for sanity --- PIL/EpsImagePlugin.py | 5 +- PIL/IptcImagePlugin.py | 11 ++--- PIL/JpegImagePlugin.py | 4 +- PIL/PpmImagePlugin.py | 5 -- _imaging.c | 14 ------ libImaging/File.c | 110 ----------------------------------------- 6 files changed, 9 insertions(+), 140 deletions(-) diff --git a/PIL/EpsImagePlugin.py b/PIL/EpsImagePlugin.py index 9a668125a..77a7e7e1c 100644 --- a/PIL/EpsImagePlugin.py +++ b/PIL/EpsImagePlugin.py @@ -145,7 +145,8 @@ def Ghostscript(tile, size, fp, scale=1): status = gs.wait() if status: raise IOError("gs failed (status %d)" % status) - im = Image.core.open_ppm(outfile) + im = Image.open(outfile) + im.load() finally: try: os.unlink(outfile) @@ -154,7 +155,7 @@ def Ghostscript(tile, size, fp, scale=1): except OSError: pass - return im + return im.im.copy() class PSFile(object): diff --git a/PIL/IptcImagePlugin.py b/PIL/IptcImagePlugin.py index ed3bf81b1..1de17cbba 100644 --- a/PIL/IptcImagePlugin.py +++ b/PIL/IptcImagePlugin.py @@ -168,14 +168,9 @@ class IptcImageFile(ImageFile.ImageFile): o.close() try: - try: - # fast - self.im = Image.core.open_ppm(outfile) - except: - # slightly slower - im = Image.open(outfile) - im.load() - self.im = im.im + _im = Image.open(outfile) + _im.load() + self.im = _im.im finally: try: os.unlink(outfile) diff --git a/PIL/JpegImagePlugin.py b/PIL/JpegImagePlugin.py index e216fa06d..ef229e611 100644 --- a/PIL/JpegImagePlugin.py +++ b/PIL/JpegImagePlugin.py @@ -377,7 +377,9 @@ class JpegImageFile(ImageFile.ImageFile): raise ValueError("Invalid Filename") try: - self.im = Image.core.open_ppm(path) + _im = Image.open(path) + _im.load() + self.im = _im.im finally: try: os.unlink(path) diff --git a/PIL/PpmImagePlugin.py b/PIL/PpmImagePlugin.py index 68073cace..adaf8384c 100644 --- a/PIL/PpmImagePlugin.py +++ b/PIL/PpmImagePlugin.py @@ -123,11 +123,6 @@ class PpmImageFile(ImageFile.ImageFile): self.fp.tell(), (rawmode, 0, 1))] - # ALTERNATIVE: load via builtin debug function - # self.im = Image.core.open_ppm(self.filename) - # self.mode = self.im.mode - # self.size = self.im.size - # # -------------------------------------------------------------------- diff --git a/_imaging.c b/_imaging.c index ef5d346ba..47334f184 100644 --- a/_imaging.c +++ b/_imaging.c @@ -686,17 +686,6 @@ _radial_gradient(PyObject* self, PyObject* args) return PyImagingNew(ImagingFillRadialGradient(mode)); } -static PyObject* -_open_ppm(PyObject* self, PyObject* args) -{ - char* filename; - - if (!PyArg_ParseTuple(args, "s", &filename)) - return NULL; - - return PyImagingNew(ImagingOpenPPM(filename)); -} - static PyObject* _alpha_composite(ImagingObject* self, PyObject* args) { @@ -3424,9 +3413,6 @@ static PyMethodDef functions[] = { {"crc32", (PyCFunction)_crc32, 1}, {"getcodecstatus", (PyCFunction)_getcodecstatus, 1}, - /* Debugging stuff */ - {"open_ppm", (PyCFunction)_open_ppm, 1}, - /* Special effects (experimental) */ #ifdef WITH_EFFECTS {"effect_mandelbrot", (PyCFunction)_effect_mandelbrot, 1}, diff --git a/libImaging/File.c b/libImaging/File.c index b669ab665..d67bcabde 100644 --- a/libImaging/File.c +++ b/libImaging/File.c @@ -20,116 +20,6 @@ #include -Imaging -ImagingOpenPPM(const char* infile) -{ - FILE* fp; - int i, c, v; - char* mode; - int x, y, max; - Imaging im; - - if (!infile) - return ImagingError_ValueError(NULL); - - fp = fopen(infile, "rb"); - if (!fp) - return ImagingError_IOError(); - - /* PPM magic */ - if (fgetc(fp) != 'P') - goto error; - switch (fgetc(fp)) { - case '4': /* FIXME: 1-bit images are not yet supported */ - goto error; - case '5': - mode = "L"; - break; - case '6': - mode = "RGB"; - break; - default: - goto error; - } - - i = 0; - c = fgetc(fp); - - x = y = max = 0; - - 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); - } - } - - /* 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); - } - - if (c == EOF) - goto error; - - 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; - - /* 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; - - } 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; - } - - fclose(fp); - - return im; - -error: - fclose(fp); - return ImagingError_IOError(); -} - int ImagingSaveRaw(Imaging im, FILE* fp)