Use PyCapsule in _imagingcms

This commit is contained in:
Aleksandr Karpinskii 2024-09-02 01:32:28 +04:00
parent 2303c063cb
commit a9798e78af
2 changed files with 14 additions and 11 deletions

View File

@ -352,7 +352,7 @@ class ImageCmsTransform(Image.ImagePointHandler):
im.load() im.load()
if imOut is None: if imOut is None:
imOut = Image.new(self.output_mode, im.size, None) imOut = Image.new(self.output_mode, im.size, None)
self.transform.apply(im.im.id, imOut.im.id) self.transform.apply(im.im.ptr, imOut.im.ptr)
imOut.info["icc_profile"] = self.output_profile.tobytes() imOut.info["icc_profile"] = self.output_profile.tobytes()
return imOut return imOut
@ -361,7 +361,7 @@ class ImageCmsTransform(Image.ImagePointHandler):
if im.mode != self.output_mode: if im.mode != self.output_mode:
msg = "mode mismatch" msg = "mode mismatch"
raise ValueError(msg) # wrong output mode raise ValueError(msg) # wrong output mode
self.transform.apply(im.im.id, im.im.id) self.transform.apply(im.im.ptr, im.im.ptr)
im.info["icc_profile"] = self.output_profile.tobytes() im.info["icc_profile"] = self.output_profile.tobytes()
return im return im

View File

@ -531,23 +531,26 @@ buildProofTransform(PyObject *self, PyObject *args) {
static PyObject * static PyObject *
cms_transform_apply(CmsTransformObject *self, PyObject *args) { cms_transform_apply(CmsTransformObject *self, PyObject *args) {
Py_ssize_t idIn; PyObject *i0, *i1;
Py_ssize_t idOut;
Imaging im; Imaging im;
Imaging imOut; Imaging imOut;
int result; if (!PyArg_ParseTuple(args, "OO:apply", &i0, &i1)) {
if (!PyArg_ParseTuple(args, "nn:apply", &idIn, &idOut)) {
return NULL; return NULL;
} }
im = (Imaging)idIn; if (!PyCapsule_IsValid(i0, IMAGING_MAGIC) ||
imOut = (Imaging)idOut; !PyCapsule_IsValid(i1, IMAGING_MAGIC)) {
PyErr_Format(
PyExc_TypeError, "Expected PyCapsule with '%s' name.", IMAGING_MAGIC
);
return NULL;
}
result = pyCMSdoTransform(im, imOut, self->transform); im = (Imaging)PyCapsule_GetPointer(i0, IMAGING_MAGIC);
imOut = (Imaging)PyCapsule_GetPointer(i1, IMAGING_MAGIC);
return Py_BuildValue("i", result); return Py_BuildValue("i", pyCMSdoTransform(im, imOut, self->transform));
} }
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */