[gimp] libgimpwidgets: Migration from GetICMProfile() to WcsGetDefaultColorProfile()
- From: Luca Bacci <lbacci src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] libgimpwidgets: Migration from GetICMProfile() to WcsGetDefaultColorProfile()
- Date: Fri, 17 Dec 2021 21:58:04 +0000 (UTC)
commit 2d1c4475086d1618a70c9aea8ddcfec7c75340a9
Author: Yoshinori Yamakawa <citrus_juicer live jp>
Date: Fri Dec 17 21:58:03 2021 +0000
libgimpwidgets: Migration from GetICMProfile() to WcsGetDefaultColorProfile()
libgimpwidgets/Makefile.am | 4 +-
libgimpwidgets/gimpwidgetsutils.c | 97 +++++++++++++++++++++++++++++++++------
libgimpwidgets/meson.build | 2 +-
meson.build | 1 +
4 files changed, 88 insertions(+), 16 deletions(-)
---
diff --git a/libgimpwidgets/Makefile.am b/libgimpwidgets/Makefile.am
index 0a354093bf..9e34c9d34f 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
@@ -133,7 +134,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 3d7b92a1a2..654afd2ddd 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
@@ -572,26 +577,90 @@ gimp_monitor_get_color_profile (GdkMonitor *monitor)
}
#elif defined G_OS_WIN32
{
- HDC hdc = GetDC (NULL);
-
- if (hdc)
+ GdkRectangle monitor_geometry;
+ gint scale_factor;
+ 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,
+ * monitor_number(monitor) may not match the index used in
+ * EnumDisplayDevices(devicename, index, displaydevice, flags).
+ */
+ gdk_monitor_get_geometry (monitor, &monitor_geometry);
+ scale_factor = gdk_monitor_get_scale_factor (monitor);
+ point.x = monitor_geometry.x * scale_factor + offsetx;
+ point.y = monitor_geometry.y * scale_factor + 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_utf16 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_build_filename (dir, filename, NULL);
+ 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
diff --git a/libgimpwidgets/meson.build b/libgimpwidgets/meson.build
index 0627789a98..1dc45627f1 100644
--- a/libgimpwidgets/meson.build
+++ b/libgimpwidgets/meson.build
@@ -188,7 +188,7 @@ libgimpwidgets = library('gimpwidgets-'+ gimp_api_version,
libgimpwidgets_sources,
include_directories: rootInclude,
dependencies: [
- gegl, gtk3, lcms, math
+ gegl, gtk3, lcms, math, mscms
],
c_args: [ '-DG_LOG_DOMAIN="LibGimpWidgets"', '-DGIMP_WIDGETS_COMPILATION', ],
link_with: [
diff --git a/meson.build b/meson.build
index cb4bb5d8c7..b4e749f61e 100644
--- a/meson.build
+++ b/meson.build
@@ -316,6 +316,7 @@ dl = platform_windows ? no_dep : cc.find_library('dl')
rpc = platform_windows ? cc.find_library('rpcrt4') : no_dep
dbghelp = platform_windows ? cc.find_library('dbghelp') : no_dep
winsock = platform_windows ? cc.find_library('ws2_32') : no_dep
+mscms = platform_windows ? cc.find_library('mscms') : no_dep
atk_minver = '2.4.0'
atk = dependency('atk', version: '>='+atk_minver)
babl_minver = '0.1.78'
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]