mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Removed 'Debugging' open_ppm call that didn't check file provided parameters for sanity
This commit is contained in:
parent
c0d2d2a912
commit
1a43da7a8b
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
#
|
||||
# --------------------------------------------------------------------
|
||||
|
|
14
_imaging.c
14
_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},
|
||||
|
|
|
@ -20,116 +20,6 @@
|
|||
|
||||
#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
|
||||
ImagingSaveRaw(Imaging im, FILE* fp)
|
||||
|
|
Loading…
Reference in New Issue
Block a user