[gimp/gimp-2-10] libgimpwidgets: Migration from GetICMProfile() to WcsGetDefaultColorProfile()
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gimp-2-10] libgimpwidgets: Migration from GetICMProfile() to WcsGetDefaultColorProfile()
- Date: Sun, 19 Dec 2021 14:56:12 +0000 (UTC)
commit ccb94344fc0843020eb1755385682f76bcefdbb7
Author: Yoshinori Yamakawa <citrus_juicer live jp>
Date: Sun Dec 19 14:56:10 2021 +0000
libgimpwidgets: Migration from GetICMProfile() to WcsGetDefaultColorProfile()
libgimpwidgets/Makefile.am | 4 +-
libgimpwidgets/gimpwidgetsutils.c | 95 +++++++++++++++++++++++++++++++++------
2 files changed, 84 insertions(+), 15 deletions(-)
---
diff --git a/libgimpwidgets/Makefile.am b/libgimpwidgets/Makefile.am
index 9c094944ad..d5454a513a 100644
--- a/libgimpwidgets/Makefile.am
+++ b/libgimpwidgets/Makefile.am
@@ -7,6 +7,7 @@ libgimpconfig = $(top_builddir)/libgimpconfig/libgimpconfig-$(GIMP_API_VERSION).
if PLATFORM_WIN32
no_undefined = -no-undefined
libgdi32 = -lgdi32
+libmscms = -lmscms
else
libm = -lm
endif
@@ -297,7 +298,8 @@ libgimpwidgets_@GIMP_API_VERSION@_la_LIBADD = \
$(GTK_LIBS) \
$(LCMS_LIBS) \
$(libm) \
- $(libgdi32)
+ $(libgdi32) \
+ $(libmscms)
BUILT_SOURCES = \
$(libgimpwidgets_built_sources)
diff --git a/libgimpwidgets/gimpwidgetsutils.c b/libgimpwidgets/gimpwidgetsutils.c
index daa9d599a5..db4b5db007 100644
--- a/libgimpwidgets/gimpwidgetsutils.c
+++ b/libgimpwidgets/gimpwidgetsutils.c
@@ -27,7 +27,12 @@
#include <gtk/gtk.h>
#ifdef G_OS_WIN32
+#ifdef _WIN32_WINNT
+#undef _WIN32_WINNT
+#endif
+#define _WIN32_WINNT 0x0600
#include <windows.h>
+#include <icm.h>
#endif
#ifdef GDK_WINDOWING_QUARTZ
@@ -554,26 +559,88 @@ gimp_screen_get_color_profile (GdkScreen *screen,
}
#elif defined G_OS_WIN32
{
- HDC hdc = GetDC (NULL);
-
- if (hdc)
+ GdkRectangle monitor_geometry;
+ POINT point;
+ gint offsetx = GetSystemMetrics (SM_XVIRTUALSCREEN);
+ gint offsety = GetSystemMetrics (SM_YVIRTUALSCREEN);
+ HMONITOR monitor_handle;
+ MONITORINFOEX info;
+ DISPLAY_DEVICE display_device;
+
+ info.cbSize = sizeof (MONITORINFOEX);
+ display_device.cb = sizeof (DISPLAY_DEVICE);
+
+ /* If the first monitor is not set as the main monitor,
+ * the monitor variable may not match the index used in
+ * EnumDisplayDevices(devicename, index, displaydevice, flags).
+ */
+ gdk_screen_get_monitor_geometry (screen, monitor, &monitor_geometry);
+ point.x = monitor_geometry.x + offsetx;
+ point.y = monitor_geometry.y + offsety;
+ monitor_handle = MonitorFromPoint (point, MONITOR_DEFAULTTONEAREST);
+
+ if (GetMonitorInfo (monitor_handle, (LPMONITORINFO)&info))
{
- gchar *path;
- gint32 len = 0;
-
- GetICMProfile (hdc, (LPDWORD) &len, NULL);
- path = g_new (gchar, len);
-
- if (GetICMProfile (hdc, (LPDWORD) &len, path))
+ if (EnumDisplayDevices (info.szDevice, 0, &display_device, 0))
{
- GFile *file = g_file_new_for_path (path);
+ gchar *device_key = g_convert (display_device.DeviceKey, -1, "UTF-16LE",
"WINDOWS-1252", NULL, NULL, NULL);
+ gchar *filename = NULL;
+ gchar *dir = NULL;
+ gchar *fullpath = NULL;
+ GFile *file;
+ DWORD len = 0;
+ gboolean per_user;
+ WCS_PROFILE_MANAGEMENT_SCOPE scope;
+
+ WcsGetUsePerUserProfiles ((LPWSTR)device_key, CLASS_MONITOR, &per_user);
+ scope = per_user ? WCS_PROFILE_MANAGEMENT_SCOPE_CURRENT_USER :
WCS_PROFILE_MANAGEMENT_SCOPE_SYSTEM_WIDE;
+
+ if (WcsGetDefaultColorProfileSize (scope,
+ (LPWSTR)device_key,
+ CPT_ICC,
+ CPST_NONE,
+ 0,
+ &len))
+ {
+ gchar *filename_utf16 = g_new (gchar, len);
+
+ WcsGetDefaultColorProfile (scope,
+ (LPWSTR)device_key,
+ CPT_ICC,
+ CPST_NONE,
+ 0,
+ len,
+ (LPWSTR)filename_utf16);
+
+ /* _filename must be native endian */
+ filename = g_utf16_to_utf8 ((gunichar2 *)filename_utf16, -1, NULL, NULL, NULL);
+ g_free (filename_utf16);
+ }
+ else
+ {
+ /* Due to a bug in Windows, the meanings of LCS_sRGB and
+ * LCS_WINDOWS_COLOR_SPACE are swapped.
+ */
+ GetStandardColorSpaceProfile (NULL, LCS_sRGB, NULL, &len);
+ filename = g_new (gchar, len);
+ GetStandardColorSpaceProfile (NULL, LCS_sRGB, filename, &len);
+ }
+
+ GetColorDirectory (NULL, NULL, &len);
+ dir = g_new (gchar, len);
+ GetColorDirectory (NULL, dir, &len);
+
+ fullpath = g_strdup_printf ("%s\\%s", dir, filename);
+ file = g_file_new_for_path (fullpath);
profile = gimp_color_profile_new_from_file (file, NULL);
g_object_unref (file);
- }
- g_free (path);
- ReleaseDC (NULL, hdc);
+ g_free (fullpath);
+ g_free (dir);
+ g_free (filename);
+ g_free (device_key);
+ }
}
}
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]