aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-07-23 22:57:23 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-07-23 22:59:29 +0200
commit817f1b6000fdbb1b813b1d290eaeeae4965ae464 (patch)
tree093c242b2f39871d34badf21161d1b1bccbe0c5a
parent31f428f4ec7f2967472018ea0a8f61c34690b0ac (diff)
downloadfiv-817f1b6000fdbb1b813b1d290eaeeae4965ae464.tar.gz
fiv-817f1b6000fdbb1b813b1d290eaeeae4965ae464.tar.xz
fiv-817f1b6000fdbb1b813b1d290eaeeae4965ae464.zip
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.
-rw-r--r--fiv-view.c27
1 files changed, 27 insertions, 0 deletions
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 <gdk/gdkquartz.h>
#endif // GDK_WINDOWING_QUARTZ
+#ifdef GDK_WINDOWING_WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <gdk/gdkwin32.h>
+#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);