redshift: Simplify set_temperature by passing color_setting_t
Changes all set_temperature function in gamma adjustment methods to take a color_setting_t pointer with the color settings. Colorramp functions are similarly changed to take a color settings struct.
This commit is contained in:
+9
-8
@@ -21,6 +21,7 @@
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "redshift.h"
|
||||
|
||||
/* Whitepoint values for temperatures at 100K intervals.
|
||||
These will be interpolated for the actual temperature.
|
||||
@@ -281,16 +282,17 @@ interpolate_color(float a, const float *c1, const float *c2, float *c)
|
||||
}
|
||||
|
||||
/* Helper macro used in the fill functions */
|
||||
#define F(Y, C) pow((Y) * brightness * white_point[C], 1.0/gamma[C])
|
||||
#define F(Y, C) pow((Y) * setting->brightness * \
|
||||
white_point[C], 1.0/setting->gamma[C])
|
||||
|
||||
void
|
||||
colorramp_fill(uint16_t *gamma_r, uint16_t *gamma_g, uint16_t *gamma_b,
|
||||
int size, int temp, float brightness, const float gamma[3])
|
||||
int size, const color_setting_t *setting)
|
||||
{
|
||||
/* Approximate white point */
|
||||
float white_point[3];
|
||||
float alpha = (temp % 100) / 100.0;
|
||||
int temp_index = ((temp - 1000) / 100)*3;
|
||||
float alpha = (setting->temperature % 100) / 100.0;
|
||||
int temp_index = ((setting->temperature - 1000) / 100)*3;
|
||||
interpolate_color(alpha, &blackbody_color[temp_index],
|
||||
&blackbody_color[temp_index+3], white_point);
|
||||
|
||||
@@ -303,13 +305,12 @@ colorramp_fill(uint16_t *gamma_r, uint16_t *gamma_g, uint16_t *gamma_b,
|
||||
|
||||
void
|
||||
colorramp_fill_float(float *gamma_r, float *gamma_g, float *gamma_b,
|
||||
int size, int temp, float brightness,
|
||||
const float gamma[3])
|
||||
int size, const color_setting_t *setting)
|
||||
{
|
||||
/* Approximate white point */
|
||||
float white_point[3];
|
||||
float alpha = (temp % 100) / 100.0;
|
||||
int temp_index = ((temp - 1000) / 100)*3;
|
||||
float alpha = (setting->temperature % 100) / 100.0;
|
||||
int temp_index = ((setting->temperature - 1000) / 100)*3;
|
||||
interpolate_color(alpha, &blackbody_color[temp_index],
|
||||
&blackbody_color[temp_index+3], white_point);
|
||||
|
||||
|
||||
+4
-3
@@ -22,10 +22,11 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "redshift.h"
|
||||
|
||||
void colorramp_fill(uint16_t *gamma_r, uint16_t *gamma_g, uint16_t *gamma_b,
|
||||
int size, int temp, float brightness, const float gamma[3]);
|
||||
int size, const color_setting_t *setting);
|
||||
void colorramp_fill_float(float *gamma_r, float *gamma_g, float *gamma_b,
|
||||
int size, int temp, float brightness,
|
||||
const float gamma[3]);
|
||||
int size, const color_setting_t *setting);
|
||||
|
||||
#endif /* ! REDSHIFT_COLORRAMP_H */
|
||||
|
||||
+2
-2
@@ -241,7 +241,7 @@ drm_set_option(drm_state_t *state, const char *key, const char *value)
|
||||
}
|
||||
|
||||
int
|
||||
drm_set_temperature(drm_state_t *state, int temp, float brightness, const float gamma[3])
|
||||
drm_set_temperature(drm_state_t *state, const color_setting_t *setting)
|
||||
{
|
||||
drm_crtc_state_t *crtcs = state->crtcs;
|
||||
int last_gamma_size = 0;
|
||||
@@ -269,7 +269,7 @@ drm_set_temperature(drm_state_t *state, int temp, float brightness, const float
|
||||
last_gamma_size = crtcs->gamma_size;
|
||||
}
|
||||
colorramp_fill(r_gamma, g_gamma, b_gamma, crtcs->gamma_size,
|
||||
temp, brightness, gamma);
|
||||
setting);
|
||||
drmModeCrtcSetGamma(state->fd, crtcs->crtc_id, crtcs->gamma_size,
|
||||
r_gamma, g_gamma, b_gamma);
|
||||
}
|
||||
|
||||
+4
-1
@@ -25,6 +25,8 @@
|
||||
#include <xf86drm.h>
|
||||
#include <xf86drmMode.h>
|
||||
|
||||
#include "redshift.h"
|
||||
|
||||
|
||||
typedef struct {
|
||||
int crtc_num;
|
||||
@@ -52,7 +54,8 @@ void drm_print_help(FILE *f);
|
||||
int drm_set_option(drm_state_t *state, const char *key, const char *value);
|
||||
|
||||
void drm_restore(drm_state_t *state);
|
||||
int drm_set_temperature(drm_state_t *state, int temp, float brightness, const float gamma[3]);
|
||||
int drm_set_temperature(drm_state_t *state,
|
||||
const color_setting_t *setting);
|
||||
|
||||
|
||||
#endif /* ! REDSHIFT_GAMMA_DRM_H */
|
||||
|
||||
+5
-4
@@ -14,7 +14,7 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Redshift. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright (c) 2013 Jon Lund Steffensen <jonlst@gmail.com>
|
||||
Copyright (c) 2013-2014 Jon Lund Steffensen <jonlst@gmail.com>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -27,6 +27,8 @@
|
||||
# define _(s) s
|
||||
#endif
|
||||
|
||||
#include "redshift.h"
|
||||
|
||||
|
||||
int
|
||||
gamma_dummy_init(void *state)
|
||||
@@ -66,9 +68,8 @@ gamma_dummy_set_option(void *state, const char *key, const char *value)
|
||||
}
|
||||
|
||||
int
|
||||
gamma_dummy_set_temperature(void *state, int temp, float brightness,
|
||||
const float gamma[3])
|
||||
gamma_dummy_set_temperature(void *state, const color_setting_t *setting)
|
||||
{
|
||||
printf(_("Temperature: %i\n"), temp);
|
||||
printf(_("Temperature: %i\n"), setting->temperature);
|
||||
return 0;
|
||||
}
|
||||
|
||||
+3
-3
@@ -14,7 +14,7 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Redshift. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright (c) 2013 Jon Lund Steffensen <jonlst@gmail.com>
|
||||
Copyright (c) 2013-2014 Jon Lund Steffensen <jonlst@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef REDSHIFT_GAMMA_DUMMY_H
|
||||
@@ -31,8 +31,8 @@ void gamma_dummy_print_help(FILE *f);
|
||||
int gamma_dummy_set_option(void *state, const char *key, const char *value);
|
||||
|
||||
void gamma_dummy_restore(void *state);
|
||||
int gamma_dummy_set_temperature(void *state, int temp, float brightness,
|
||||
const float gamma[3]);
|
||||
int gamma_dummy_set_temperature(void *state,
|
||||
const color_setting_t *setting);
|
||||
|
||||
|
||||
#endif /* ! REDSHIFT_GAMMA_DUMMY_H */
|
||||
|
||||
+6
-7
@@ -75,8 +75,8 @@ quartz_set_option(quartz_state_t *state, const char *key, const char *value)
|
||||
}
|
||||
|
||||
static void
|
||||
quartz_set_temperature_for_display(CGDirectDisplayID display, int temp,
|
||||
float brightness, const float gamma[3])
|
||||
quartz_set_temperature_for_display(CGDirectDisplayID display,
|
||||
const color_setting_t *setting)
|
||||
{
|
||||
uint32_t ramp_size = CGDisplayGammaTableCapacity(display);
|
||||
if (ramp_size == 0) {
|
||||
@@ -97,7 +97,7 @@ quartz_set_temperature_for_display(CGDirectDisplayID display, int temp,
|
||||
float *gamma_b = &gamma_ramps[2*ramp_size];
|
||||
|
||||
colorramp_fill_float(gamma_r, gamma_g, gamma_b, ramp_size,
|
||||
temp, brightness, gamma);
|
||||
setting);
|
||||
|
||||
CGError error =
|
||||
CGSetDisplayTransferByTable(display, ramp_size,
|
||||
@@ -111,8 +111,8 @@ quartz_set_temperature_for_display(CGDirectDisplayID display, int temp,
|
||||
}
|
||||
|
||||
int
|
||||
quartz_set_temperature(quartz_state_t *state, int temp, float brightness,
|
||||
const float gamma[3])
|
||||
quartz_set_temperature(quartz_state_t *state,
|
||||
const color_setting_t *setting)
|
||||
{
|
||||
int r;
|
||||
CGError error;
|
||||
@@ -136,8 +136,7 @@ quartz_set_temperature(quartz_state_t *state, int temp, float brightness,
|
||||
}
|
||||
|
||||
for (int i = 0; i < display_count; i++) {
|
||||
quartz_set_temperature_for_display(displays[i], temp,
|
||||
brightness, gamma);
|
||||
quartz_set_temperature_for_display(displays[i], setting);
|
||||
}
|
||||
|
||||
free(displays);
|
||||
|
||||
+2
-2
@@ -37,8 +37,8 @@ int quartz_set_option(quartz_state_t *state, const char *key,
|
||||
const char *value);
|
||||
|
||||
void quartz_restore(quartz_state_t *state);
|
||||
int quartz_set_temperature(quartz_state_t *state, int temp, float brightness,
|
||||
const float gamma[3]);
|
||||
int quartz_set_temperature(quartz_state_t *state,
|
||||
const color_setting_t *setting);
|
||||
|
||||
|
||||
#endif /* ! REDSHIFT_GAMMA_QUARTZ_H */
|
||||
|
||||
+9
-9
@@ -14,7 +14,7 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Redshift. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright (c) 2010 Jon Lund Steffensen <jonlst@gmail.com>
|
||||
Copyright (c) 2010-2014 Jon Lund Steffensen <jonlst@gmail.com>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <xcb/randr.h>
|
||||
|
||||
#include "gamma-randr.h"
|
||||
#include "redshift.h"
|
||||
#include "colorramp.h"
|
||||
|
||||
|
||||
@@ -294,8 +295,8 @@ randr_set_option(randr_state_t *state, const char *key, const char *value)
|
||||
}
|
||||
|
||||
static int
|
||||
randr_set_temperature_for_crtc(randr_state_t *state, int crtc_num, int temp,
|
||||
float brightness, const float gamma[3])
|
||||
randr_set_temperature_for_crtc(randr_state_t *state, int crtc_num,
|
||||
const color_setting_t *setting)
|
||||
{
|
||||
xcb_generic_error_t *error;
|
||||
|
||||
@@ -327,7 +328,7 @@ randr_set_temperature_for_crtc(randr_state_t *state, int crtc_num, int temp,
|
||||
uint16_t *gamma_b = &gamma_ramps[2*ramp_size];
|
||||
|
||||
colorramp_fill(gamma_r, gamma_g, gamma_b, ramp_size,
|
||||
temp, brightness, gamma);
|
||||
setting);
|
||||
|
||||
/* Set new gamma ramps */
|
||||
xcb_void_cookie_t gamma_set_cookie =
|
||||
@@ -349,8 +350,8 @@ randr_set_temperature_for_crtc(randr_state_t *state, int crtc_num, int temp,
|
||||
}
|
||||
|
||||
int
|
||||
randr_set_temperature(randr_state_t *state, int temp, float brightness,
|
||||
const float gamma[3])
|
||||
randr_set_temperature(randr_state_t *state,
|
||||
const color_setting_t *setting)
|
||||
{
|
||||
int r;
|
||||
|
||||
@@ -359,13 +360,12 @@ randr_set_temperature(randr_state_t *state, int temp, float brightness,
|
||||
if (state->crtc_num < 0) {
|
||||
for (int i = 0; i < state->crtc_count; i++) {
|
||||
r = randr_set_temperature_for_crtc(state, i,
|
||||
temp, brightness,
|
||||
gamma);
|
||||
setting);
|
||||
if (r < 0) return -1;
|
||||
}
|
||||
} else {
|
||||
return randr_set_temperature_for_crtc(state, state->crtc_num,
|
||||
temp, brightness, gamma);
|
||||
setting);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
+3
-3
@@ -14,7 +14,7 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Redshift. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright (c) 2010 Jon Lund Steffensen <jonlst@gmail.com>
|
||||
Copyright (c) 2010-2014 Jon Lund Steffensen <jonlst@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef REDSHIFT_GAMMA_RANDR_H
|
||||
@@ -54,8 +54,8 @@ void randr_print_help(FILE *f);
|
||||
int randr_set_option(randr_state_t *state, const char *key, const char *value);
|
||||
|
||||
void randr_restore(randr_state_t *state);
|
||||
int randr_set_temperature(randr_state_t *state, int temp, float brightness,
|
||||
const float gamma[3]);
|
||||
int randr_set_temperature(randr_state_t *state,
|
||||
const color_setting_t *setting);
|
||||
|
||||
|
||||
#endif /* ! REDSHIFT_GAMMA_RANDR_H */
|
||||
|
||||
+5
-4
@@ -14,7 +14,7 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Redshift. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright (c) 2010 Jon Lund Steffensen <jonlst@gmail.com>
|
||||
Copyright (c) 2010-2014 Jon Lund Steffensen <jonlst@gmail.com>
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <X11/extensions/xf86vmode.h>
|
||||
|
||||
#include "gamma-vidmode.h"
|
||||
#include "redshift.h"
|
||||
#include "colorramp.h"
|
||||
|
||||
|
||||
@@ -163,8 +164,8 @@ vidmode_restore(vidmode_state_t *state)
|
||||
}
|
||||
|
||||
int
|
||||
vidmode_set_temperature(vidmode_state_t *state, int temp, float brightness,
|
||||
const float gamma[3])
|
||||
vidmode_set_temperature(vidmode_state_t *state,
|
||||
const color_setting_t *setting)
|
||||
{
|
||||
int r;
|
||||
|
||||
@@ -180,7 +181,7 @@ vidmode_set_temperature(vidmode_state_t *state, int temp, float brightness,
|
||||
uint16_t *gamma_b = &gamma_ramps[2*state->ramp_size];
|
||||
|
||||
colorramp_fill(gamma_r, gamma_g, gamma_b, state->ramp_size,
|
||||
temp, brightness, gamma);
|
||||
setting);
|
||||
|
||||
/* Set new gamma ramps */
|
||||
r = XF86VidModeSetGammaRamp(state->display, state->screen_num,
|
||||
|
||||
+5
-3
@@ -14,12 +14,14 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Redshift. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright (c) 2010 Jon Lund Steffensen <jonlst@gmail.com>
|
||||
Copyright (c) 2010-2014 Jon Lund Steffensen <jonlst@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef REDSHIFT_GAMMA_VIDMODE_H
|
||||
#define REDSHIFT_GAMMA_VIDMODE_H
|
||||
|
||||
#include "redshift.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -42,8 +44,8 @@ int vidmode_set_option(vidmode_state_t *state, const char *key,
|
||||
const char *value);
|
||||
|
||||
void vidmode_restore(vidmode_state_t *state);
|
||||
int vidmode_set_temperature(vidmode_state_t *state, int temp, float brightness,
|
||||
const float gamma[3]);
|
||||
int vidmode_set_temperature(vidmode_state_t *state,
|
||||
const color_setting_t *setting);
|
||||
|
||||
|
||||
#endif /* ! REDSHIFT_GAMMA_VIDMODE_H */
|
||||
|
||||
+4
-4
@@ -14,7 +14,7 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Redshift. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright (c) 2010 Jon Lund Steffensen <jonlst@gmail.com>
|
||||
Copyright (c) 2010-2014 Jon Lund Steffensen <jonlst@gmail.com>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -129,8 +129,8 @@ w32gdi_restore(w32gdi_state_t *state)
|
||||
}
|
||||
|
||||
int
|
||||
w32gdi_set_temperature(w32gdi_state_t *state, int temp, float brightness,
|
||||
const float gamma[3])
|
||||
w32gdi_set_temperature(w32gdi_state_t *state,
|
||||
const color_setting_t *setting)
|
||||
{
|
||||
BOOL r;
|
||||
|
||||
@@ -154,7 +154,7 @@ w32gdi_set_temperature(w32gdi_state_t *state, int temp, float brightness,
|
||||
WORD *gamma_b = &gamma_ramps[2*GAMMA_RAMP_SIZE];
|
||||
|
||||
colorramp_fill(gamma_r, gamma_g, gamma_b, GAMMA_RAMP_SIZE,
|
||||
temp, brightness, gamma);
|
||||
setting);
|
||||
|
||||
/* Set new gamma ramps */
|
||||
r = SetDeviceGammaRamp(hDC, gamma_ramps);
|
||||
|
||||
+5
-3
@@ -14,7 +14,7 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Redshift. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright (c) 2010 Jon Lund Steffensen <jonlst@gmail.com>
|
||||
Copyright (c) 2010-2014 Jon Lund Steffensen <jonlst@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef REDSHIFT_GAMMA_W32GDI_H
|
||||
@@ -23,6 +23,8 @@
|
||||
#include <windows.h>
|
||||
#include <wingdi.h>
|
||||
|
||||
#include "redshift.h"
|
||||
|
||||
|
||||
typedef struct {
|
||||
WORD *saved_ramps;
|
||||
@@ -38,8 +40,8 @@ int w32gdi_set_option(w32gdi_state_t *state, const char *key,
|
||||
const char *value);
|
||||
|
||||
void w32gdi_restore(w32gdi_state_t *state);
|
||||
int w32gdi_set_temperature(w32gdi_state_t *state, int temp, float brightness,
|
||||
const float gamma[3]);
|
||||
int w32gdi_set_temperature(w32gdi_state_t *state,
|
||||
const color_setting_t *color);
|
||||
|
||||
|
||||
#endif /* ! REDSHIFT_GAMMA_W32GDI_H */
|
||||
|
||||
+8
-10
@@ -1296,8 +1296,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
/* Adjust temperature */
|
||||
r = method->set_temperature(&state, interp.temperature,
|
||||
interp.brightness, interp.gamma);
|
||||
r = method->set_temperature(&state, &interp);
|
||||
if (r < 0) {
|
||||
fputs(_("Temperature adjustment failed.\n"), stderr);
|
||||
method->free(&state);
|
||||
@@ -1310,8 +1309,10 @@ main(int argc, char *argv[])
|
||||
if (verbose) printf(_("Color temperature: %uK\n"), temp_set);
|
||||
|
||||
/* Adjust temperature */
|
||||
r = method->set_temperature(&state, temp_set, day.brightness,
|
||||
day.gamma);
|
||||
color_setting_t manual;
|
||||
memcpy(&manual, &day, sizeof(color_setting_t));
|
||||
manual.temperature = temp_set;
|
||||
r = method->set_temperature(&state, &manual);
|
||||
if (r < 0) {
|
||||
fputs(_("Temperature adjustment failed.\n"), stderr);
|
||||
method->free(&state);
|
||||
@@ -1323,8 +1324,8 @@ main(int argc, char *argv[])
|
||||
case PROGRAM_MODE_RESET:
|
||||
{
|
||||
/* Reset screen */
|
||||
r = method->set_temperature(&state, NEUTRAL_TEMP, 1.0,
|
||||
day.gamma);
|
||||
color_setting_t reset = { NEUTRAL_TEMP, { 1.0, 1.0, 1.0 }, 1.0 };
|
||||
r = method->set_temperature(&state, &reset);
|
||||
if (r < 0) {
|
||||
fputs(_("Temperature adjustment failed.\n"), stderr);
|
||||
method->free(&state);
|
||||
@@ -1473,10 +1474,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Adjust temperature */
|
||||
if (!disabled || short_trans_delta || set_adjustments) {
|
||||
r = method->set_temperature(&state,
|
||||
interp.temperature,
|
||||
interp.brightness,
|
||||
interp.gamma);
|
||||
r = method->set_temperature(&state, &interp);
|
||||
if (r < 0) {
|
||||
fputs(_("Temperature adjustment"
|
||||
" failed.\n"), stderr);
|
||||
|
||||
+3
-4
@@ -14,7 +14,7 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Redshift. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright (c) 2013 Jon Lund Steffensen <jonlst@gmail.com>
|
||||
Copyright (c) 2013-2014 Jon Lund Steffensen <jonlst@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef REDSHIFT_REDSHIFT_H
|
||||
@@ -40,9 +40,8 @@ typedef void gamma_method_print_help_func(FILE *f);
|
||||
typedef int gamma_method_set_option_func(void *state, const char *key,
|
||||
const char *value);
|
||||
typedef void gamma_method_restore_func(void *state);
|
||||
typedef int gamma_method_set_temperature_func(void *state, int temp,
|
||||
float brightness,
|
||||
const float gamma[3]);
|
||||
typedef int gamma_method_set_temperature_func(void *state,
|
||||
const color_setting_t *setting);
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
|
||||
Reference in New Issue
Block a user