aboutsummaryrefslogtreecommitdiffstats
path: root/src/gamma-drm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gamma-drm.c')
-rw-r--r--src/gamma-drm.c32
1 files changed, 12 insertions, 20 deletions
diff --git a/src/gamma-drm.c b/src/gamma-drm.c
index 8c7bcec..a4cc75e 100644
--- a/src/gamma-drm.c
+++ b/src/gamma-drm.c
@@ -160,7 +160,7 @@ drm_start(struct gamma_state *state, enum program_mode mode)
crtcs->r_gamma = calloc(3 * crtcs->gamma_size, sizeof(uint16_t));
crtcs->g_gamma = crtcs->r_gamma + crtcs->gamma_size;
crtcs->b_gamma = crtcs->g_gamma + crtcs->gamma_size;
- if (crtcs->r_gamma != NULL) {
+ if (crtcs->r_gamma) {
int r = drmModeCrtcGetGamma(state->fd, crtcs->crtc_id, crtcs->gamma_size,
crtcs->r_gamma, crtcs->g_gamma, crtcs->b_gamma);
if (r < 0) {
@@ -171,7 +171,7 @@ drm_start(struct gamma_state *state, enum program_mode mode)
crtcs->r_gamma = NULL;
}
} else {
- perror("malloc");
+ weprintf("malloc:");
drmModeFreeResources(state->res);
state->res = NULL;
close(state->fd);
@@ -192,7 +192,7 @@ drm_restore(struct gamma_state *state)
{
struct drm_crtc_state *crtcs = state->crtcs;
while (crtcs->crtc_num >= 0) {
- if (crtcs->r_gamma != NULL) {
+ if (crtcs->r_gamma) {
drmModeCrtcSetGamma(state->fd, crtcs->crtc_id, crtcs->gamma_size,
crtcs->r_gamma, crtcs->g_gamma, crtcs->b_gamma);
}
@@ -203,7 +203,7 @@ drm_restore(struct gamma_state *state)
static void
drm_free(struct gamma_state *state)
{
- if (state->crtcs != NULL) {
+ if (state->crtcs) {
struct drm_crtc_state *crtcs = state->crtcs;
while (crtcs->crtc_num >= 0) {
free(crtcs->r_gamma);
@@ -213,7 +213,7 @@ drm_free(struct gamma_state *state)
free(state->crtcs);
state->crtcs = NULL;
}
- if (state->res != NULL) {
+ if (state->res) {
drmModeFreeResources(state->res);
state->res = NULL;
}
@@ -241,16 +241,16 @@ drm_print_help(FILE *f)
static int
drm_set_option(struct gamma_state *state, const char *key, const char *value)
{
- if (strcasecmp(key, "card") == 0) {
+ if (!strcasecmp(key, "card")) {
state->card_num = atoi(value);
- } else if (strcasecmp(key, "crtc") == 0) {
+ } else if (!strcasecmp(key, "crtc")) {
state->crtc_num = atoi(value);
if (state->crtc_num < 0) {
- fprintf(stderr, _("CRTC must be a non-negative integer\n"));
+ weprintf(_("CRTC must be a non-negative integer\n"));
return -1;
}
} else {
- fprintf(stderr, _("Unknown method parameter: `%s'.\n"), key);
+ weprintf(_("Unknown method parameter: `%s'.\n"), key);
return -1;
}
@@ -275,18 +275,10 @@ drm_set_temperature(
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));
+ if (crtcs->gamma_size > last_gamma_size) {
+ r_gamma = erealloc(r_gamma, 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;
}
@@ -294,7 +286,7 @@ drm_set_temperature(
/* Initialize gamma ramps to pure state */
ramp_size = crtcs->gamma_size;
for (i = 0; i < ramp_size; i++) {
- value = (uint16_t)((double)i/ramp_size * (UINT16_MAX+1));
+ value = (uint16_t)((double)i / (ramp_size - 1) * UINT16_MAX);
r_gamma[i] = value;
g_gamma[i] = value;
b_gamma[i] = value;