diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-02-23 10:49:36 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-02-23 10:49:36 +0100 |
commit | 50ef1eed478d758dbd2aa4cddb57a7c6eb562ed8 (patch) | |
tree | e4b3dc2e55122811eb83b825220486ff9fa4fd34 /src | |
parent | doc some solar functions (diff) | |
download | blueshift-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')
-rw-r--r-- | src/blueshift_randr_c.c | 62 | ||||
-rw-r--r-- | src/blueshift_vidmode_c.c | 39 |
2 files changed, 101 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 diff --git a/src/blueshift_vidmode_c.c b/src/blueshift_vidmode_c.c index b160e7e..b53a23d 100644 --- a/src/blueshift_vidmode_c.c +++ b/src/blueshift_vidmode_c.c @@ -115,6 +115,45 @@ int blueshift_vidmode_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_vidmode_read(int use_crtc) +{ + (void) use_crtc; + + /* Read curves */ + + uint16_t* r_gamma = ((uint16_t*)malloc((3 + 3 * curve_size) * sizeof(uint16_t))) + 1; + uint16_t* g_gamma = r_gamma + curve_size + 1; + uint16_t* b_gamma = g_gamma + curve_size + 1; + if (r_gamma == NULL) + { + fprintf(stderr, "Out of memory\n"); + XCloseDisplay(display); + return NULL; + } + + if (XF86VidModeGetGammaRamp(display, screen, curve_size, r_gamma, g_gamma, b_gamma) == 0) + { + fprintf(stderr, "VidMode gamma query failed\n"); + free(r_gamma); + XCloseDisplay(display); + return NULL; + } + + *(r_gamma - 1) = curve_size; + *(g_gamma - 1) = curve_size; + *(b_gamma - 1) = curve_size; + return r_gamma; +} + + +/** * Apply stage of colour curve control * * @param use_crtcs Mask of CRTC:s to use |