From 817f1b6000fdbb1b813b1d290eaeeae4965ae464 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Sat, 23 Jul 2022 22:57:23 +0200 Subject: Support colour management on Windows There is also an alternative WcsGetDefaultColorProfile() path that might be necessary on some broken versions of Microsoft Windows, which I certainly do not want to support. --- fiv-view.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/fiv-view.c b/fiv-view.c index e0e42c0..c570f35 100644 --- a/fiv-view.c +++ b/fiv-view.c @@ -30,6 +30,11 @@ #ifdef GDK_WINDOWING_QUARTZ #include #endif // GDK_WINDOWING_QUARTZ +#ifdef GDK_WINDOWING_WIN32 +#define WIN32_LEAN_AND_MEAN +#include +#include +#endif // GDK_WINDOWING_WIN32 GType fiv_view_command_get_type(void) @@ -448,6 +453,28 @@ reload_screen_cms_profile(FivView *self, GdkWindow *window) { g_clear_pointer(&self->screen_cms_profile, fiv_io_profile_free); +#ifdef GDK_WINDOWING_WIN32 + if (GDK_IS_WIN32_WINDOW(window)) { + HWND hwnd = GDK_WINDOW_HWND(window); + HDC hdc = GetDC(hwnd); + if (hdc) { + DWORD len = 0; + (void) GetICMProfile(hdc, &len, NULL); + gchar *path = g_new(gchar, len); + if (GetICMProfile(hdc, &len, path)) { + gchar *data = NULL; + gsize length = 0; + if (g_file_get_contents(path, &data, &length, NULL)) + self->screen_cms_profile = fiv_io_profile_new(data, length); + g_free(data); + } + g_free(path); + ReleaseDC(hwnd, hdc); + } + goto out; + } +#endif // GDK_WINDOWING_WIN32 + GdkDisplay *display = gdk_window_get_display(window); GdkMonitor *monitor = gdk_display_get_monitor_at_window(display, window); -- cgit v1.2.3