Removed 'Debugging' open_ppm call that didn't check file provided parameters for sanity

This commit is contained in:
wiredfool 2016-10-03 03:09:54 -07:00
parent c0d2d2a912
commit 1a43da7a8b
6 changed files with 9 additions and 140 deletions

View File

@ -145,7 +145,8 @@ def Ghostscript(tile, size, fp, scale=1):
status = gs.wait() status = gs.wait()
if status: if status:
raise IOError("gs failed (status %d)" % status) raise IOError("gs failed (status %d)" % status)
im = Image.core.open_ppm(outfile) im = Image.open(outfile)
im.load()
finally: finally:
try: try:
os.unlink(outfile) os.unlink(outfile)
@ -154,7 +155,7 @@ def Ghostscript(tile, size, fp, scale=1):
except OSError: except OSError:
pass pass
return im return im.im.copy()
class PSFile(object): class PSFile(object):

View File

@ -168,14 +168,9 @@ class IptcImageFile(ImageFile.ImageFile):
o.close() o.close()
try: try:
try: _im = Image.open(outfile)
# fast _im.load()
self.im = Image.core.open_ppm(outfile) self.im = _im.im
except:
# slightly slower
im = Image.open(outfile)
im.load()
self.im = im.im
finally: finally:
try: try:
os.unlink(outfile) os.unlink(outfile)

View File

@ -377,7 +377,9 @@ class JpegImageFile(ImageFile.ImageFile):
raise ValueError("Invalid Filename") raise ValueError("Invalid Filename")
try: try:
self.im = Image.core.open_ppm(path) _im = Image.open(path)
_im.load()
self.im = _im.im
finally: finally:
try: try:
os.unlink(path) os.unlink(path)

View File

@ -123,11 +123,6 @@ class PpmImageFile(ImageFile.ImageFile):
self.fp.tell(), self.fp.tell(),
(rawmode, 0, 1))] (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
# #
# -------------------------------------------------------------------- # --------------------------------------------------------------------

View File

@ -686,17 +686,6 @@ _radial_gradient(PyObject* self, PyObject* args)
return PyImagingNew(ImagingFillRadialGradient(mode)); 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* static PyObject*
_alpha_composite(ImagingObject* self, PyObject* args) _alpha_composite(ImagingObject* self, PyObject* args)
{ {
@ -3424,9 +3413,6 @@ static PyMethodDef functions[] = {
{"crc32", (PyCFunction)_crc32, 1}, {"crc32", (PyCFunction)_crc32, 1},
{"getcodecstatus", (PyCFunction)_getcodecstatus, 1}, {"getcodecstatus", (PyCFunction)_getcodecstatus, 1},
/* Debugging stuff */
{"open_ppm", (PyCFunction)_open_ppm, 1},
/* Special effects (experimental) */ /* Special effects (experimental) */
#ifdef WITH_EFFECTS #ifdef WITH_EFFECTS
{"effect_mandelbrot", (PyCFunction)_effect_mandelbrot, 1}, {"effect_mandelbrot", (PyCFunction)_effect_mandelbrot, 1},

View File

@ -20,116 +20,6 @@
#include <ctype.h> #include <ctype.h>
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 int
ImagingSaveRaw(Imaging im, FILE* fp) ImagingSaveRaw(Imaging im, FILE* fp)