Skip to content

Commit 34b1799

Browse files
committed
Use Python PPM save, instead of C
1 parent e55c000 commit 34b1799

5 files changed

Lines changed: 15 additions & 119 deletions

File tree

Tests/test_image.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,11 @@ def test_dump(self, tmp_path: Path) -> None:
270270
im = Image.new("RGB", (10, 10))
271271
im._dump(str(tmp_path / "temp_RGB.ppm"))
272272

273+
im = Image.new("RGBA", (10, 10))
274+
im._dump(str(tmp_path / "temp_RGBA.ppm"))
275+
273276
im = Image.new("HSV", (10, 10))
274-
with pytest.raises(ValueError):
277+
with pytest.raises(OSError):
275278
im._dump(str(tmp_path / "temp_HSV.ppm"))
276279

277280
def test_comparison_with_other_type(self) -> None:

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ def get_version() -> str:
9494
"Draw",
9595
"Effects",
9696
"EpsEncode",
97-
"File",
9897
"Fill",
9998
"Filter",
10099
"FliDecode",

src/PIL/Image.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -731,24 +731,17 @@ def _ensure_mutable(self) -> None:
731731
def _dump(
732732
self, file: str | None = None, format: str | None = None, **options: Any
733733
) -> str:
734-
suffix = ""
735-
if format:
736-
suffix = f".{format}"
734+
suffix = f".{format}" if format else ""
737735

738-
if not file:
739-
f, filename = tempfile.mkstemp(suffix)
740-
os.close(f)
741-
else:
736+
if file:
742737
filename = file
743738
if not filename.endswith(suffix):
744-
filename = filename + suffix
745-
746-
self.load()
747-
748-
if not format or format == "PPM":
749-
self.im.save_ppm(filename)
739+
filename += suffix
750740
else:
751-
self.save(filename, format, **options)
741+
f, filename = tempfile.mkstemp(suffix)
742+
os.close(f)
743+
744+
self.save(filename, format or "PPM", **options)
752745

753746
return filename
754747

src/_imaging.c

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
#define S16(v) ((v) < 32768 ? (v) : ((v) - 65536))
109109

110110
/* -------------------------------------------------------------------- */
111-
/* OBJECT ADMINISTRATION */
111+
/* OBJECT ADMINISTRATION */
112112
/* -------------------------------------------------------------------- */
113113

114114
typedef struct {
@@ -379,7 +379,7 @@ ImagingError_ValueError(const char *message) {
379379
}
380380

381381
/* -------------------------------------------------------------------- */
382-
/* HELPERS */
382+
/* HELPERS */
383383
/* -------------------------------------------------------------------- */
384384

385385
static int
@@ -683,7 +683,7 @@ getink(PyObject *color, Imaging im, char *ink) {
683683
}
684684

685685
/* -------------------------------------------------------------------- */
686-
/* FACTORIES */
686+
/* FACTORIES */
687687
/* -------------------------------------------------------------------- */
688688

689689
static PyObject *
@@ -3611,7 +3611,7 @@ _effect_spread(ImagingObject *self, PyObject *args) {
36113611
}
36123612

36133613
/* -------------------------------------------------------------------- */
3614-
/* UTILITIES */
3614+
/* UTILITIES */
36153615
/* -------------------------------------------------------------------- */
36163616

36173617
static PyObject *
@@ -3646,25 +3646,6 @@ _getcodecstatus(PyObject *self, PyObject *args) {
36463646
return PyUnicode_FromString(msg);
36473647
}
36483648

3649-
/* -------------------------------------------------------------------- */
3650-
/* DEBUGGING HELPERS */
3651-
/* -------------------------------------------------------------------- */
3652-
3653-
static PyObject *
3654-
_save_ppm(ImagingObject *self, PyObject *args) {
3655-
char *filename;
3656-
3657-
if (!PyArg_ParseTuple(args, "s", &filename)) {
3658-
return NULL;
3659-
}
3660-
3661-
if (!ImagingSavePPM(self->image, filename)) {
3662-
return NULL;
3663-
}
3664-
3665-
Py_RETURN_NONE;
3666-
}
3667-
36683649
/* -------------------------------------------------------------------- */
36693650

36703651
/* methods */
@@ -3748,9 +3729,6 @@ static struct PyMethodDef methods[] = {
37483729
/* Special effects */
37493730
{"effect_spread", (PyCFunction)_effect_spread, METH_VARARGS},
37503731

3751-
/* Misc. */
3752-
{"save_ppm", (PyCFunction)_save_ppm, METH_VARARGS},
3753-
37543732
/* arrow */
37553733
{"__arrow_c_schema__", (PyCFunction)ExportArrowSchemaPyCapsule, METH_VARARGS},
37563734
{"__arrow_c_array__", (PyCFunction)ExportArrowArrayPyCapsule, METH_VARARGS},

src/libImaging/File.c

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)