Fredrik Lundh avatar Fredrik Lundh committed 4ab7abb

Added LittleCMS version query to ImageCms module.

Comments (0)

Files changed (4)

 import Image
 import _imagingcms
 
-cmscore = _imagingcms
+core = _imagingcms
 
 #
 # intent/direction values
         # accepts a string (filename), a file-like object, or a low-level
         # profile object
         if Image.isStringType(profile):
-            self._set(cmscore.profile_open(profile), profile)
+            self._set(core.profile_open(profile), profile)
         elif hasattr(profile, "read"):
-            self._set(cmscore.profile_fromstring(profile.read()))
+            self._set(core.profile_fromstring(profile.read()))
         else:
             self._set(profile) # assume it's already a profile
 
                  intent=INTENT_PERCEPTUAL,
                  proof=None, proof_intent=INTENT_ABSOLUTE_COLORIMETRIC, flags=0):
         if proof is None:
-            self.transform = cmscore.buildTransform(
+            self.transform = core.buildTransform(
                 input.profile, output.profile,
                 input_mode, output_mode,
                 intent,
                 flags
                 )
         else:
-            self.transform = cmscore.buildProofTransform(
+            self.transform = core.buildProofTransform(
                 input.profile, output.profile, proof.profile,
                 input_mode, output_mode,
                 intent, proof_intent,
     if sys.platform == "win32":
         import ImageWin
         if isinstance(handle, ImageWin.HDC):
-            profile = cmscore.get_display_profile_win32(handle, 1)
+            profile = core.get_display_profile_win32(handle, 1)
         else:
-            profile = cmscore.get_display_profile_win32(handle or 0)
+            profile = core.get_display_profile_win32(handle or 0)
     else:
         try:
             get = _imagingcms.get_display_profile
             raise PyCMSError("Color temperature must be a positive integer, \"%s\" not valid" % colorTemp)
 
     try:
-        return cmscore.createProfile(colorSpace, colorTemp)
+        return core.createProfile(colorSpace, colorTemp)
     except (TypeError, ValueError), v:
         raise PyCMSError(v)
 
 
 def versions():
     import sys
-    pycms, lcms = cmscore.versions()
-    return (pycms, "%d.%d" % divmod(lcms, 100),
-            sys.version.split()[0], Image.VERSION)
+    return (VERSION, core.getversion(), sys.version.split()[0], Image.VERSION)
 
 # --------------------------------------------------------------------
 

Tests/test_imagecms.py

     assert_equal(v[0], '0.1.0 pil')
     assert_equal(map(type, v), [str, str, str, str])
 
+    v = ImageCms.core.getversion() # should return a "major.minor" string
+    assert_match("\d+\.\d+$", v)
+
     i = ImageCms.profileToProfile(lena(), SRGB, SRGB)
     assert_image(i, "RGB", (128, 128))
 
     else:
         failure(msg or "got %r, expected %r" % (a, b))
 
+def assert_match(p, s, msg=None):
+    import re
+    if re.match(p, s):
+        success()
+    else:
+        failure(msg or "got %r, doesn't match pattern %r" % (s, p))
+
 def assert_exception(exc_class, func):
     import sys, traceback
     try:
 /* Python callable functions */
 
 static PyObject *
-versions (PyObject *self, PyObject *args)
+getversion(PyObject *self, PyObject *args)
 {
-  return Py_BuildValue("si", PYCMSVERSION, LCMS_VERSION);
+  return PyString_FromFormat("%d.%d", LCMS_VERSION / 100, LCMS_VERSION % 100);
 }
 
 static PyObject *
   {"profile_open", cms_profile_open, 1},
   {"profile_fromstring", cms_profile_fromstring, 1},
 
-  /* pyCMS info */
-  {"versions", versions, 1},
-
   /* profile and transform functions */
   {"buildTransform", buildTransform, 1},
   {"buildProofTransform", buildProofTransform, 1},
   {"get_display_profile_win32", cms_get_display_profile_win32, 1},
 #endif
 
+  {"getversion", getversion, 1},
+
   {NULL, NULL}
 };
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.