Skip to content

Python wrapper for MSCMS color management functions - #591

Closed
Anulap wants to merge 17 commits into
eoyilmaz:developfrom
Anulap:mscms_wrapper_refactor
Closed

Python wrapper for MSCMS color management functions#591
Anulap wants to merge 17 commits into
eoyilmaz:developfrom
Anulap:mscms_wrapper_refactor

Conversation

@Anulap

@Anulap Anulap commented Aug 1, 2025

Copy link
Copy Markdown

Description

This PR introduces a Python wrapper for selected MSCMS (Microsoft Color Management System) functions. The implementation includes:

  • A low-level ctypes binding (mscms_wrapper.py) for core MSCMS functions. If desired it can be used on it's own with a caveat that it leaks like a seive (see motication)
  • A high-level wrapper (mscms.py) with simplified APIs and process based isolation for actual API calls

Motivation

DisplayCAL uses rather non conventional way to interact with WCS: a hybrid solution using both registry and API calls (plus a couple of kludges to try and counteract handle leak). Unfortunately, it is a rather fragile solution and the list of color profiles retrieved from registry does not necessarily coinside with internal windows tools

Architecture

WCSManager is a Singleton with lazy initialization, which provides a threadsafe interface (MPSC) to an instance of the WCS class (which runs in a separate process). Once the process containing the WCS instance passes a certain number of open handles, it is killed and restarted in a safe and consistent manner. Any logs or exceptions created in a separate process are transparently returned to the main process

Changes

  • moves all the low level interactions and error handling to a separate class
  • simplifies use
  • provides proper typing support
  • isolates leaking calls to WinAPI

Dependencies

  • typing_extensions
  • psutil is mandatory

Known issues

WIP

  • initial implementation
  • review passed
  • bug fixes
  • tests implemented
  • legacy python version support ensured
  • less verbose default log level

References

Anulap added 9 commits July 25, 2025 22:03
Fix for unfortunate file naming error.
WCSManager: improve exception handling from worker process: all builtins now supported
WCSManager: retries on shutdown also, cause it might be a reboot
WCSManager: various bug fixes and corner case handling
…oader.py)

Add better handling of WcsDisassociateColorProfileFromDevice API quirks in WCS class
Update documentation
@Adam-Color

Copy link
Copy Markdown

Thanks for this! You may want to cross-check the files you're changing with #552, @eoyilmaz isn't merging anything until that's done.

@Anulap

Anulap commented Aug 18, 2025

Copy link
Copy Markdown
Author

Thanks for this! You may want to cross-check the files you're changing with #552, @eoyilmaz isn't merging anything until that's done.

While it won't take much to rebase this unto refactored code, I'll see if there are relevant changes.

@eoyilmaz

eoyilmaz commented Sep 3, 2025

Copy link
Copy Markdown
Owner

@Anulap can you fix your code so the tests are passing please

@Anulap

Anulap commented Sep 3, 2025

Copy link
Copy Markdown
Author

@eoyilmaz well, there is a reason this is a draft. But yes, I'll get to it eventually. Maybe this weekend or the next one. It just requires a better separation between platforms and some tests of it's own.

@eoyilmaz

eoyilmaz commented Sep 3, 2025

Copy link
Copy Markdown
Owner

well, there is a reason this is a draft

aah sorry I didn't see that 👍

@Anulap

Anulap commented Nov 25, 2025

Copy link
Copy Markdown
Author

I have been rather busy with my new day job. But I'll continue work on this one. Windows tests are still broken. After that I might add a couple of test of my own and that will probably be it (minus bug fixes).

Update:
Tricky-tricky. Tests didn't like spawning additional thread and process.

@Anulap
Anulap force-pushed the mscms_wrapper_refactor branch from e092ab4 to e016402 Compare November 27, 2025 16:51
@Anulap

Anulap commented Nov 29, 2025

Copy link
Copy Markdown
Author

I somewhat doubt that I managed to break argyll tests now.

@Anulap
Anulap marked this pull request as ready for review January 5, 2026 16:54
@Anulap

Anulap commented Jan 5, 2026

Copy link
Copy Markdown
Author

Download error seem to be server and resource related, so I don't think that is my fault

jaminmc added a commit to jaminmc/displaycal-py3 that referenced this pull request Feb 25, 2026
Port the PR eoyilmaz#591 MSCMS manager/wrapper and tests into the eoyilmaz#552 branch while preserving current cross-platform behavior and dependency set. Fix retry semantics, WCS API signature/size handling, and English test docstrings for safer Windows profile management integration.

Co-authored-by: Anulap <perpetuallybored@yandex.ru>
eoyilmaz added a commit that referenced this pull request Feb 27, 2026
[#552] Integrate MSCMS PR #591 with Windows Python 3.13+ build compatibility fixes
@eoyilmaz

Copy link
Copy Markdown
Owner

Hi @Anulap, thanks for this PR, what you guys put is a herculian effort 👏 ... @jaminmc has ported this over the 552-big-refactoring branch and I just merged it. So closing this one... Thank you 🙏

@eoyilmaz eoyilmaz closed this Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants