Example #1
0
/**
 * Set the gamma ramps of the of a monitor
 * 
 * @param   connection  The identifier for the connection to the card
 * @param   crtc_index  The index of the CRTC to read from
 * @param   gamma_size  The size a gamma ramp
 * @param   red         The red gamma ramp
 * @param   green       The green gamma ramp
 * @param   blue        The blue gamma ramp
 * @return              Zero on success
 */
int blueshift_drm_set_gamma_ramps(int connection, int crtc_index, int gamma_size, uint16_t* red, uint16_t* green, uint16_t* blue)
{
  card_connection* card = card_connections + connection;
  
  /* Fails if inside a graphical environment */
  return drmModeCrtcSetGamma(card->fd, *(card->res->crtcs + crtc_index), (uint32_t)gamma_size, red, green, blue);
}
Example #2
0
static void
crtc_gamma_set(xf86CrtcPtr crtc, CARD16 * red, CARD16 * green, CARD16 * blue,
	       int size)
{
    modesettingPtr ms = modesettingPTR(crtc->scrn);
    struct crtc_private *crtcp = crtc->driver_private;

    drmModeCrtcSetGamma(ms->fd, crtcp->drm_crtc->crtc_id, size, red, green, blue);
}
static void
drmmode_crtc_gamma_set(xf86CrtcPtr crtc,
		       CARD16 *red, CARD16 *green, CARD16 *blue, int size)
{
	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
	drmmode_ptr drmmode = drmmode_crtc->drmmode;

	drmModeCrtcSetGamma(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
			    size, red, green, blue);
}
Example #4
0
static void
drm_restore(drm_state_t *state)
{
	drm_crtc_state_t *crtcs = state->crtcs;
	while (crtcs->crtc_num >= 0) {
		if (crtcs->r_gamma != NULL) {
			drmModeCrtcSetGamma(state->fd, crtcs->crtc_id, crtcs->gamma_size,
					    crtcs->r_gamma, crtcs->g_gamma, crtcs->b_gamma);
		}
		crtcs++;
	}
}
Example #5
0
static int
drm_set_temperature(
	drm_state_t *state, const color_setting_t *setting, int preserve)
{
	drm_crtc_state_t *crtcs = state->crtcs;
	int last_gamma_size = 0;
	uint16_t *r_gamma = NULL;
	uint16_t *g_gamma = NULL;
	uint16_t *b_gamma = NULL;

	for (; crtcs->crtc_num >= 0; crtcs++) {
		if (crtcs->gamma_size <= 1)
			continue;
		if (crtcs->gamma_size != last_gamma_size) {
			if (last_gamma_size == 0) {
				r_gamma = malloc(3 * crtcs->gamma_size * sizeof(uint16_t));
				g_gamma = r_gamma + crtcs->gamma_size;
				b_gamma = g_gamma + crtcs->gamma_size;
			} else if (crtcs->gamma_size > last_gamma_size) {
				r_gamma = realloc(r_gamma, 3 * crtcs->gamma_size * sizeof(uint16_t));
				g_gamma = r_gamma + crtcs->gamma_size;
				b_gamma = g_gamma + crtcs->gamma_size;
			}
			if (r_gamma == NULL) {
				perror(last_gamma_size == 0 ? "malloc" : "realloc");
				return -1;
			}
			last_gamma_size = crtcs->gamma_size;
		}

		/* Initialize gamma ramps to pure state */
		int ramp_size = crtcs->gamma_size;
		for (int i = 0; i < ramp_size; i++) {
			uint16_t value = (double)i/ramp_size * (UINT16_MAX+1);
			r_gamma[i] = value;
			g_gamma[i] = value;
			b_gamma[i] = value;
		}

		colorramp_fill(r_gamma, g_gamma, b_gamma, crtcs->gamma_size,
			       setting);
		drmModeCrtcSetGamma(state->fd, crtcs->crtc_id, crtcs->gamma_size,
				    r_gamma, g_gamma, b_gamma);
	}

	free(r_gamma);

	return 0;
}