diff options
-rw-r--r-- | TODO | 5 | ||||
-rw-r--r-- | examples/comprehensive | 44 | ||||
-rw-r--r-- | examples/sleepmode | 8 | ||||
-rw-r--r-- | src/blueshift_randr.pyx | 3 | ||||
-rw-r--r-- | src/blueshift_randr_c.c | 11 | ||||
-rw-r--r-- | src/blueshift_vidmode.pyx | 3 | ||||
-rw-r--r-- | src/blueshift_vidmode_c.c | 11 | ||||
-rw-r--r-- | src/monitor.py | 14 |
8 files changed, 67 insertions, 32 deletions
@@ -1,11 +1,8 @@ -High priority: - Test: randr_get and vidmode_get - Add to example: randr_get and vidmode_get - Medium priority: Small examples -r support in the comperhensive example Store settings so that we can transition from them instead of from clean + Verify command line option correctness Low priority: Fix errors caused by SIGUSR2 diff --git a/examples/comprehensive b/examples/comprehensive index 48951ea..8b55ed5 100644 --- a/examples/comprehensive +++ b/examples/comprehensive @@ -4,7 +4,9 @@ # curve modifiers: nothing else than CIE 1964 10 degree CMF for # colour temperature, not use of temporarly linear RGB curves, # negative image, inverted image, sigmoid correction, or free -# function modifier. +# function modifier. Neither does it support multiple screens, +# this is normally not an issue because Xinerama is normally used +# to put all monitors on the same screen. # Geographical coodinates. @@ -123,6 +125,28 @@ icc_video_filter_profile = [None] icc_calibration_profile = [None] +# Function for getting the current the current monitor calibration. +# If `None` the the current monitor calibration will be ignored. +# `if not panicgate:` is included to ignore monitor calibration if +# -p (--panicgate) is used. +current_calibration = [None] +if not panicgate: + #calib_get = None + calib_get = randr_get + #calib_get = vidmode_get + current_calibration = [calib_get] + + +# Loads the current monitor calibrations. +m = 0 +for i in range(len(current_calibration)): + f = current_calibration[i] + if f is not None: + if len(monitors) == 0: + m = monitors[i % len(monitors)] + current_calibration[i] = f(m) + + monitor_controller = lambda : randr(*monitors) ''' :()→void Function used by Blueshift on exit to apply reset colour curves, if using preimplemented `reset` @@ -177,7 +201,7 @@ def periodically(year, month, day, hour, minute, second, weekday, fade): interpol = lambda _day, _night : _day[m % len(_day)] * dayness + _night[m % len(_night)] * (1 - dayness) purify = lambda current, pure : current * alpha + pure * (1 - alpha) - for m in [0] if len(monitors) == 0 else monitors: + for m in range(max(1, len(monitors))): temperature_ = interpol(temperature_day, temperature_night) brightness_ = interpol(brightness_day, brightness_night) brightness_red_ = interpol(brightness_red_day, brightness_red_night) @@ -224,6 +248,11 @@ def periodically(year, month, day, hour, minute, second, weekday, fade): # Apply colour temperature using raw CIE 1964 10 degree CMF data with interpolation. temperature(temperature_, lambda t : divide_by_maximum(cmf_10deg(t))) + # Apply calibration used when started. + c = current_calibration[m % len(current_calibration)] + if c is not None: + c() + # Apply colour brightness using the CIE xyY colour space. cie_brightness(brightness_) # Apply colour brightness using the sRGB colour space. @@ -253,7 +282,7 @@ def periodically(year, month, day, hour, minute, second, weekday, fade): if len(monitors) == 0: randr() else: - randr(m) + randr(monitors[m % len(monitors)]) # Lets wait only 5 seconds, instead of a minute before running again. wait_period = 10 @@ -263,7 +292,7 @@ def reset(): ''' Invoked to reset the displays ''' - for m in [0] if len(monitors) == 0 else monitors: + for m in range(max(1, len(monitors))): gamma_red_ = gamma_red_default [m % len(gamma_red_default)] gamma_green_ = gamma_green_default[m % len(gamma_green_default)] gamma_blue_ = gamma_blue_default [m % len(gamma_blue_default)] @@ -271,6 +300,11 @@ def reset(): # Remove settings from last run. start_over() + # Apply calibration used when started. + c = current_calibration[m % len(current_calibration)] + if c is not None: + c() + # Apply gamma correction to monitor. gamma(gamma_red_, gamma_green_, gamma_blue_) @@ -285,7 +319,7 @@ def reset(): if len(monitors) == 0: randr() else: - randr(m) + randr(monitors[m % len(monitors)]) if get_dayness is not None: diff --git a/examples/sleepmode b/examples/sleepmode index 44695a3..a5b3023 100644 --- a/examples/sleepmode +++ b/examples/sleepmode @@ -79,7 +79,7 @@ def periodically(year, month, day, hour, minute, second, weekday, fade): (**) See https://en.wikipedia.org/wiki/Leap_second ''' purity = 0 if fade is None else 1 - abs(fade) - for m in [0] if len(monitors) == 0 else monitors: + for m in max(1, len(monitors)): # Remove settings from last run. start_over() @@ -103,14 +103,14 @@ def periodically(year, month, day, hour, minute, second, weekday, fade): if len(monitors) == 0: randr() else: - randr(m) + randr(monitors[m % len(monitors)]) def reset(): ''' Invoked to reset the displays ''' - for m in [0] if len(monitors) == 0 else monitors: + for m in max(1, len(monitors)): # Remove settings from last run. start_over() @@ -124,5 +124,5 @@ def reset(): if len(monitors) == 0: randr() else: - randr(m) + randr(monitors[m % len(monitors)]) diff --git a/src/blueshift_randr.pyx b/src/blueshift_randr.pyx index 76a6f86..294910a 100644 --- a/src/blueshift_randr.pyx +++ b/src/blueshift_randr.pyx @@ -54,9 +54,8 @@ def randr_read(int use_crtc): s = got[i] i += 1 for j in range(s): - c.append(s[i + j]) + c.append(got[i + j]) i += s - free(got) return (r, g, b) diff --git a/src/blueshift_randr_c.c b/src/blueshift_randr_c.c index 856d4f0..d7be886 100644 --- a/src/blueshift_randr_c.c +++ b/src/blueshift_randr_c.c @@ -243,7 +243,7 @@ uint16_t* blueshift_randr_read(int use_crtc) G_gamma = xcb_randr_get_crtc_gamma_green(gamma_get_reply); B_gamma = xcb_randr_get_crtc_gamma_blue(gamma_get_reply); - r_gamma = ((uint16_t*)malloc((3 + R_size + G_size + B_size) * sizeof(uint16_t))) + 1; + r_gamma = malloc((3 + R_size + G_size + B_size) * sizeof(uint16_t)); g_gamma = r_gamma + R_size + 1; b_gamma = g_gamma + G_size + 1; if (r_gamma == NULL) @@ -254,17 +254,16 @@ uint16_t* blueshift_randr_read(int use_crtc) return NULL; } - *(r_gamma - 1) = R_size; - *(g_gamma - 1) = G_size; - *(b_gamma - 1) = B_size; + *r_gamma++ = R_size; + *g_gamma++ = G_size; + *b_gamma++ = B_size; for (i = 0; i < R_size; i++) *(r_gamma + i) = *(R_gamma + i); for (i = 0; i < G_size; i++) *(g_gamma + i) = *(G_gamma + i); for (i = 0; i < B_size; i++) *(b_gamma + i) = *(B_gamma + i); free(gamma_get_reply); - - return r_gamma; + return r_gamma - 1; } diff --git a/src/blueshift_vidmode.pyx b/src/blueshift_vidmode.pyx index ac7c6c1..fdb5cb4 100644 --- a/src/blueshift_vidmode.pyx +++ b/src/blueshift_vidmode.pyx @@ -54,9 +54,8 @@ def vidmode_read(int use_crtc): s = got[i] i += 1 for j in range(s): - c.append(s[i + j]) + c.append(got[i + j]) i += s - free(got) return (r, g, b) diff --git a/src/blueshift_vidmode_c.c b/src/blueshift_vidmode_c.c index 8b9994d..42b501e 100644 --- a/src/blueshift_vidmode_c.c +++ b/src/blueshift_vidmode_c.c @@ -129,7 +129,7 @@ uint16_t* blueshift_vidmode_read(int use_crtc) /* Read curves */ - uint16_t* r_gamma = ((uint16_t*)malloc((3 + 3 * curve_size) * sizeof(uint16_t))) + 1; + uint16_t* r_gamma = malloc((3 + 3 * curve_size) * sizeof(uint16_t)); uint16_t* g_gamma = r_gamma + curve_size + 1; uint16_t* b_gamma = g_gamma + curve_size + 1; if (r_gamma == NULL) @@ -139,6 +139,10 @@ uint16_t* blueshift_vidmode_read(int use_crtc) return NULL; } + *r_gamma++ = curve_size; + *g_gamma++ = curve_size; + *b_gamma++ = curve_size; + if (XF86VidModeGetGammaRamp(display, screen, curve_size, r_gamma, g_gamma, b_gamma) == 0) { fprintf(stderr, "VidMode gamma query failed\n"); @@ -147,10 +151,7 @@ uint16_t* blueshift_vidmode_read(int use_crtc) return NULL; } - *(r_gamma - 1) = curve_size; - *(g_gamma - 1) = curve_size; - *(b_gamma - 1) = curve_size; - return r_gamma; + return r_gamma - 1; } diff --git a/src/monitor.py b/src/monitor.py index 3d75e72..7572061 100644 --- a/src/monitor.py +++ b/src/monitor.py @@ -75,14 +75,17 @@ def randr_get(crtc = 0, screen = 0): randr_opened = screen else: sys.exit(1) - (r, g, b) = randr_read() + (r, g, b) = randr_read(crtc) + r = [y / 65535 for y in r] + g = [y / 65535 for y in g] + b = [y / 65535 for y in b] def fcurve(R_curve, G_curve, B_curve): for curve, cur in curves(R_curve, G_curve, B_curve): for i in range(i_size): y = int(curve[i] * (len(cur) - 1) + 0.5) y = min(max(0, y), len(cur) - 1) curve[i] = cur[y] - return lambda : fcurve + return lambda : fcurve(r, g, b) def vidmode_get(crtc = 0, screen = 0): @@ -102,14 +105,17 @@ def vidmode_get(crtc = 0, screen = 0): vidmode_opened = screen else: sys.exit(1) - (r, g, b) = vidmode_read() + (r, g, b) = vidmode_read(crtc) + r = [y / 65535 for y in r] + g = [y / 65535 for y in g] + b = [y / 65535 for y in b] def fcurve(R_curve, G_curve, B_curve): for curve, cur in curves(R_curve, G_curve, B_curve): for i in range(i_size): y = int(curve[i] * (len(cur) - 1) + 0.5) y = min(max(0, y), len(cur) - 1) curve[i] = cur[y] - return lambda : fcurve + return lambda : fcurve(r, g, b) def randr(*crtcs, screen = 0): |