Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ src/redshift-gtk/redshift-gtk
contrib/redshift.spec
src/redshift
src/redshift-gtk/__pycache__/
/data/systemd/redshift.service
/data/systemd/redshift-gtk.service

# gettext
/po/POTFILES
Expand Down
2 changes: 1 addition & 1 deletion DESIGN
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ I've been mostly consistent with the naming throughout the source code
(I hope).

First adjustment methods: There is "randr" which is the preferred
because it has support for multiple outputs per X screen whic is lacking
because it has support for multiple outputs per X screen which is lacking
in "vidmode". Both are APIs in the X server that allow for manipulation
of gamma ramps, which is what Redshift uses to change the screen color
temperature. There's also "wingdi" which is for the Windows version,
Expand Down
6 changes: 6 additions & 0 deletions redshift.1
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ One shot mode (do not continuously adjust color temperature)
\fB\-O\fR TEMP
One shot manual mode (set color temperature)
.TP
\fB\-P\fR
Preserve current calibrations
.TP
\fB\-p\fR
Print mode (only print parameters and exit)
.TP
Expand Down Expand Up @@ -106,6 +109,9 @@ Screen brightness at night
\fBgamma\fR = R:G:B
Gamma adjustment to apply
.TP
\fBpreserve-calibrations\fR = 0 or 1
Disable or enable preservation of currently applied calibrations.
.TP
\fBadjustment\-method\fR = name
Select adjustment method. Options for the adjustment method can be
given under the configuration file heading of the same name.
Expand Down
34 changes: 33 additions & 1 deletion src/colorramp.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Copyright (c) 2013 Ingo Thies <[email protected]>
*/

#include <stdlib.h>
#include <stdint.h>
#include <math.h>

Expand Down Expand Up @@ -282,7 +283,8 @@ interpolate_color(float a, const float *c1, const float *c2, float *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, int temp, float brightness, const float gamma[3],
uint16_t *calib_r, uint16_t *calib_g, uint16_t *calib_b)
{
/* Approximate white point */
float white_point[3];
Expand All @@ -298,4 +300,34 @@ colorramp_fill(uint16_t *gamma_r, uint16_t *gamma_g, uint16_t *gamma_b,
gamma_g[i] = F((float)i/size, 1) * (UINT16_MAX+1);
gamma_b[i] = F((float)i/size, 2) * (UINT16_MAX+1);
}

/* Apply gamma ramps used when Redshift started on top of
the effects of Redshift. It would be easier to put
Redshift's effects on top if this, but then calibrations
whould become incorrect. */
if (calib_r == NULL)
return;
uint16_t *calib[3];
calib[0] = calib_r;
calib[1] = calib_g;
calib[2] = calib_b;
uint16_t *filter[3];
filter[0] = gamma_r;
filter[1] = gamma_g;
filter[2] = gamma_b;
int size_ = size - 1;
for (int c = 0; c < 3; c++) {
uint16_t *cfilter = filter[c];
uint16_t *ccalib = calib[c];
for (int i = 0; i < size; i++) {
/* We a rounding a bit. We could do linear
interpolation or even (precalculated)
polynomial interpolation, but it is
probably not worth it. */
int y = cfilter[i];
y = (float)(y * size_) / UINT16_MAX + 0.5;
y = y < 0 ? 0 : (y > size_ ? size_ : y);
cfilter[i] = ccalib[y];
}
}
}
3 changes: 2 additions & 1 deletion src/colorramp.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <stdint.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, int temp, float brightness, const float gamma[3],
uint16_t *calib_r, uint16_t *calib_g, uint16_t *calib_b);

#endif /* ! REDSHIFT_COLORRAMP_H */
31 changes: 31 additions & 0 deletions src/config-ini.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,34 @@ config_ini_get_section(config_ini_state_t *state, const char *name)

return NULL;
}

config_ini_section_t **
config_ini_get_sections(config_ini_state_t *state, const char *name)
{
config_ini_section_t **sections = malloc(1 * sizeof(config_ini_section_t*));
if (sections == NULL) {
perror("malloc");
return NULL;
}

int ptr = 0;
config_ini_section_t *section = state->sections;
while (section != NULL) {
if (strcasecmp(section->name, name) == 0) {
sections[ptr++] = section;

if ((ptr & -ptr) == ptr) {
sections = realloc(sections, (ptr << 1) * sizeof(config_ini_section_t*));
if (sections == NULL) {
perror("realloc");
return NULL;
}
}
}

section = section->next;
}

sections[ptr] = NULL;
return sections;
}
3 changes: 3 additions & 0 deletions src/config-ini.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@ void config_ini_free(config_ini_state_t *state);
config_ini_section_t *config_ini_get_section(config_ini_state_t *state,
const char *name);

config_ini_section_t **config_ini_get_sections(config_ini_state_t *state,
const char *name);

#endif /* ! REDSHIFT_CONFIG_INI_H */
Loading