Skip to content

Commit

Permalink
Merge pull request #7931 from Yay295/imagingcms_modes
Browse files Browse the repository at this point in the history
Remove unused CMS properties and fix documentation
  • Loading branch information
hugovk committed Apr 6, 2024
2 parents ff64ade + 7eee479 commit f8ec9f7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 39 deletions.
16 changes: 8 additions & 8 deletions src/PIL/ImageCms.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,12 +704,12 @@ def applyTransform(
"""
(pyCMS) Applies a transform to a given image.
If ``im.mode != transform.inMode``, a :exc:`PyCMSError` is raised.
If ``im.mode != transform.input_mode``, a :exc:`PyCMSError` is raised.
If ``inPlace`` is ``True`` and ``transform.inMode != transform.outMode``, a
If ``inPlace`` is ``True`` and ``transform.input_mode != transform.output_mode``, a
:exc:`PyCMSError` is raised.
If ``im.mode``, ``transform.inMode`` or ``transform.outMode`` is not
If ``im.mode``, ``transform.input_mode`` or ``transform.output_mode`` is not
supported by pyCMSdll or the profiles you used for the transform, a
:exc:`PyCMSError` is raised.
Expand All @@ -723,13 +723,13 @@ def applyTransform(
If you want to modify im in-place instead of receiving a new image as
the return value, set ``inPlace`` to ``True``. This can only be done if
``transform.inMode`` and ``transform.outMode`` are the same, because we can't
change the mode in-place (the buffer sizes for some modes are
``transform.input_mode`` and ``transform.output_mode`` are the same, because we
can't change the mode in-place (the buffer sizes for some modes are
different). The default behavior is to return a new :py:class:`~PIL.Image.Image`
object of the same dimensions in mode ``transform.outMode``.
object of the same dimensions in mode ``transform.output_mode``.
:param im: An :py:class:`~PIL.Image.Image` object, and im.mode must be the same
as the ``inMode`` supported by the transform.
:param im: An :py:class:`~PIL.Image.Image` object, and ``im.mode`` must be the same
as the ``input_mode`` supported by the transform.
:param transform: A valid CmsTransform class object
:param inPlace: Bool. If ``True``, ``im`` is modified in place and ``None`` is
returned, if ``False``, a new :py:class:`~PIL.Image.Image` object with the
Expand Down
4 changes: 0 additions & 4 deletions src/PIL/_imagingcms.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ class CmsProfile:
def is_intent_supported(self, intent: int, direction: int, /) -> int: ...

class CmsTransform:
@property
def inputMode(self) -> str: ...
@property
def outputMode(self) -> str: ...
def apply(self, id_in: int, id_out: int) -> int: ...

def profile_open(profile: str, /) -> CmsProfile: ...
Expand Down
34 changes: 7 additions & 27 deletions src/_imagingcms.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,15 @@ cms_profile_dealloc(CmsProfileObject *self) {
/* a transform represents the mapping between two profiles */

typedef struct {
PyObject_HEAD char mode_in[8];
char mode_out[8];
cmsHTRANSFORM transform;
PyObject_HEAD cmsHTRANSFORM transform;
} CmsTransformObject;

static PyTypeObject CmsTransform_Type;

#define CmsTransform_Check(op) (Py_TYPE(op) == &CmsTransform_Type)

static PyObject *
cms_transform_new(cmsHTRANSFORM transform, char *mode_in, char *mode_out) {
cms_transform_new(cmsHTRANSFORM transform) {
CmsTransformObject *self;

self = PyObject_New(CmsTransformObject, &CmsTransform_Type);
Expand All @@ -201,9 +199,6 @@ cms_transform_new(cmsHTRANSFORM transform, char *mode_in, char *mode_out) {

self->transform = transform;

strncpy(self->mode_in, mode_in, 8);
strncpy(self->mode_out, mode_out, 8);

return (PyObject *)self;
}

Expand Down Expand Up @@ -395,7 +390,7 @@ _buildTransform(

Py_END_ALLOW_THREADS

if (!hTransform) {
if (!hTransform) {
PyErr_SetString(PyExc_ValueError, "cannot build transform");
}

Expand Down Expand Up @@ -429,7 +424,7 @@ _buildProofTransform(

Py_END_ALLOW_THREADS

if (!hTransform) {
if (!hTransform) {
PyErr_SetString(PyExc_ValueError, "cannot build proof transform");
}

Expand Down Expand Up @@ -476,7 +471,7 @@ buildTransform(PyObject *self, PyObject *args) {
return NULL;
}

return cms_transform_new(transform, sInMode, sOutMode);
return cms_transform_new(transform);
}

static PyObject *
Expand Down Expand Up @@ -523,7 +518,7 @@ buildProofTransform(PyObject *self, PyObject *args) {
return NULL;
}

return cms_transform_new(transform, sInMode, sOutMode);
return cms_transform_new(transform);
}

static PyObject *
Expand Down Expand Up @@ -1456,21 +1451,6 @@ static struct PyMethodDef cms_transform_methods[] = {
{"apply", (PyCFunction)cms_transform_apply, 1}, {NULL, NULL} /* sentinel */
};

static PyObject *
cms_transform_getattr_inputMode(CmsTransformObject *self, void *closure) {
return PyUnicode_FromString(self->mode_in);
}

static PyObject *
cms_transform_getattr_outputMode(CmsTransformObject *self, void *closure) {
return PyUnicode_FromString(self->mode_out);
}

static struct PyGetSetDef cms_transform_getsetters[] = {
{"inputMode", (getter)cms_transform_getattr_inputMode},
{"outputMode", (getter)cms_transform_getattr_outputMode},
{NULL}};

static PyTypeObject CmsTransform_Type = {
PyVarObject_HEAD_INIT(NULL, 0) "PIL.ImageCms.core.CmsTransform", /*tp_name*/
sizeof(CmsTransformObject), /*tp_basicsize*/
Expand Down Expand Up @@ -1501,7 +1481,7 @@ static PyTypeObject CmsTransform_Type = {
0, /*tp_iternext*/
cms_transform_methods, /*tp_methods*/
0, /*tp_members*/
cms_transform_getsetters, /*tp_getset*/
0, /*tp_getset*/
};

static int
Expand Down

0 comments on commit f8ec9f7

Please sign in to comment.