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()
if imOut is 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()
return imOut
@ -361,7 +361,7 @@ class ImageCmsTransform(Image.ImagePointHandler):
if im.mode != self.output_mode:
msg = "mode mismatch"
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()
return im

View File

@ -531,23 +531,26 @@ buildProofTransform(PyObject *self, PyObject *args) {
static PyObject *
cms_transform_apply(CmsTransformObject *self, PyObject *args) {
Py_ssize_t idIn;
Py_ssize_t idOut;
PyObject *i0, *i1;
Imaging im;
Imaging imOut;
int result;
if (!PyArg_ParseTuple(args, "nn:apply", &idIn, &idOut)) {
if (!PyArg_ParseTuple(args, "OO:apply", &i0, &i1)) {
return NULL;
}
im = (Imaging)idIn;
imOut = (Imaging)idOut;
if (!PyCapsule_IsValid(i0, IMAGING_MAGIC) ||
!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));
}
/* -------------------------------------------------------------------- */