Esempio n. 1
0
def get_icc_info():
    ENV_ICC_DATA = os.environ.get("XPRA_ICC_DATA")
    if ENV_ICC_DATA:
        import binascii
        return {
            "source": "environment-override",
            "data": binascii.unhexlify(ENV_ICC_DATA),
        }
    from xpra.os_util import get_util_logger, bytestostr
    log = get_util_logger()
    info = {}
    try:
        from PIL import ImageCms
        from PIL.ImageCms import get_display_profile, getDefaultIntent
        INTENT_STR = {}
        for x in ("PERCEPTUAL", "RELATIVE_COLORIMETRIC", "SATURATION",
                  "ABSOLUTE_COLORIMETRIC"):
            v = getattr(ImageCms, "INTENT_%s" % x, None)
            if v:
                INTENT_STR[v] = x.lower().replace("_", "-")
        log("get_icc_info() intents=%s", INTENT_STR)

        def getDefaultIntentStr(_p):
            return INTENT_STR.get(getDefaultIntent(_p), "unknown")

        def getData(_p):
            return _p.tobytes()

        p = get_display_profile()
        log("get_icc_info() display_profile=%s", p)
        if p:
            for (k, fn) in {
                    "name": "getProfileName",
                    "info": "getProfileInfo",
                    "copyright": "getProfileCopyright",
                    "manufacturer": "getProfileManufacturer",
                    "model": "getProfileModel",
                    "description": "getProfileDescription",
                    "default-intent": "getDefaultIntentStr",
                    "data": "getData",
            }.items():
                m = getattr(ImageCms, fn, None)
                if not m:
                    log("%s lacks %s", ImageCms, fn)
                    continue
                try:
                    v = m(p)
                    info[k] = bytestostr(v).rstrip("\n\r")
                except Exception as e:
                    log("ICC profile error on %s using %s: %s", k, fn, e)
    except Exception as e:
        log("get_icc_info()", exc_info=True)
        log.warn("Warning: cannot query ICC profiles:")
        log.warn(" %s", e)
    return info
Esempio n. 2
0
def get_icc_info():
    from xpra.log import Logger

    log = Logger("platform")
    info = {}
    try:
        from PIL.ImageCms import (
            get_display_profile,
            getProfileName,
            getProfileInfo,
            getProfileCopyright,
            getProfileManufacturer,
            getProfileModel,
            getProfileDescription,
            getDefaultIntent,
            INTENT_PERCEPTUAL,
            INTENT_RELATIVE_COLORIMETRIC,
            INTENT_SATURATION,
            INTENT_ABSOLUTE_COLORIMETRIC,
        )

        INTENT_STR = {
            INTENT_PERCEPTUAL: "perceptual",
            INTENT_RELATIVE_COLORIMETRIC: "relative-colorimetric",
            INTENT_SATURATION: "saturation",
            INTENT_ABSOLUTE_COLORIMETRIC: "absolute-colorimetric",
        }

        def getDefaultIntentStr(_p):
            return INTENT_STR.get(getDefaultIntent(_p), "unknown")

        def getData(_p):
            return _p.tobytes()

        p = get_display_profile()
        if p:
            for (k, fn) in {
                "name": getProfileName,
                "info": getProfileInfo,
                "copyright": getProfileCopyright,
                "manufacturer": getProfileManufacturer,
                "model": getProfileModel,
                "description": getProfileDescription,
                "default-intent": getDefaultIntentStr,
                "data": getData,
            }.items():
                try:
                    v = fn(p)
                    info[k] = v
                except Exception as e:
                    log("ICC profile error on %s using %s: %s", k, fn, e)
    except Exception as e:
        log.warn("Warning: cannot query ICC profiles:")
        log.warn(" %s", e)
    return info
Esempio n. 3
0
 def getMonitorProfile(cls, qscreen=None):
     """
     Try to retrieve the default color profile
     associated to the monitor specified by QScreen
     (the system main display if qscreen is None).
     The method returns None if no profile can be found.
     @param qscreen: QScreen instance
     @type qscreen: QScreen
     @return: monitor profile
     @rtype: CmsProfile
     """
     try:
         if qscreen is not None and sys.platform == 'win32':
             dc = win32gui.CreateDC(qscreen.name(), None, None)
             monitorProfile = get_display_profile(
                 dc)  # cf. imageCms.get_display_profile_win32 v5.1.0 patch
         else:
             monitorProfile = get_display_profile()
     except (RuntimeError, OSError):
         monitorProfile = None
     return monitorProfile
Esempio n. 4
0
def get_icc_info():
    from xpra.log import Logger
    log = Logger("platform")
    ENV_ICC_DATA = os.environ.get("XPRA_ICC_DATA")
    if ENV_ICC_DATA:
        import binascii
        return {
                "source"    : "environment-override",
                "data"      : binascii.unhexlify(ENV_ICC_DATA),
                }
    info = {}
    try:
        from PIL import ImageCms
        from PIL.ImageCms import get_display_profile, getDefaultIntent
        INTENT_STR = {}
        for x in ("PERCEPTUAL", "RELATIVE_COLORIMETRIC", "SATURATION", "ABSOLUTE_COLORIMETRIC"):
            v = getattr(ImageCms, "INTENT_%s" % x, None)
            if v:
                INTENT_STR[v] = x.lower().replace("_", "-")
        log("get_icc_info() intents=%s", INTENT_STR)
        def getDefaultIntentStr(_p):
            return INTENT_STR.get(getDefaultIntent(_p), "unknown")
        def getData(_p):
            return _p.tobytes()
        p = get_display_profile()
        log("get_icc_info() display_profile=%s", p)
        if p:
            for (k, fn) in {
                            "name"          : "getProfileName",
                            "info"          : "getProfileInfo",
                            "copyright"     : "getProfileCopyright",
                            "manufacturer"  : "getProfileManufacturer",
                            "model"         : "getProfileModel",
                            "description"   : "getProfileDescription",
                            "default-intent": "getDefaultIntentStr",
                            "data"          : "getData",
                            }.items():
                m = getattr(ImageCms, fn, None)
                if not m:
                    log("%s lacks %s", ImageCms, fn)
                    continue
                try:
                    v = m(p)
                    info[k] = v
                except Exception as e:
                    log("ICC profile error on %s using %s: %s", k, fn, e)
    except Exception as e:
        log("get_icc_info()", exc_info=True)
        log.warn("Warning: cannot query ICC profiles:")
        log.warn(" %s", e)
    return info
Esempio n. 5
0
File: gui.py Progetto: chewi/xpra
def get_pillow_icc_info():
    screenlog = Logger("screen")
    info = {}
    try:
        from PIL import ImageCms
        from PIL.ImageCms import get_display_profile
        INTENT_STR = {}
        for x in ("PERCEPTUAL", "RELATIVE_COLORIMETRIC", "SATURATION", "ABSOLUTE_COLORIMETRIC"):
            intent = getattr(ImageCms, "Intent", None)
            if intent:
                v = getattr(intent, x, None)
            else:
                v = getattr(ImageCms, "INTENT_%s" % x, None)
            if v:
                INTENT_STR[v] = x.lower().replace("_", "-")
        screenlog("get_icc_info() intents=%s", INTENT_STR)
        p = get_display_profile()
        screenlog("get_icc_info() display_profile=%s", p)
        if p:
            def getDefaultIntentStr(v):
                return INTENT_STR.get(v, "unknown")
            def getData(v):
                return v.tobytes()
            for (k, fn, conv) in (
                ("name",            "getProfileName",           None),
                ("info",            "getProfileInfo",           None),
                ("copyright",       "getProfileCopyright",      None),
                ("manufacturer",    "getProfileManufacturer",   None),
                ("model",           "getProfileModel",          None),
                ("description",     "getProfileDescription",    None),
                ("default-intent",  "getDefaultIntent",         getDefaultIntentStr),
                ("data",            "getData",                  getData),
                ):
                m = getattr(ImageCms, fn, None)
                if m is None:
                    screenlog("%s lacks %s", ImageCms, fn)
                    continue
                try:
                    v = m(p)
                    if conv:
                        v = conv(v)
                    info[k] = bytestostr(v).rstrip("\n\r")
                except Exception as e:
                    screenlog("get_icc_info()", exc_info=True)
                    screenlog("ICC profile error on %s using %s: %s", k, fn, e)
    except Exception as e:
        screenlog("get_icc_info()", exc_info=True)
        screenlog.warn("Warning: cannot query ICC profiles:")
        screenlog.warn(" %s", e)
    return info
Esempio n. 6
0
def get_icc_info():
    from xpra.log import Logger
    log = Logger("platform")
    info = {}
    try:
        from PIL import ImageCms
        from PIL.ImageCms import get_display_profile, getDefaultIntent
        INTENT_STR = {}
        for x in ("PERCEPTUAL", "RELATIVE_COLORIMETRIC", "SATURATION",
                  "ABSOLUTE_COLORIMETRIC"):
            v = getattr(ImageCms, "INTENT_%s" % x, None)
            if v:
                INTENT_STR[v] = x.lower().replace("_", "-")
        log("get_icc_info() intents=%s", INTENT_STR)

        def getDefaultIntentStr(_p):
            return INTENT_STR.get(getDefaultIntent(_p), "unknown")

        def getData(_p):
            return _p.tobytes()

        p = get_display_profile()
        log("get_icc_info() display_profile=%s", p)
        if p:
            for (k, fn) in {
                    "name": "getProfileName",
                    "info": "getProfileInfo",
                    "copyright": "getProfileCopyright",
                    "manufacturer": "getProfileManufacturer",
                    "model": "getProfileModel",
                    "description": "getProfileDescription",
                    "default-intent": "getDefaultIntentStr",
                    "data": "getData",
            }.items():
                m = getattr(ImageCms, fn, None)
                if not m:
                    log("%s lacks %s", ImageCms, fn)
                    continue
                try:
                    v = m(p)
                    info[k] = v
                except Exception as e:
                    log("ICC profile error on %s using %s: %s", k, fn, e)
    except Exception as e:
        log("get_icc_info()", exc_info=True)
        log.warn("Warning: cannot query ICC profiles:")
        log.warn(" %s", e)
    return info
Esempio n. 7
0
def get_icc_info():
    from xpra.log import Logger
    log = Logger("platform")
    info = {}
    try:
        from PIL.ImageCms import get_display_profile, \
            getProfileName, getProfileInfo, getProfileCopyright, getProfileManufacturer, getProfileModel, getProfileDescription, getDefaultIntent, \
            INTENT_PERCEPTUAL, INTENT_RELATIVE_COLORIMETRIC, INTENT_SATURATION, INTENT_ABSOLUTE_COLORIMETRIC
        INTENT_STR = {
            INTENT_PERCEPTUAL: "perceptual",
            INTENT_RELATIVE_COLORIMETRIC: "relative-colorimetric",
            INTENT_SATURATION: "saturation",
            INTENT_ABSOLUTE_COLORIMETRIC: "absolute-colorimetric",
        }

        def getDefaultIntentStr(_p):
            return INTENT_STR.get(getDefaultIntent(_p), "unknown")

        def getData(_p):
            return _p.tobytes()

        p = get_display_profile()
        if p:
            for (k, fn) in {
                    "name": getProfileName,
                    "info": getProfileInfo,
                    "copyright": getProfileCopyright,
                    "manufacturer": getProfileManufacturer,
                    "model": getProfileModel,
                    "description": getProfileDescription,
                    "default-intent": getDefaultIntentStr,
                    "data": getData,
            }.items():
                try:
                    v = fn(p)
                    info[k] = v
                except Exception as e:
                    log("ICC profile error on %s using %s: %s", k, fn, e)
    except Exception as e:
        log.warn("Warning: cannot query ICC profiles:")
        log.warn(" %s", e)
    return info