Skip to content

Conversation

@radarhere
Copy link
Member

Resolves #5990

#5990 (comment) pointed out that the second value in _MODE_CONV, extra, is the number of bands in the mode. Rather than writing those out in _MODE_CONV, this could instead be derived from ImageMode.

The user in the issue would also like the NumPy typestr from _MODE_CONV available through a public API, and suggested ImageMode. From an organisational point of view for Pillow's code, that seems like a more logical location for that information, and it would be neater, since it then means that _MODE_CONV can be removed. The NumPy typestr could then be accessed by a user through ImageMode.getmode(mode).typestr.

Copy link
Contributor

@FirefoxMetzger FirefoxMetzger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some small, perhaps opinionated, comments. Looking good from my side otherwise.

src/PIL/Image.py Outdated
Comment on lines 214 to 217
shape = (im.size[1], im.size[0])
extra = len(m.bands)
if extra != 1:
shape += (extra,)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
shape = (im.size[1], im.size[0])
extra = len(m.bands)
if extra != 1:
shape += (extra,)
shape = (im.size[1], im.size[0]) # im.size[::-1]
shape = shape if len(m.bands) == 1 else (*shape, len(m.bands))

Not sure if you find this syntax neater. Both options look viable to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does seem to be a matter of personal preference, but shape = shape looks odd to me.

I have clarified the first line slightly by changing it to (im.height, im.width).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's fair.

@hugovk hugovk merged commit e0afe93 into python-pillow:main Feb 19, 2022
@hugovk
Copy link
Member

hugovk commented Feb 19, 2022

Thanks both!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor _MODE_CONV into ImageModes

3 participants