From 71f64125e8f66cf0e504c8b35f7ab89f22765ae4 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 23 Feb 2014 17:49:30 +0100 Subject: fix errors in getting current curves + add getting curent curves to tests + fix multimonitor mistakes in examples MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/blueshift_randr.pyx | 3 +-- src/blueshift_randr_c.c | 11 +++++------ src/blueshift_vidmode.pyx | 3 +-- src/blueshift_vidmode_c.c | 11 ++++++----- src/monitor.py | 14 ++++++++++---- 5 files changed, 23 insertions(+), 19 deletions(-) (limited to 'src') 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): -- cgit v1.2.3-70-g09d2