Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c80d58f
Add hidden non-git files and .gch and .su (can be generated when comp…
maandree May 12, 2014
e3f9cb9
Add fake-w32gdi (./configure --enable-fakegdi) that enabled the w32gd…
maandree May 12, 2014
e5ad5a1
Printing gamma in verbose mode is not necessary and causes complicati…
maandree May 12, 2014
84fe440
Separate out adjustment methods from redshift.c into adjustments.h so…
maandree May 12, 2014
fa0c50a
Move coordinate and elevation constants from redshift.c to redshift.h…
maandree May 12, 2014
bba1834
Use separate arguments instead of colon for option delimiting in -l a…
maandree May 16, 2014
d8dd370
Add adjustment datastructures to adjustments.h and prepare colorramp_…
maandree May 13, 2014
1751578
Add adjustment method common states
maandree May 12, 2014
9bf932f
Adjustment method common state initialisation and destruction
maandree May 12, 2014
addf271
Add adjustment method commit CRTC iterator
maandree May 16, 2014
f70127e
Add a function to find the alreadly loaded, if any, site (e.g. X disp…
maandree May 16, 2014
ada4fba
Implement adjustment method common CRTC selection logic
maandree May 16, 2014
062c997
Add adjustment method common gamma ramp update function and restore f…
maandree May 12, 2014
b59ece3
Add adjustment method common option parsing
maandree May 12, 2014
68b2b10
Add functions for updating adjustment settings
maandree May 12, 2014
96f1561
Add function to config-ini that gets multiple sections with the same …
maandree May 12, 2014
b8b58dc
Rewrite gamma-dummy to use gamma-common and update redshift.c to use …
maandree May 12, 2014
04df1b4
Rewrite gamma-randr to use gamma-common
maandree May 12, 2014
c17850a
Rewrite gamma-vidmode to use gamma-common
maandree May 12, 2014
e105abb
Rewrite gramma-drm to use gamma-common
maandree May 12, 2014
50c66f8
Rewrite gamma-w32gdi to use gamma-common
maandree May 12, 2014
64d2f47
Remove the old colorramp_fill
maandree May 12, 2014
a18884f
Some code reduce
maandree Apr 11, 2014
289c886
Minor documentation edits
maandree Apr 11, 2014
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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Hidden and temporary files
.*
!.git*

# Backup files
*~
\#*\#
Expand All @@ -6,6 +10,10 @@
*.o
*.ko

# Auxiliary files
*.gch
*.su

# Libraries
*.lib
*.a
Expand Down
17 changes: 16 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,28 @@ AS_IF([test "x$enable_vidmode" != xno], [
])
AM_CONDITIONAL([ENABLE_VIDMODE], [test "x$enable_vidmode" = xyes])

# Check for fake Windows GDI
AC_MSG_CHECKING([whether to enable fake WinGDI])
AC_ARG_ENABLE([fakegdi], [AC_HELP_STRING([--enable-fakegdi],
[enable fake WinGDI])],
[enable_fakegdi=$enableval],[enable_fakegdi=no])
AS_IF([test "x$enable_fakegdi" != xno], [
AC_DEFINE([FAKE_W32GDI], 1,
[Define to 1 to enable WinGDI method])
AC_MSG_RESULT([yes])
enable_fakegdi=yes
], [
AC_MSG_RESULT([no])
])
AM_CONDITIONAL([FAKE_W32GDI], [test "x$enable_fakegdi" != xno])

# Check Windows GDI method
AC_MSG_CHECKING([whether to enable WinGDI method])
AC_ARG_ENABLE([wingdi], [AC_HELP_STRING([--enable-wingdi],
[enable WinGDI method])],
[enable_wingdi=$enableval],[enable_wingdi=maybe])
AS_IF([test "x$enable_wingdi" != xno], [
AS_IF([test $have_windows_h = yes], [
AS_IF([test $have_windows_h = yes -o $enable_fakegdi = yes], [
AC_DEFINE([ENABLE_WINGDI], 1,
[Define to 1 to enable WinGDI method])
AC_MSG_RESULT([yes])
Expand Down
6 changes: 3 additions & 3 deletions redshift.1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
redshift \- Set color temperature of display according to time of day.
.SH SYNOPSIS
.B redshift
\fI[\-l LAT:LON | \-l PROVIDER:OPTIONS] [\-t DAY:NIGHT] \fR[\fIOPTIONS\fR...]
\fI[\-l LAT:LON | \-l PROVIDER OPTIONS] [\-t DAY:NIGHT] \fR[\fIOPTIONS\fR...]
.SH DESCRIPTION
.B redshift
adjusts the color temperature of your screen according to your
Expand Down Expand Up @@ -46,11 +46,11 @@ Your current location, in degrees, given as floating point numbers,
towards north and east, with negative numbers representing south and
west, respectively.
.TP
\fB\-l\fR PROVIDER[:OPTIONS]
\fB\-l\fR PROVIDER [OPTIONS]
Select provider for automatic location updates
(Type `list' to see available providers)
.TP
\fB\-m\fR METHOD
\fB\-m\fR METHOD [OPTIONS]
Method to use to set color temperature
(Type `list' to see available methods)
.TP
Expand Down
10 changes: 9 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ redshift_SOURCES = \
location-manual.c location-manual.h \
solar.c solar.h \
systemtime.c systemtime.h \
gamma-dummy.c gamma-dummy.h
adjustments.h \
gamma-common.c gamma-common.h \
gamma-dummy.c gamma-dummy.h \
opt-parser.c opt-parser.h

EXTRA_redshift_SOURCES = \
gamma-drm.c gamma-drm.h \
gamma-randr.c gamma-randr.h \
gamma-vidmode.c gamma-vidmode.h \
gamma-w32gdi.c gamma-w32gdi.h \
fake-w32gdi.c fake-w32gdi.h \
location-geoclue.c location-geoclue.h

AM_CFLAGS =
Expand Down Expand Up @@ -53,8 +57,12 @@ endif

if ENABLE_WINGDI
redshift_SOURCES += gamma-w32gdi.c gamma-w32gdi.h
if FAKE_W32GDI
redshift_SOURCES += fake-w32gdi.c fake-w32gdi.h
else
redshift_LDADD += -lgdi32
endif
endif


if ENABLE_GEOCLUE
Expand Down
88 changes: 88 additions & 0 deletions src/adjustments.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/* adjustments.h -- Adjustment constants and data structures header
This file is part of Redshift.

Redshift is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Redshift is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

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) 2014 Mattias Andrée <[email protected]>
*/

#ifndef REDSHIFT_ADJUSTMENTS_H
#define REDSHIFT_ADJUSTMENTS_H

#include <stdint.h>
#include <unistd.h>



/* Bounds for parameters. */
#define MIN_TEMP 1000
#define MAX_TEMP 25000
#ifndef MIN_BRIGHTNESS
# define MIN_BRIGHTNESS 0.1f
#endif
#if !defined(MAX_BRIGHTNESS) && !defined(NO_MAX_BRIGHTNESS)
# define MAX_BRIGHTNESS 1.0f
#endif
#ifndef MIN_GAMMA
# define MIN_GAMMA 0.1f
#endif
#if !defined(MAX_GAMMA) && !defined(NO_MAX_GAMMA)
# define MAX_GAMMA 10.0f
#endif

/* Default values for parameters. */
#define DEFAULT_DAY_TEMP 5500
#define DEFAULT_NIGHT_TEMP 3500
#define DEFAULT_BRIGHTNESS 1.0f
#define DEFAULT_GAMMA 1.0f

/* The color temperature when no adjustment is applied. */
#define NEUTRAL_TEMP 6500



/* Gamma ramp trio. */
typedef struct {
/* The number of stops in each ramp. */
size_t red_size;
size_t green_size;
size_t blue_size;
/* The actual ramps. */
uint16_t *red;
uint16_t *green;
uint16_t *blue;
} gamma_ramps_t;


/* Color adjustment settings. */
typedef struct {
/* The monitor's gamma correction. */
float gamma_correction[3];
/* Adjustments.
The gamma is only one value, rather than
three becuase it is not an correction,
but rather an adjustment as suggest in
<https://github.com/jonls/redshift/issues/10>.
This is included for performance: it takes
less work for Redshift to multiply the gamma
values than for a front-ent to create or
modify a lookup table. */
float gamma;
float brightness;
float temperature;
} gamma_settings_t;



#endif
46 changes: 38 additions & 8 deletions src/colorramp.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@

Copyright (c) 2013 Jon Lund Steffensen <[email protected]>
Copyright (c) 2013 Ingo Thies <[email protected]>
Copyright (c) 2014 Mattias Andrée <[email protected]>
*/

#include "colorramp.h"
#include "adjustments.h"

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

Expand Down Expand Up @@ -281,21 +286,46 @@ 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])
colorramp_fill(gamma_ramps_t out_ramps, gamma_settings_t adjustments)
{
/* Approximate white point */
size_t gamma_sizes[3] = {
out_ramps.red_size,
out_ramps.green_size,
out_ramps.blue_size
};

uint16_t *filter[3] = {
out_ramps.red,
out_ramps.green,
out_ramps.blue
};


/* Approximate white point. */
int temp = (int)(adjustments.temperature + 0.5f);
float white_point[3];
float alpha = (temp % 100) / 100.0;
int temp_index = ((temp - 1000) / 100)*3;
interpolate_color(alpha, &blackbody_color[temp_index],
&blackbody_color[temp_index+3], white_point);

#define F(Y, C) pow((Y) * brightness * white_point[C], 1.0/gamma[C])
float gamma[3] = {
adjustments.gamma_correction[0] * adjustments.gamma,
adjustments.gamma_correction[1] * adjustments.gamma,
adjustments.gamma_correction[2] * adjustments.gamma
};

#define F(Y, C) pow((Y) * adjustments.brightness * white_point[C], \
1.0f / gamma[C])

for (int i = 0; i < size; i++) {
gamma_r[i] = F((float)i/size, 0) * (UINT16_MAX+1);
gamma_g[i] = F((float)i/size, 1) * (UINT16_MAX+1);
gamma_b[i] = F((float)i/size, 2) * (UINT16_MAX+1);
for (int c = 0; c < 3; c++) {
uint16_t *cfilter = filter[c];
size_t gamma_size = gamma_sizes[c];
for (size_t i = 0; i < gamma_size; i++) {
int32_t y = F((float)i / gamma_size, c) * (UINT16_MAX+1);
cfilter[i] = (uint16_t)(y < 0 ? 0 : y > UINT16_MAX ? UINT16_MAX : y);
}
}

#undef F
}
6 changes: 3 additions & 3 deletions src/colorramp.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
along with Redshift. If not, see <http://www.gnu.org/licenses/>.

Copyright (c) 2010 Jon Lund Steffensen <[email protected]>
Copyright (c) 2014 Mattias Andrée <[email protected]>
*/

#ifndef REDSHIFT_COLORRAMP_H
#define REDSHIFT_COLORRAMP_H

#include <stdint.h>
#include "adjustments.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]);
void colorramp_fill(gamma_ramps_t out_ramps, gamma_settings_t adjustments);

#endif /* ! REDSHIFT_COLORRAMP_H */
34 changes: 33 additions & 1 deletion src/config-ini.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
along with Redshift. If not, see <http://www.gnu.org/licenses/>.

Copyright (c) 2010 Jon Lund Steffensen <[email protected]>
Copyright (c) 2014 Mattias Andrée <[email protected]>
*/


Expand Down Expand Up @@ -285,7 +286,7 @@ 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_get_section(const config_ini_state_t *state, const char *name)
{
config_ini_section_t *section = state->sections;
while (section != NULL) {
Expand All @@ -297,3 +298,34 @@ config_ini_get_section(config_ini_state_t *state, const char *name)

return NULL;
}

config_ini_section_t **
config_ini_get_sections(const 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;
}

size_t 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;
}
8 changes: 6 additions & 2 deletions src/config-ini.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
along with Redshift. If not, see <http://www.gnu.org/licenses/>.

Copyright (c) 2010 Jon Lund Steffensen <[email protected]>
Copyright (c) 2014 Mattias Andrée <[email protected]>
*/

#ifndef REDSHIFT_CONFIG_INI_H
Expand Down Expand Up @@ -43,7 +44,10 @@ typedef struct {
int config_ini_init(config_ini_state_t *state, const char *filepath);
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_section(const config_ini_state_t *state,
const char *name) __attribute__((pure));

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

#endif /* ! REDSHIFT_CONFIG_INI_H */
Loading