Skip to content

Commit b2ee9dc

Browse files
authored
Fix color management issue on windows (#20054)
* Fix color management issue on windows * win32 dt_colorspaces_set_display_profile style and log
1 parent 6690177 commit b2ee9dc

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/common/colorspaces.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of darktable,
3-
Copyright (C) 2010-2025 darktable developers.
3+
Copyright (C) 2010-2026 darktable developers.
44
55
darktable is free software: you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -37,6 +37,11 @@
3737
#include "colord-gtk.h"
3838
#endif
3939

40+
#ifdef _WIN32
41+
#include <dwmapi.h>
42+
#include <gdk/gdkwin32.h>
43+
#endif
44+
4045
#if 0
4146
#include <ApplicationServices/ApplicationServices.h>
4247
#include <Carbon/Carbon.h>
@@ -2009,7 +2014,25 @@ void dt_colorspaces_set_display_profile
20092014
profile_source = g_strdup("osx color profile api");
20102015
#endif
20112016
#elif defined G_OS_WIN32
2012-
HDC hdc = GetDC(NULL);
2017+
GtkWidget *widget = (profile_type == DT_COLORSPACE_DISPLAY2)
2018+
? darktable.develop->second_wnd
2019+
: dt_ui_center(darktable.gui->ui);
2020+
GdkWindow *window = gtk_widget_get_window(widget);
2021+
HWND hwnd = (HWND)gdk_win32_window_get_handle(window); // get window handle
2022+
HMONITOR hMonitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); // get monitor handle
2023+
if(!hMonitor)
2024+
{
2025+
dt_print(DT_DEBUG_ALWAYS, "[win32 dt_colorspaces_set_display_profile] error getting monitor handle");
2026+
return;
2027+
}
2028+
MONITORINFOEX monitorInfo;
2029+
monitorInfo.cbSize = sizeof(MONITORINFOEX);
2030+
if(!GetMonitorInfoW(hMonitor, (LPMONITORINFO) &monitorInfo)) //get monitor info
2031+
{
2032+
dt_print(DT_DEBUG_ALWAYS, "[win32 dt_colorspaces_set_display_profile] error getting monitor info");
2033+
return;
2034+
}
2035+
HDC hdc = CreateIC(L"MONITOR", monitorInfo.szDevice, NULL, NULL); // get device-info context of the monitor
20132036
if(hdc != NULL)
20142037
{
20152038
DWORD len = 0;
@@ -2028,7 +2051,7 @@ void dt_colorspaces_set_display_profile
20282051
}
20292052
}
20302053
g_free(wpath);
2031-
ReleaseDC(NULL, hdc);
2054+
DeleteDC(hdc);
20322055
}
20332056
profile_source = g_strdup("windows color profile api");
20342057
#endif

0 commit comments

Comments
 (0)