mm2 / Little-CMS

A free, open source, CMM engine. It provides fast transforms between ICC profiles.
https://www.littlecms.com
MIT License
549 stars 174 forks source link

Feature request: utility function to duplicate colour profiles #454

Closed DominikDeak closed 2 months ago

DominikDeak commented 2 months ago

How feasible is adding a function that is capable of deep copying colour profiles in memory? I see cmsDupContext() exists for cloning cmsContext, perhaps a similar feature could be implemented for profiles as well? For example, cmsDupProfile().

Deep copying is sometimes useful when cloning data in multi-threading environments. Currently we clone profiles by saving and loading them in memory (via cmsSaveProfileToMem and cmsOpenProfileFromMemTHR), but I'm wondering if there is a more efficient way of doing this?

mm2 commented 2 months ago

Hi, cmsSaveProfileToMem and cmsOpenProfileFromMemTHR is the way to do that and it is very efficient.

Deep copying is sometimes useful when cloning data in multi-threading environments.

Double check if you really want this. The way lcms works allows to open the profile or transform in one thread and reuse the handle on many other threads. Maybe you want to duplicate memory because you are running on different processes, but in this case is better to open the file. Note that only the required parts of the profile are loaded in memory in this case.

DominikDeak commented 2 months ago

The way lcms works allows to open the profile or transform in one thread and reuse the handle on many other threads.

Right, as long I can safely use the same profile handle concurrently across different threads, that should be good enough for our use case.

Thanks for taking the time looking into this.