Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed unused profile_fromstring method #6987

Merged
merged 1 commit into from
Mar 4, 2023

Conversation

radarhere
Copy link
Member

While ImageCms calls profile_frombytes,

Pillow/src/PIL/ImageCms.py

Lines 187 to 191 in 1457d2c

self._set(core.profile_frombytes(f.read()))
return
self._set(core.profile_open(profile), profile)
elif hasattr(profile, "read"):
self._set(core.profile_frombytes(profile.read()))

profile_fromstring is unused.

profile_fromstring actually calls the same code as profile_frombytes.

Pillow/src/_imagingcms.c

Lines 963 to 964 in 1457d2c

{"profile_frombytes", cms_profile_fromstring, METH_VARARGS},
{"profile_fromstring", cms_profile_fromstring, METH_VARARGS},

So this PR removes the profile_fromstring method declaration, and renames the C method to cms_profile_frombytes for clarity.

@hugovk hugovk merged commit 1da6ff3 into python-pillow:main Mar 4, 2023
@hugovk hugovk added the Cleanup label Mar 4, 2023
@radarhere radarhere deleted the unused branch March 4, 2023 11:07
@etienned
Copy link
Contributor

I just want to let you know that this change broke my code (written a long time ago) because I was using the profile_fromstring (maybe this is considered a private method?) to create a profile from the 'icc_profile' info of the image. I understand that using the profile_frombytes is the right thing to do, because the 'icc_profile' is already in bytes, no problem there, but I would like to know if this method is considered private and, if it's the case, what's the proper way to create a profile from the 'icc_profile' info? If the method is not considered private, maybe you should have put a deprecation before removing it. Thanks

@hugovk
Copy link
Member

hugovk commented Apr 21, 2023

Sorry about that, how were you calling it?

Pillow's C API is internal and private, and can and will change between versions without deprecation warnings.

@etienned
Copy link
Contributor

etienned commented Apr 21, 2023

Thanks for the fast reply! As it's private, no need to be sorry, this is just normal.

I was calling it like this:

profile_data = img.info.get('icc_profile')
if profile_data:
    profile = ImageCms.core.profile_fromstring(profile_data)

I'm still calling profile_frombytes the same way. Is there a way to get a profile from the image info 'icc_profile' without using private methods? After reflexion, I should probably do this:

profile_data = img.info.get('icc_profile')
if profile_data:
    profile_file = io.BytesIO(profile_data)
    profile = ImageCms.getOpenProfile(profile_file)

@radarhere
Copy link
Member Author

After reflexion, I should probably do this:

profile_data = img.info.get('icc_profile')
if profile_data:
    profile_file = io.BytesIO(profile_data)
    profile = ImageCms.getOpenProfile(profile_file)

Sounds like a plan to me. Although for the record, to better match your first code block, you'd want to do ImageCms.getOpenProfile(profile_file).profile.

@etienned
Copy link
Contributor

Thanks for the info, but as I'm using profile with ImageCms.getProfileName and ImageCms.profileToProfile, I think it's better that I keep it as a ImageCmsProfile instance.

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.

3 participants