Commits

Fredrik Lundh committed ccd8600

Added HWND/HDC support to ImageCms.get_display_profile().

Comments (0)

Files changed (3)

 # (experimental) Fetches the profile for the current display device.
 # Returns None if the profile is not known.
 
-def get_display_profile():
-    try:
-        get = _imagingcms.get_display_profile
-    except AttributeError:
-        return None
+def get_display_profile(handle=None):
+    import sys
+    if sys.platform == "win32":
+        import ImageWin
+        if isinstance(handle, ImageWin.HDC):
+            profile = cmscore.get_display_profile_win32(handle, 1)
+        else:
+            profile = cmscore.get_display_profile_win32(handle or 0)
     else:
-        return ImageCmsProfile(get())
+        try:
+            get = _imagingcms.get_display_profile
+        except AttributeError:
+            return None
+        else:
+            profile = get()
+    return ImageCmsProfile(profile)
 
 # --------------------------------------------------------------------.
 # pyCMS compatible layer

Tests/test_imagecms.py

     im = lena().point(t)
 
     # try fetching the profile for the current display device
-    assert_no_exception(lambda: ImageCms._imagingcms.get_display_profile())
+    assert_no_exception(lambda: ImageCms.get_display_profile())
 {
   char filename[MAX_PATH];
   DWORD filename_size;
-  HWND wnd = NULL; /* FIXME: pass in as parameter */
-  HDC dc;
   BOOL ok;
 
-  dc = GetDC(wnd);
+  int handle = 0;
+  int is_dc = 0;
+  if (!PyArg_ParseTuple(args, "|ii:get_display_profile", &handle, &is_dc))
+    return NULL;
 
   filename_size = sizeof(filename);
-  ok = GetICMProfile(dc, &filename_size, filename);
 
-  ReleaseDC(wnd, dc);
+  if (is_dc) {
+    ok = GetICMProfile((HDC) handle, &filename_size, filename);
+  } else {
+    HDC dc = GetDC((HWND) handle);
+    ok = GetICMProfile(dc, &filename_size, filename);
+    ReleaseDC((HWND) handle, dc);
+  }
 
   if (ok)
     return PyString_FromStringAndSize(filename, filename_size-1);
 
   /* platform specific tools */
 #ifdef WIN32
-  {"get_display_profile", cms_get_display_profile_win32, 1},
+  {"get_display_profile_win32", cms_get_display_profile_win32, 1},
 #endif
 
   {NULL, NULL}