def main(*args, **kwargs):
    # Parse arguments
    cal_only = kwargs.get("--cal-only", CAL_ONLY)
    state = None
    xy = None
    profile = None
    outfilename = None
    for i, arg in enumerate(args):
        if arg == "-t":
            state = "COLORTEMP_DAYLIGHT"
        elif arg == "-T":
            state = "COLORTEMP_BLACKBODY"
        elif arg.startswith("-t") or arg.startswith("-T") or state in (
                "COLORTEMP_DAYLIGHT", "COLORTEMP_BLACKBODY"):
            if state in ("COLORTEMP_DAYLIGHT", "COLORTEMP_BLACKBODY"):
                ctstr = arg
            else:
                ctstr = arg[2:]
            try:
                ct = float(ctstr)
            except ValueError:
                raise Invalid("Invalid color temperature %s" % ctstr)
            if arg.startswith("-t") or state == "COLORTEMP_DAYLIGHT":
                xy = cm.CIEDCCT2xyY(ct)
                if not xy:
                    raise Invalid(
                        "Daylight color temperature %i out of range" % ct)
            else:
                xy = cm.planckianCT2xyY(ct)
                if not xy:
                    raise Invalid(
                        "Blackbody color temperature %i out of range" % ct)
            state = None
        elif arg == "-w":
            state = "CHROMATICITY"
        elif arg.startswith("-w") or state == "CHROMATICITY":
            if state == "CHROMATICITY":
                xystr = arg
            else:
                xystr = arg[2:]
            xy = xystr.split(",")
            if len(xy) != 2:
                raise Invalid("Invalid chromaticity: %s" % xystr)
            try:
                xy = [float(v) for v in xy]
            except ValueError:
                raise Invalid("Invalid chromaticity %s" % xystr)
            state = None
        elif os.path.isfile(arg) and i < len(args) - 1:
            safe_print("Reading profile:", arg)
            profile = ICCP.ICCProfile(arg)
        else:
            outfilename = os.path.abspath(arg)
    if not xy or not outfilename:
        raise Invalid(
            "Usage: %s [-t temp | -T temp | -w x,y] [--cal-only] [inprofile] outfilename"
            % os.path.basename(__file__))
    if not profile:
        safe_print("Reading display profile")
        profile = ICCP.get_display_profile()
    # Setup
    config.initcfg()
    lang.init()
    w = worker.Worker()
    fn = w.change_display_profile_cal_whitepoint
    args = profile, xy[0], xy[1], outfilename, cal_only, USE_COLLINK
    # Process
    if CAL_ONLY:
        fn(*args)
    else:
        app = BaseApp(0)
        app.TopWindow = wx.Frame(None)
        w.start(lambda result: app.ExitMainLoop(),
                fn,
                wargs=args,
                progress_msg=lang.getstr("create_profile"))
        app.MainLoop()
Example #2
0
    # Tags
    print "Description:", profile.getDescription()
    print "Copyright:", profile.getCopyright()
    if "dmnd" in profile.tags:
        print "Device Manufacturer Description:",
        print profile.getDeviceManufacturerDescription()
    if "dmdd" in profile.tags:
        print "Device Model Description:", profile.getDeviceModelDescription()
    if "vued" in profile.tags:
        print "Viewing Conditions Description:",
        print profile.getViewingConditionsDescription()
    wtpt_profile_norm = tuple(n * 100 for n in profile.tags.wtpt.values())
    if "chad" in profile.tags:
        # undo chromatic adaption of profile whitepoint
        X, Y, Z = wtpt_profile_norm
        M = colormath.Matrix3x3(profile.tags.chad).inverted()
        XR = X * M[0][0] + Y * M[0][1] + Z * M[0][2]
        YR = X * M[1][0] + Y * M[1][1] + Z * M[1][2]
        ZR = X * M[2][0] + Y * M[2][1] + Z * M[2][2]
        wtpt_profile_norm = tuple((n / YR) * 100.0 for n in (XR, YR, ZR))
    if "lumi" in profile.tags and isinstance(profile.tags.lumi, ICCP.XYZType):
        print "Luminance:", profile.tags.lumi.Y
    print "Actual Whitepoint XYZ:", " ".join(str(n) for n in wtpt_profile_norm)
    print "Correlated Color Temperature:", colormath.XYZ2CCT(
        *wtpt_profile_norm)


if __name__ == "__main__":
    for arg in sys.argv[1:] or [ICCP.get_display_profile()]:
        profileinfo(arg)