summaryrefslogtreecommitdiffstats
path: root/src/blueshift_randr_c.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-02-23 10:49:36 +0100
committerMattias Andrée <maandree@operamail.com>2014-02-23 10:49:36 +0100
commit50ef1eed478d758dbd2aa4cddb57a7c6eb562ed8 (patch)
treee4b3dc2e55122811eb83b825220486ff9fa4fd34 /src/blueshift_randr_c.c
parentdoc some solar functions (diff)
downloadblueshift-50ef1eed478d758dbd2aa4cddb57a7c6eb562ed8.tar.gz
blueshift-50ef1eed478d758dbd2aa4cddb57a7c6eb562ed8.tar.bz2
blueshift-50ef1eed478d758dbd2aa4cddb57a7c6eb562ed8.tar.xz
c side of reading curves
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/blueshift_randr_c.c')
-rw-r--r--src/blueshift_randr_c.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/blueshift_randr_c.c b/src/blueshift_randr_c.c
index 8a40f7c..fa75656 100644
--- a/src/blueshift_randr_c.c
+++ b/src/blueshift_randr_c.c
@@ -206,6 +206,68 @@ int blueshift_randr_open(int use_screen)
/**
+ * Gets the current colour curves
+ *
+ * @param use_crtc The CRTC to use
+ * @return {the size of the red curve, *the red curve,
+ * the size of the green curve, *the green curve,
+ * the size of the blue curve, *the blue curve}, needs to be free:d
+ */
+uint16_t* blueshift_randr_read(int use_crtc)
+{
+ xcb_randr_get_crtc_gamma_cookie_t gamma_get_cookie;
+ xcb_randr_get_crtc_gamma_reply_t* gamma_get_reply;
+ uint16_t* r_gamma, * R_gamma;
+ uint16_t* g_gamma, * G_gamma;
+ uint16_t* b_gamma, * B_gamma;
+ int i, R_size, G_size, B_size;
+
+ /* Read curves */
+
+ gamma_get_cookie = xcb_randr_get_crtc_gamma(connection, *((crtcs + use_crtc)->crtc));
+ gamma_get_reply = xcb_randr_get_crtc_gamma_reply(connection, gamma_get_cookie, &error);
+
+ if (error)
+ {
+ fprintf(stderr, "RANDR CRTC gamma query returned %i\n", error->error_code);
+ xcb_disconnect(connection);
+ return NULL;
+ }
+
+ R_size = xcb_randr_get_crtc_gamma_red_length(gamma_get_reply);
+ G_size = xcb_randr_get_crtc_gamma_green_length(gamma_get_reply);
+ B_size = xcb_randr_get_crtc_gamma_blue_length(gamma_get_reply);
+
+ R_gamma = xcb_randr_get_crtc_gamma_red(gamma_get_reply);
+ 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;
+ g_gamma = r_gamma + R_size + 1;
+ b_gamma = g_gamma + G_size + 1;
+ if (r_gamma == NULL)
+ {
+ fprintf(stderr, "Out of memory\n");
+ free(gamma_get_reply);
+ xcb_disconnect(connection);
+ return NULL;
+ }
+
+ *(r_gamma - 1) = R_size;
+ *(g_gamma - 1) = G_size;
+ *(b_gamma - 1) = 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;
+}
+
+
+/**
* Apply stage of colour curve control
*
* @param use_crtcs Mask of CRTC:s to use